cv::VideoCapture reads only image sequence if images are located in the same folder as the executable. (Bugfix #3306)
Description
I found the following example with is officially included within opencv:
http://kevinhughes.ca/tutorials/reading-image-sequences-with-opencv/
However, this works only if the images are located in the same folder with the executable.
E.g. the following setup is working:
img_000.png
img_001.png
img_002.png
img_003.png
program.exe
However if the images are located in another folder I cant get this running.
Consider the following example:
std::string pathToData("c:\\path\\img_000.png");
Only the specified image "c:\\path\\img_000.png" is read and displayed, after this the VideoCapture instance says that there are no further images.
See also: http://stackoverflow.com/questions/16713258/opencv-reading-image-series-from-a-folder/19246508
History
Updated by Steven Puttemans over 11 years ago
Actually this is not a bug, you need to specify it correctly.
Next documentation will have some more explanation on this (already submitted as pullrequest).
If you want it to work with a different path, instead of passing right%%02d.jpg as argument and making sure that the first image in the folder is read, you need to change this in your case to:
std::string pathToData("c:\\path\\img_%%02d.png");
Then it will actually work. Try it and reopen if the ticket if it isn't solved.
- Status changed from New to Cancelled
Updated by sfdhiu iuhiuh over 11 years ago
Im sorry, I can't get this to work. Could you tell me the correct syntax for the following example:
Images are located in: c:\path\
Image numbering:
cap_00000000.bmp
cap_00000001.bmp
cap_00000002.bmp
...
How has
std::string pathToData("c:\\path\\???");
to look like?
Steven Puttemans wrote:
Actually this is not a bug, you need to specify it correctly.
Next documentation will have some more explanation on this (already submitted as pullrequest).If you want it to work with a different path, instead of passing right%%02d.jpg as argument and making sure that the first image in the folder is read, you need to change this in your case to:
std::string pathToData("c:\\path\\img_%%02d.png");
Then it will actually work. Try it and reopen if the ticket if it isn't solved.
Updated by Steven Puttemans over 11 years ago
Since you have 8 whitespace with zeros, your command should look like this:
std::string pathToData("c:\\path\\cap_%%08d.bmp");
Updated by sfdhiu iuhiuh over 11 years ago
I tried exactly would you suggested:
Case 1:
std::string pathToData("c:\\path\\cap_00000000.bmp");
Result: cv::VideoCapture "isOpened()" delivers true, I can grab exactly one picture ("cap_00000000.bmp"). When I am trying to grab the second "image.empty()" becomes true (failed to grab cap_00000001.bmp).
Case 2:
I put the executable in the directory "c:/path/" where the images are located. I change pathToDate appropriately:
std::string pathToData("cap_00000000.bmp");
Result: Everything works as expected, the images are read sequentially.
Case 3:
This is what you suggested:
std::string pathToData("c:\\path\\cap_%%08d.bmp");
Result: cv::VideoCapture::isOpened returns false.
So is this a bug? Or am I still doing sth. wrong?
Updated by Kirill Kornyakov over 11 years ago
Well, if you think this is a bug, you can try to debug it. It should be relatively easy to track what OpenCV tries to do, and why it fails to read images from other folder. May be the reason is that OpenCV wants forward slash ("/") as path delimeter... Did you try it?
- Status changed from Cancelled to Open
- Assignee set to sfdhiu iuhiuh
Updated by sfdhiu iuhiuh over 11 years ago
Kirill Kornyakov wrote:
Well, if you think this is a bug, you can try to debug it. It should be relatively easy to track what OpenCV tries to do, and why it fails to read images from other folder. May be the reason is that OpenCV wants forward slash ("/") as path delimeter... Did you try it?
Of course I tried it. I spent further time to debug this and I found the relevant source file:
cap_images.cpp
However, I cannot identify the exact reason for this behavior since I can write C++ code, not this "sscanf, strdup" etc. stuff. So I dont know exactly what is going on there. But I found at least one bug:
The c function "icvExtractPattern()" tries to extract the pattern (e.g. %08d).
If no pattern is provided, a pattern is extracted. Therefore it does not matter whether your path is
std::string pathToData("c:\\path\\cap_00000000.bmp");
or
std::string pathToData("c:\\path\\cap_%%08d.bmp");
However the author's code fails if the path contains further numbers such as date and time. The following fails:
std::string pathToData("c:\\2013-Data\\path\\cap_00000000.bmp")
Therefore it should be implemented that the user MUST provide a pattern in any case! This should also be documented!
I dont know if this fixes the whole problem? Could someone who can compile opencv try my above mentioned cases (the 3 ones)?
The 2013 is identified as a pattern and
- Status changed from Open to Cancelled
- % Done changed from 0 to 10
- Assignee deleted (
sfdhiu iuhiuh)
Updated by sfdhiu iuhiuh over 11 years ago
Okay I got in contact with the author (Nils Hasler, see cap_images.cpp). Some things.
1.) He fixed the bug with additional numbers in the path by parsing now from right to left. He sent me the new source file and wanted me to post this there:
http://codepad.org/aeNa9ezH
2.) Concerning the double '%'-sign.
E.g. as suggested here:
std::string pathToData("c:\\path\\cap_%%08d.bmp");
This is also wrong. The author wrote me:
"Allerdings sollte NUR EIN % benutzt werden. [...] Das doppelte % ist ganz klar ein Bug in der Doku."
In English: "ONLY ONE % should be used! [...] Passing two '%' signs is definitely a bug within the documentation."
So the documentation should also be fixed. Furthermore I suggest that someone who is really into OpenCV takes some time to have a look on "cap_images.cpp" and tests the whole cap_images-Functionality. Best regards.
- % Done changed from 10 to 20
- Status changed from Cancelled to Open
Updated by Kirill Kornyakov over 11 years ago
Anybody? Who is really into OpenCV...
- Tracker changed from Bug to Bugfix
Updated by Steven Puttemans over 11 years ago
Okay, after some digging, it seems I already fixed this one in master, but it never got pushed to the 2.4 branch.
Therefore pull request submitted : https://github.com/Itseez/opencv/pull/1845
Will provide a pull request for master fixes based on new code also in other pull
- % Done changed from 20 to 50
Updated by Steven Puttemans over 11 years ago
Pull request for master branch : https://github.com/Itseez/opencv/pull/1846
Hopefully it will work after patch :)
Updated by Kevin Hughes over 11 years ago
I think I may have wrote some of that documentation and its possible some confusion arose with respect to the double %% as a result of what is in a string in source code and what actually gets printed if you were to see the usage string in the console. Don't have time to verify but that might have led to some of the troubles.
Cheers
Updated by Steven Puttemans over 11 years ago
https://github.com/Itseez/opencv/pull/1845 is the only correct fix.
SpecLad already programmed a check for controlling if their are numbers in the pathname, which is more intuitive. Therefore the only changes need to be made to docs and sample. Sample was also added to 2.4 branch since it seems to be missing there.
- Affected version changed from 2.4.6 (latest release) to 2.4.7 (latest release)
Updated by Victor Kocheganov over 11 years ago
- Assignee set to Sergei Nosov
- Pull request set to https://github.com/Itseez/opencv/pull/1845
Updated by Alexander Smorkalov over 11 years ago
- Target version changed from 2.4.7 to 2.4.8
Updated by Steven Puttemans over 11 years ago
Fixes where merged, latest branches will both support the correct use of image sequences now using the VideoCapture interace!
- Status changed from Open to Done
- Assignee deleted (
Sergei Nosov) - % Done changed from 50 to 100