LISHUZUOXUN_yangjiang/realtime_streaming.py

18 lines
381 B
Python
Raw Normal View History

2024-09-23 14:54:15 +08:00
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')