0

I am swapping from EmguCV to OpenCV so that I can try some of the OpenCV functions that are not yet wrapped by EmguCV. However I'm failing to load my simple test video file, which loads without issue in EmguCV. Looking at the EmguCV source code I notice that they call the OpenCV C functions rather than C++ to initialise capture from a file (or a webcam) so I wrote the following test code (with help from 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. it happens for "sample.wmv", "sample.avi", and even one of the OpenCV sample files "tree.avi".

Why? What is going on?

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

Community
  • 1
  • 1
dumbledad
  • 16,305
  • 23
  • 120
  • 273
  • Do you have the necessary permissions on your system? Can you open anything (i.e. images or XML files, etc) with opencv? – alrikai Oct 25 '13 at 20:27
  • Yep - jpeg opens fine. Plus EmguCV projects successfully open the same video files. – dumbledad Oct 25 '13 at 20:37
  • Do you have the samples? I can tried it for you and then I'll let you know if it works fine. – Mzk Oct 26 '13 at 02:03
  • Thanks @Mzk I've put sample.wmv here: https://www.dropbox.com/sh/1lp9vb9wgfg7l1l/FDddArU10f – dumbledad Oct 26 '13 at 07:17

2 Answers2

3

It appears that, following advice from @tobias-senst on another answer, I needed to build OpenCV on my local machine rather than rely on the DLLs that are provided with the standard distribution. It has been a headache to get OpenCV to build locally (see here, here, and here) but now that I reference to a copy of OpenCV 2.4.6 that was built on this machine I can open the video files.

I have no idea why this works, why it is not mentioned in the requirements, why others are not more frequently having this problem, nor what is failing with the default deployment, but at least I have it fixed.

Community
  • 1
  • 1
dumbledad
  • 16,305
  • 23
  • 120
  • 273
1

umm..if emgu and your project use the same version, just copy the emgu's opencv dlls(and all other dlls) to your folder..maybe it will work.

one reason why that maybe 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 rely on ffmpeg to do almost all of the decoding. opencv ffmpeg/s are probably built in release mode so if your project is in debug mode it probably wont work either.

Zaw Lin
  • 5,629
  • 1
  • 23
  • 41
  • Thanks @zaw-lin Swapping to the OpenCV DLLs that come with EmguCV is a good idea, but as I'm swapping from EmguCV to OpenCV I'd like to use the latest realease, or at least understand why I cannot. I think you may be correct about the ffmpeg DLLs, though I was already copying them (debug and release) into the directory. I've ended up realising that I need to build the DLLs (or possible only the ffmpeg one?) locally, and [that fixed it](http://stackoverflow.com/a/19635301/575530). – dumbledad Oct 28 '13 at 12:56