How to read directory with images by VideoCapture?
I know it is not officially supported yet, but I would like to read images in a directory numbered as 1.png, 2.png ... 137.png using VideoCapture
.
While browsing the source code I saw CvCapture_Images
class which can read images one by one using a printf
like pattern. I can't seem to make it work. I have tried:
VideoCapture cap("c:/fullpath/1.png");
and
VideoCapture cap("c:/fullpath/%d.png");
Neither of them worked, the first one was able to read only 1.png but not the rest of the images. Latter one was not able to open the capture at all.
How can I make VideoCapture work to read images named nicely?
Answer
Because I don't have enough reputation I can't add this as an answer, so here it goes, you can do either:
VideoCapture cap("c:/fullpath/1.png");
OR
VideoCapture cap("c:/fullpath/%1d.png");
the reason it didn't work the first time is that there is a bug with CvCapture_Images
[1] where fullpath contains digits the first method fails. The latter method works as long as you specify using %#d
format, i.e. don't forget to put at least one digit before d
.
See the sammy's alternative answer below.