简体   繁体   English

OpenCV 和 Python Flask 如何从文件夹和 ZF7B44CFAFD5C62223D7BZA2E 中读取图像到网站?

[英]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.

相关问题 无法从文件夹中读取 bmp 图像,OpenCV (python) - can't read bmp images from folder ,OpenCV (python) 如何在 Python 中使用 opencv 从文件夹中读取图像序列(im1、im2、...)? - How can I read a sequence of images (im1, im2, ...) from a folder using opencv in Python? 如何使用Python和OpenCV从目录中读取图像? - How to read images from a directory with Python and OpenCV? 如何在 python 中使用 selenium 从网站上抓取多个图像并将它们保存在特定文件夹中? - How do I scrape multiple images from a website and save them on a specific folder using selenium in python? 如何从烧瓶中关闭opencv视频流 - How to close opencv video stream from flask 无法从 D 驱动器 [OpenCV] [Python] 读取或写入图像 - Can't read or write images from D Drive [OpenCV] [Python] Python/OpenCV - 如何按字母顺序从文件夹中加载所有图像 - Python/OpenCV - how to load all images from folder in alphabetical order 从子文件夹中读取所有图像,检测文本并将它们与原始名称和文件夹一起保存在 Python 中? - Read all images from subfolder, detect text them and save them with their original name and folder in Python? 如何在Python html和flask中显示文件夹中的图像 - How to display images from folder in Python html and flask 从特定目录读取多个图像,使用 python 和 opencv 将它们保存在另一个目录中 - Read multiple images from specific directory, prepossessed and save them another directory using python and opencv
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM