def gen_normal():
while 1:
if len(latest_video_frame) > 0: # if we have started receiving actual frames:
# convert the latest read video frame to jpg format:
ret, jpg = cv2.imencode(".jpg", latest_video_frame)
# get the raw data bytes of the jpg image: (convert to binary)
frame = jpg.tobytes()
# yield ('return') the frame: (yield: returns value and saves the current state of the generator function, the next time this generator function is called execution will resume on the next line of code in the function (ie it will in this example start a new cycle of the while loop and yield a new frame))
# what we yield looks like this, but in binary: (binary data is a must for multipart)
# --frame
# Content-Type: image/jpeg
#
# <frame data>
#
yield (b'--frame\nContent-Type: image/jpeg\n\n' + frame + b'\n')
评论列表
文章目录