views:

1842

answers:

8

Hi every one,

When I compile my Windows application (called CrosslinesDetection) in Visual C++ 2005 including OpenCV 1.1, a computer vision library, I do not get any compile or link errors, but when I am running it, it gets to a point and freezes, and Windows says the following:

"Unhandled exception at 0x7c915223 in CrosslinesDetection.exe:
0xC0000005: Access violation writing location 0x00030ffc."

The program is a common C++ Windows Applikation with two lines of OpenCV code:

IplImage *img = cvCreateImage( cvSize( 1024, 768 ), IPL_DEPTH_8U, 1 );
cvReleaseImage( &img );

The strange behavior is now, if I - include the OpenCV lines, the program throws the exception - exclude the OpenCV lines, the program works properly.

I used the OpenCV libraries in another project without any problems. In particular, I made a C# project for the GUI and a C++ project compiled as DLL in the background. If I create such a solution for the above lines, I have not problems during execution.

Has anybody an idea, what might cause this error?

Thanks for any help, Stefan

A: 

Isn't it

cvReleaseImage( img );

? (ampersand removed) Also you should check the proper calling convention.

jmihalicza
The signature for cvReleaseImage is "void cvReleaseImage(IplImage** image)" so when you pass img by reference you are passing the memory location of the pointer (pointer to the pointer)
JustSmith
A: 

I just ran and compiled those exact lines with OpenCV 1.0 and Visual Studio 2008, with no errors. Maybe try creating an empty project which does nothing else but includes the cxcore.h header and then runs those two lines.

Also just to the other poster: no the ampersand is part of the specification, he's correct there. Sorry I would post this as a comment but can't yet.

Ray Hidayat
A: 

Thanks for the comments.

Meanwhile, I use a minimal project for testing.

I still do not fully understand the problem, but meanwhile, I figured out, that the excpetion occurs, when I include a third party library (from uEye).

If I use a single function from OpenCV and from the uEye library in the project, then an exception occurs. If I use either a single function from OpenCV or from uEye, no exception is thrown. So, these to libraries seem to be somewhat incompatible, or yet there is another problem. However, I don't know how to detect it.

A: 

When they both crash, are the two functions at all related? Like do you pass uEye your IplImage for example?

Ray Hidayat
A: 

No not at this point. In the minimal example the functions are unrelated. One functions initializes the camera and the other function intializes an image structure.

A: 

But maybe the error is elsewhere...

I created in Visual Studio a C++ Windows Form Application. I added to the form a button as well as corresponding function in Form1.h file:

private: System::Void Form1_Click(System::Object^  sender, System::EventArgs^  e) {
  OpenCamera();
  IplImage * img = cvCreateImageHeader( cvSize( 1024, 768 ), IPL_DEPTH_8U, 1);
  cvReleaseImage( &img );
  CloseCamera();
}

And I added the headeras at the begin of Form1.h:

#include "CameraControl.h"
#include "cv.h"

Then, I had to switch off the precompiled header option and I had to change from /clr:pure to /clr option to successfully compile and link the project.

But, then I run the program the above mentioned exception is thrown...

I am wondering, if I misuse the C++ Windows Form Application and I should not inlcude my pure C++ code or if there is really a problem with OpenCV or the uEye library.

+1  A: 

I would suggest to test this same code in a native project, without managed code. Either MFC or a Win32 console application.

Dani van der Meer
A: 

Thanks, yes, the problem is caused by the managed code. If I encapuslate my stuff in a DLL, then it works...