[英]How can OpenCV with Python Flask read images from folder and stream them to website?
def gen2():
img = [cv2.imread(file) for file in glob.glob("path/*.jpg")]
img = cv2.resize(img, (0,0), fx = 0.5, fy = 0.5)
frame = cv2.imencode('.jpg', img)[1].tobytes()
yield(b'--frame\r\n'b'Content-Type: image/jpeg\r\n\r\n' + frame + b'\r\n')
I have some images in order with format image_0, image_1,...,image_999.jpg, for example.例如,我有一些图像格式为 image_0、image_1、...、image_999.jpg。 I try the above code but it does not work, I think I need a loop for the
frame and yield
, I am new to OpenCV and have no idea.我尝试了上面的代码,但它不起作用,我想我需要一个循环来处理
frame and yield
,我是 OpenCV 的新手并且不知道。 Thanks in advance.提前致谢。
Yes, img is an array of images, so you will need a loop.是的,img 是一个图像数组,所以你需要一个循环。 Try this
尝试这个
def gen2():
imgs = [cv2.imread(file) for file in glob.glob("path/*.jpg")]
imgs = [cv2.resize(img, (0,0), fx = 0.5, fy = 0.5) for img in imgs]
frames = [cv2.imencode('.jpg', img)[1].tobytes() for img in imgs]
for frame in frames :
yield(b'--frame\r\n'b'Content-Type: image/jpeg\r\n\r\n' + frame + b'\r\n')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.