【问题标题】:How can I read images from a folder, starting from image 10 for example with VideoCapture()?如何从文件夹中读取图像,例如使用 VideoCapture() 从图像 10 开始?
【发布时间】:2019-09-04 22:29:06
【问题描述】:

我想从文件夹中读取一系列图像。 我发现:

cap=cv2.VideoCapture("in%6d.jpg")

但我必须从image10 开始,而不是从第一个开始。

我该怎么做?

【问题讨论】:

  • 请提供minimal reproducible example。没有它,就很难或不可能说出您要做什么以及具体问题出在哪里。
  • 我不认为cv2.VideoCapture() 是您想要用来读取文件的东西——它不是用来从相机捕捉图像吗?
  • @martineau 请参阅docs.opencv.org/2.4/modules/highgui/doc/… 了解 OP 的用例。
  • @uneven_mark:嗯,谢谢,不幸的是,文档像泥巴一样清晰......

标签: python opencv


【解决方案1】:

这应该有效:

import os

folder = os.listdir()
folder = sorted(folder)
start_pos = [i for i,x in enumerate(folder) if x == 'image10.jpg'][0]

for i in range(start_pos,len(folder)):
    cap=cv2.VideoCapture(folder[i]) #or whatever the cv2 function is...

【讨论】:

  • os.listdir 也不返回有序列表,OP 也不想为每个图像调用 VideoCapture,请参阅 docs.opencv.org/2.4/modules/highgui/doc/…
  • 您的文件系统已经对列表进行了排序......但无论出于何种原因假设它是按降序排序的,这就像添加 .sort 函数一样简单。
猜你喜欢
  • 1970-01-01
  • 2023-03-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-03-25
  • 2020-02-14
  • 1970-01-01
相关资源
最近更新 更多