OpenCV: Reading image series from a folder

一曲冷凌霜 提交于 2019-11-29 08:01:16

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);

the images are sequentially read:

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

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

According to this link it needs to be:

cv::VideoCapture cap("C:/Users/Admin/Documents/Images/%2d.jpg");
                      ^^^                             ^^^

i.e. just a single : after the C and %2d for a 2 digit file name sequence.

Similarly your second example should probably be:

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

use glob as in glob(folderpath, vectorOfimages) then access each of the images as vectorOfimages[i].

vectorOfimages is

 vector<String>

and folderpath is a String.

We need to declare like this

VideoCapture vcap("C:\\pathDirectory\\folderName\\drop%d.bmp");

I declared like that and it worked fine for me, because my images names were drop1.bmp, drop2.bmp, drop3.bmp ……and so on

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!