直接上代码吧,关键一句是:detect_face_image = io.BytesIO (bytes_image)
import cv2
from PIL import Image
import numpy as np
import io
#读取网络摄像头
#camera = cv2.VideoCapture('rtsp://admin:password@10.0.10.1:554/h264/ch1/main/av_stream')
#读取本地摄像头
camera = cv2.VideoCapture (0)
success, image = camera.read ()
imgRGB = cv2.cvtColor (image, cv2.IMREAD_COLOR)
r, buf = cv2.imencode (".jpg", imgRGB)
bytes_image = Image.fromarray (np.uint8 (buf)).tobytes ()
#array转换成二进制
detect_face_image = io.BytesIO (bytes_image)
print(detect_face_image)