【问题标题】:How do I save particular frames of video into folders using python?如何使用 python 将特定的视频帧保存到文件夹中?
【发布时间】:2020-11-18 12:15:20
【问题描述】:

我有一个可以进行运动检测的代码。它将视频作为输入,然后当对象进入场景时,背景会发生变化,并且代码会在检测到的帧上将“对象被看到”作为文本发布。

我的问题是如何将“看到对象时”的帧保存到文件夹中(对于彩色和灰色图像)?我知道我可以使用“ cv2.imwrite("frame%d.jpg" % count, resizedFrame)" 编写这些帧,但不幸的是它不起作用。

如何将检测到的帧保存到“彩色”和“灰色”文件夹?

【问题讨论】:

    标签: python image image-processing motion-detection


    【解决方案1】:

    您必须先通过cv2.imread() 阅读图像,然后再通过 cv2.imwrite() 阅读图像 这是一个小例子

    import
    cv2
     
    # read image as grey scale
    grey_img=cv2.imread('/home/img/python.png',cv2.IMREAD_GRAYSCALE)
     # save image
    status=cv2.imwrite('/home/img/python_grey.png',grey_img)
     print("Image written to file-system : ",status)
    

    如果您没有文件夹路径,请使用它 status=cv2.imwrite('python_grey.png',grey_img) 它会将照片保存在您保存.py 文件的默认文件夹中

    如果你想保存不同的图像,这里是代码

    import cv2
    import time
    
    # for number of images you need different names so set name automatically
    name=str(time.time())+str(.png))
     # read image as grey scale
    grey_img=cv2.imread('/home/img/python.png',cv2.IMREAD_GRAYSCALE)
     # save image
    status=cv2.imwrite('%s'%name,grey_img)
     print("Image written to file-system : ",status)
    

    【讨论】:

    • 我知道这些事情,我的问题是关于这个特殊问题,当没有文件夹可供读取时。在处理过程中如何保存这些特定帧?
    • 你可以简单的忽略文件夹路径,直接写cv2.imwritr('photo.jpg',img)
    • 好的,谢谢,您能否编辑您的答案并使其用于保存图像循环?我会选择你的答案。
    • 你能保存不同的图片吗
    • 是的,因为我正在从视频中读取这些帧。谢谢
    猜你喜欢
    • 2014-09-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-06-13
    • 1970-01-01
    • 2014-11-04
    • 2020-04-01
    • 2022-01-19
    相关资源
    最近更新 更多