OpenCV:从文件夹中读取图像系列 [英] OpenCV: Reading image series from a folder

查看:762
本文介绍了OpenCV:从文件夹中读取图像系列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用OpenCV的 VideoCapture 函数从文件夹中读取一系列图像。在互联网上进行一些搜索之后,我目前的代码是这样的:

I am trying to read a series of images from a folder using OpenCV's VideoCapture function. After some search on the internet, my current code is like this:

cv::VideoCapture cap ( "C:\\Users\\Admin\\Documents\\Images\\%02d.jpg");

我原本希望看到 VideoCapture 功能应该读取该文件夹中名称为两个连续数字的所有图像,如 01.jpg,02.jpg,...,30.jpg 。有人在互联网上告诉我,一旦我给出第一张图片的位置和名称, VideoCapture 功能应该可以捕获所有这些图像。所以我也尝试这样做:

I was expecting to see that VideoCapture function should read all the images in that folder with names of two serial digits, like 01.jpg, 02.jpg, ..., 30.jpg. Someone told on the internet that the VideoCapture function should be ale to catch all of these images once I give the first image's location and name. So I also tried to do it like this:

cv::VideoCapture cap ("C:\\Users\\Admin\\Documents\\Images\\01.jpg");

但这仍然不起作用,至少在我的情况下不行。这些图像具有不同的大小,因此我将首先阅读它们,调整它们的大小,然后对它们进行进一步处理。我怎样才能做到这一点?我正在使用Windows7,使用VisualStudio。谢谢。

But still this is not working, at least not for my case here. These images are of different sizes, so I am going to read them first, resize them, and then do further processing on each of them. How can I do this? I am using Windows7, with VisualStudio. Thank you.

推荐答案

根据我的经验,即使没有指定格式,VideoCapture也可以读取一系列图像。
例如以下工作正常:

From my experiences the VideoCapture can read a sequence of images even without specifing the format. E.g. the following works fine:

std::string pathToData("cap_00000000.bmp");
cv::VideoCapture sequence(pathToData);

按顺序读取图像:

Mat image;
sequence >> image; // Reads cap_00000001.bmp

HOWEVER:这仅适用于图像位于可执行文件的文件夹中。我无法指出这样的目录:

HOWEVER: This only works if the images are located within the folder of the executable file. I could not figure out to specify a directory like this:

std::string pathToData("c:\\path\\cap_00000000.bmp");
std::string pathToData("c://path//cap_00000000.bmp");
// etc.

似乎是一个错误。一个正式的例子可以在这里找到:

Seems to be a bug. An offical example can be found here:

http://kevinhughes.ca/tutorials/reading-image-sequences-with-opencv/
https://github.com/Itseez/opencv/pull/823/files

这篇关于OpenCV:从文件夹中读取图像系列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆