Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Why would video files open in C but not C++ with OpenCV?

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 http://stackoverflow.com/a/10260047/575530). Here is my simple code

VideoCapture cap ("sample.wmv");
if(!cap.isOpened())
{
    OutputDebugString("Failed to open in C++"); 
    CvCapture* capture = cvCaptureFromAVI("sample.wmv");
    if (!capture)
    {
        OutputDebugString(" but opened in C\n");    
    }
    else
    {
        OutputDebugString(" in C++ and C\n");
        cvReleaseCapture(&capture);
    }
    return -1;
}

You've probably guessed the punch-line of this 'joke' but the output from that simple fragment of code is

Failed to open in C++ but opened in C

Why? What is going on?

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

Why would video files open in C but not C++ with OpenCV?

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 http://stackoverflow.com/a/10260047/575530). stackoverflow). Here is my simple code

VideoCapture cap ("sample.wmv");
if(!cap.isOpened())
{
    OutputDebugString("Failed to open in C++"); 
    CvCapture* capture = cvCaptureFromAVI("sample.wmv");
    if (!capture)
    {
        OutputDebugString(" but opened in C\n");    
    }
    else
    {
        OutputDebugString(" in C++ and C\n");
        cvReleaseCapture(&capture);
    }
    return -1;
}

You've probably guessed the punch-line of this 'joke' but the output from that simple fragment of code is

Failed to open in C++ but opened in C

C

Why? What is going on?

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

Why would video files open in C but not C++ with OpenCV?

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 stackoverflow). 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 ("sample.wmv");
(filename);
        if(!cap.isOpened())
{
    OutputDebugString("Failed         {
            cout << "Failed to open file in C++"); 
OpenCV C++" << endl;
            //Trying C API too just-in-case
            CvCapture* capture = cvCaptureFromAVI("sample.wmv");
cvCreateFileCapture(filename.c_str());
            if (!capture)
    {
        OutputDebugString(" but opened         {
                cout << "Failed to open file in C\n");    
    }
OpenCV C" << endl;  
            }
            else
    {
        OutputDebugString(" in C++         {
                //Grab frames and C\n");
do stuff
                cvReleaseCapture(&capture);
    }
        }
            return -1;
        }
        else
        {
            //Grab frames and do stuff
        }
    }
    return 0;
}

You've probably guessed the punch-line 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 this 'joke' but the output from that simple fragment the file, i.e. it happens for "sample.wmv", "sample.avi", and even one of code is the OpenCV sample files "tree.avi".

Failed to open in C++ but opened in C

Why? What is going on?

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

click to hide/show revision 4
revising title in line with code

Why would video files not open in OpenCV (both C but not & C++ with OpenCV?APIs)?

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 stackoverflow). 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.)

Why would video files not open in OpenCV (both C & C++ APIs)?

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 stackoverflow). Here is my simple code

int _tmain()
{
    string filename ("sample.wmv");
= "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.)

click to hide/show revision 6
blockquote not code for output

Why would video files not open in OpenCV (both C & C++ APIs)?

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 stackoverflow). 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.)

Why would video files not open in OpenCV (both C & C++ APIs)?

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 stackoverflow). 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 exists

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

Failed to open file in OpenCV C

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.)

click to hide/show revision 8
retagged

updated 2013-10-26 04:21:11 -0600

berak gravatar image

Why would video files not open in OpenCV (both C & C++ APIs)?

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 stackoverflow). 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.)