18 lines
381 B
Python
18 lines
381 B
Python
import cv2
|
|
|
|
|
|
# 将图像转化为jpg
|
|
def img_format_jpg(img):
|
|
try:
|
|
return cv2.imencode('.jpg', img)[1].tobytes()
|
|
except Exception as e:
|
|
print(e)
|
|
|
|
|
|
def gen(camera):
|
|
"""视频流生成"""
|
|
while True:
|
|
frame = camera.get_frame()
|
|
yield (b'--frame\r\n'
|
|
b'Content-Type: image/jpeg\r\n\r\n' + img_format_jpg(frame) + b'\r\n')
|