Reputation: 548
I have a problem using VideoCapture class with OpenCV 2.4.2 under windows XP 32bits. It doesn't open any file or camera and fixing it's being a pain. Im using visual studio 2010 but i have also tried the code in QTcreator with the same result.
The testing code is the following:
#include "opencv/cv.h"
#include "opencv/highgui.h"
#include <iostream>
#include <string>
#include <iomanip>
#include <sstream>
using namespace cv;
using namespace std;
int main()
{
const char* videoPath = "C:/video/";
string videoName = string(videoPath) + "avi.avi";
VideoCapture cap(videoName);
if(!cap.isOpened())
{
std::cout<<"Fail"<<std::endl;
return -3;
}
return 0;
}
The output is always '-3'. Qt Creator shows a warning: Error opening file (../../modules/highgui/src/cap_ffmpeg_impl.hpp:361)
I debugged it and the problem appears in the first line of:
CvCapture* cvCreateFileCapture_FFMPEG_proxy(const char * filename)
{
CvCapture_FFMPEG_proxy* result = new CvCapture_FFMPEG_proxy;
if( result->open( filename ))
return result;
delete result;
#if defined WIN32 || defined _WIN32
return cvCreateFileCapture_VFW(filename);
#else
return 0;
#endif
}
in the cap_ffmpeg.cpp internal file.
I have tested the same code in a mac under snow leopard and it works. No surprises here since it must be a library issue. I have opened the avi file with the same path route using the c-function cvCapture easy and fast. I got all the dlls of 'C:\opencv\opencv\build\x86\vc10\bin' included in mi debug file. I got the tbb.dll and all the 'C:\opencv\opencv\3rdparty\ffmpeg' content included too.
This is drving me crazy so any help would be appreciated.
Thanks in advance.
Upvotes: 6
Views: 19611
Reputation: 3906
I too faced the same issue and resolved after pointing to the correct location of the input video.
Upvotes: 0
Reputation: 505
See the fix I found below, for mp4 files. I faced the same issue on Windows 7, using OpenCV 2.4.9. I am using the java wrapper for opencv.
Matthias Krings has done a lot of research for this. See this. Apparently this is an issue based on the video file type. With .avi files, it seems to work for a lot of people. Unfortunately his solution of setting OPENCV_DIR did not work for me. But his comments in the bug listing gave me a hint to fix the issue.
You have to do two things:
java.library.path
to include the directory {opencv\install\dir}opencv-2.4.9\build\x86\vc10\bin
. You can set the variable using the -D
option on the java command line: java -Djava.library.path=PATH_TO_YOUR_DLL ...
. Also fetch this variable from your environment, using System.getProperty(...)
, and print it before calling loadLibrary()
, to verify that the path setting is working. System.loadLibrary("opencv_ffmpeg249");
. The loadLibrary()
function should be invoked from within a static block
in java. opencv_ffmpeg249.dll
in the java.library.path
that we set. .so
files.Upvotes: 0
Reputation: 1
I had the same issue with the open method whilst running under Windows 8 (64bit), opencv 2.4.10. IDE is running in x86.
I found that running the application in release configuration solved the problem.
Stumbled across the answer because I had the same issue with imread. Issue is presented in the this thread. imread not working in Opencv
Upvotes: 0
Reputation: 31
I also faced with this problem and solved it by correct the path of the function:
VideoCapture cap(videoName);
If the AVI file of videoName does't exist, it will be an error:
(../../modules/highgui/src/cap_ffmpeg_impl.hpp:XXX)
where XXX represents the line number.
Upvotes: 3
Reputation: 56
In my case, the same problem was resolved after deleting all opencv_***.dll
files in C:\Windows\System32
. So, I use the dll files just through the path like "%PATH%;C: \Program Files \OpenCV2.4.2\build\x86\vc10/bin"
. Please try it.
Upvotes: 4