Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OpenCV2.4.2 unhandled exception on VideoCapture

Tags:

opencv

cmake

I just installed OpenCV2.4.2 and created an OpenCV project using CMake. I don't get any compilation errors. I have several functions for processing images and I have 2 applications:

1- Processes data from a video

2- Processes simulated data.

Both applications are identical except from the data extraction from the video.

PROBLEM: The application processing video crashes with

Unhandled exception at 0x75d8a048 in program.exe Access violation reading location 0x049f08c0.

It crashes in this part of the code, when reading frames:

cv::VideoCapture _video;
while(1) 
{       
        // grab the frame
        _video >> frame;  <-------------CRASHES HERE
                processFrame(frame);
}

So I guess there could be a problem with cv::VideoCapture class in OpenCV 2.4.2. How can I detect the problem and solve it?

EDIT

With video camera I managed to catch the error message:

OpenCV Error: Assertion failed (m.dims >= 2) in unknown function, file ..\..\..\
src\opencv\modules\core\src\matrix.cpp, line 268
OpenCV Error: Assertion failed (0 <= _rowRange.start && _rowRange.start <= _rowR
ange.end && _rowRange.end <= m.rows) in unknown function, file ..\..\..\src\open
cv\modules\core\src\matrix.cpp, line 283
like image 338
Carlos Cachalote Avatar asked Sep 10 '12 13:09

Carlos Cachalote


1 Answers

Are you checking if the capture actually opened the file/camera ?

    if(_video.isOpened()) {  // check if capture succeeded
      // do stuff
    }

Not all codecs are supported per default. This depends on the library you use underneath to open the video. (This might be ffmpeg or quicktime).

Also you can catch the exception yourself, just to be on the safe side for future problems

try {
    _video >> frame;
} catch (cv::Exception) {
    cout << "An exception has accurred" << endl;
};
like image 115
count0 Avatar answered Sep 28 '22 07:09

count0