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:
the images are sequentially read:
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:
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:
i.e. just a single
:
after theC
and%2d
for a 2 digit file name sequence.Similarly your second example should probably be:
We need to declare like this
I declared like that and it worked fine for me, because my images names were drop1.bmp, drop2.bmp, drop3.bmp ……and so on
use glob as in glob(folderpath, vectorOfimages) then access each of the images as vectorOfimages[i].
vectorOfimages is
and folderpath is a String.