27 lines
650 B
Python
27 lines
650 B
Python
from copy import deepcopy
|
|
|
|
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')
|
|
|
|
|
|
# 基础Http视频流
|
|
def base_camera(camera, video_source):
|
|
while True:
|
|
_img = deepcopy(camera.get_frame(video_source=video_source))
|
|
yield b'--frame\r\nContent-Type: image/jpeg\r\n\r\n' + img_format_jpg(_img) + b'\r\n'
|