Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to find out what is causing "cv::Exception at memory location"?

I'm currently suffering from some strange exceptions that are most probably due to me doing something incorrectly while interacting with opencv:

First-chance exception at 0x7580b9bc in xxx.exe: Microsoft C++ exception: cv::Exception at memory location 0x00c1c624..

I've already enabled the Thrown field in the Debug -> Exceptions menu, however I really can't figure out where in my code the exception is thrown.

How can I debug this?

EDIT the stack frame reads like this (my app won't even show up in the list!):

  • KernelBase.dll!7580b8bc()
  • [Frames below may be incorrect or missing ]
  • KernelBase.dll!7580b8bc()
  • opencv_core242d.dll!54eb60cc()
like image 656
memyself Avatar asked Oct 02 '12 09:10

memyself


3 Answers

You could wrap your entire main in a try catch block which prints out the exception details. If the open CV API can throw exceptions, you will need to think about handling them anyway as part of your design:

try
{
  // ... Contents of your main
}
catch ( cv::Exception & e )
{
 cerr << e.msg << endl; // output exception message
}
like image 189
Benj Avatar answered Oct 19 '22 01:10

Benj


OpenCV has this handy function called cv::setBreakOnError

If you put the following into your main before any opencv calls:

cv::setBreakOnError(true);

then your program will crash, because OpenCV will do an invalid operation (dereferencing a null pointer) just before it would throw cv::Exception normally. If you run your code in a debugger, it will stop at this illegal operation, and you can see the whole call stack with all of your codes and variables at the time of the error.

like image 29
tr3w Avatar answered Oct 19 '22 01:10

tr3w


I´ve got this problem by using OpenCV with WebCam. The problem in my case is that the program is trying to read an image when the Cam hasn't been initialized.

my error code:

 // open camera
capture.open(0);
while (1){
    //store image to matrix // here is the bug
    capture.read(cameraFeed);

The solution

 // open camera
capture.open(0);
while (1){

     //this line makes the program wait for an image 
     while (!capture.read(cameraFeed));

    //store image to matrix 
    capture.read(cameraFeed);

(sorry about my english) Thanks

like image 1
Bob Avatar answered Oct 19 '22 01:10

Bob