Strange behavior with OpenCV


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

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.

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.

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) {
  IplImage * img = cvCreateImageHeader( cvSize( 1024, 768 ), IPL_DEPTH_8U, 1);
  cvReleaseImage( &img );

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.

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