Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OpenCV: Reading image series from a folder

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

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

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.

like image 529
E_learner Avatar asked Dec 26 '22 03:12

E_learner


2 Answers

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

like image 107
Anonymous Avatar answered Dec 28 '22 18:12

Anonymous


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");
                      ^^^
like image 26
Paul R Avatar answered Dec 28 '22 17:12

Paul R