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.
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