Why won't video files open in OpenCV (like C & C ++ API)?

I am switching from EmguCV to OpenCV so that I can try some of the OpenCV features that EmguCV hasn't wrapped yet. However, I am unable to load my simple test video file, which loads seamlessly into EmguCV. Looking at the source code of EmguCV I notice that they are calling OpenCV C functions, not C ++ functions, to initialize the capture from a file (or webcam), so I wrote the following test code (using this answer ). Here is my simple code

int _tmain()
{
    string filename = "sample.wmv";
    if (!FileExists(filename.c_str))
    {
        cout << "File does not exist" << endl;  
        return -1;
    }
    else
    {
        cout << "File exists" << endl;
        VideoCapture cap (filename);
        if(!cap.isOpened())
        {
            cout << "Failed to open file in OpenCV C++" << endl;
            //Trying C API too just-in-case
            CvCapture* capture = cvCreateFileCapture(filename.c_str());
            if (!capture)
            {
                cout << "Failed to open file in OpenCV C" << endl;  
            }
            else
            {
                //Grab frames and do stuff
                cvReleaseCapture(&capture);
            }
            return -1;
        }
        else
        {
            //Grab frames and do stuff
        }
    }
    return 0;
}

      

When I run this I get the output

File exists
Failed to open file in OpenCV C++
Failed to open file in OpenCV C

      

This happens regardless of the file, i.e. this happens for "sample.wmv", "sample.avi" and even one of the OpenCV sample files "tree.avi".

Why? What's happening?

(I am running OpenCV 2.4.6 on a Windows 8 and Windows 8.1 machine.)

0


source to share


2 answers


It looks like, following @ tobias-senst's advice on another answer , I needed to build OpenCV on my local machine and not rely on DLLs that come with a standard distribution. It was a headache to localize OpenCV (see here , here, and here ), but now when I link to a copy of OpenCV 2.4.6 that was built on this computer, I can open the video files.



I have no idea why this works, why it is not mentioned in the requirements, why others do not encounter this problem more often, and what fails with default deployment, but at least I fixed it.

+3


source


umm..if emgu and your project are using the same version, just copy the emgu opencv dll (and all other dlls) to your folder. Maybe it will work.



one of the reasons why it is possible is because opencv is not built with ffmpeg ( or you are missing them in your folder, just copy them over then it also might start to work

). opencv relies on ffmpeg to do almost all decoding. opencv ffmpeg / s are probably built in release mode, so if your project is in debug mode it probably won't work either.

+1


source







All Articles