简体   繁体   English

OpenCV的奇怪行为

[英]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: 当我在包含OpenCV 1.1(一种计算机视觉库)的Visual C ++ 2005中编译我的Windows应用程序(称为CrosslinesDetection)时,我没有得到任何编译或链接错误,但是当我运行它时,它会停滞并冻结,并且Windows说以下内容:

"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: 该程序是常见的C ++ Windows应用程序,带有两行OpenCV代码:

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. 现在,奇怪的行为是,如果我-包含OpenCV行,程序将引发异常-排除OpenCV行,则程序将正常运行。

I used the OpenCV libraries in another project without any problems. 我在另一个项目中使用了OpenCV库,没有任何问题。 In particular, I made a C# project for the GUI and a C++ project compiled as DLL in the background. 特别是,我为GUI创建了一个C#项目,并在后台为DLL编译了一个C ++项目。 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). 我仍然不完全理解这个问题,但与此同时,我发现,当我包含第三方库(来自uEye)时,就会发生这种情况。

If I use a single function from OpenCV and from the uEye library in the project, then an exception occurs. 如果我使用来自OpenCV和项目中的uEye库的单个函数,则会发生异常。 If I use either a single function from OpenCV or from uEye, no exception is thrown. 如果我使用来自OpenCV或uEye的单个函数,则不会引发任何异常。 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. 我在Visual Studio中创建了一个C ++ Windows窗体应用程序。 I added to the form a button as well as corresponding function in Form1.h file: 我在Form1.h文件中向表单添加了一个按钮以及相应的功能:

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: 我在Form1.h的开头添加了headeras:

#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. 然后,我必须关闭预编译的头文件选项,并且必须从/ clr:pure更改为/ clr选项,才能成功编译和链接项目。

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. 我想知道,如果我滥用C ++ Windows窗体应用程序,并且不应该包含纯C ++代码,或者OpenCV或uEye库是否确实存在问题。

I would suggest to test this same code in a native project, without managed code. 我建议在没有托管代码的情况下在本机项目中测试相同的代码。 Either MFC or a Win32 console application. MFC或Win32控制台应用程序。

Isn't it 是不是

cvReleaseImage( img );

? (ampersand removed) Also you should check the proper calling convention. (和号已删除)另外,您还应该检查正确的调用约定。

I just ran and compiled those exact lines with OpenCV 1.0 and Visual Studio 2008, with no errors. 我只是使用OpenCV 1.0和Visual Studio 2008运行并编译了这些确切的行,没有错误。 Maybe try creating an empty project which does nothing else but includes the cxcore.h header and then runs those two lines. 也许尝试创建一个空项目,该空项目除了包含cxcore.h标头外什么都不做,然后运行这两行。

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. 抱歉,我将其发布为评论,但还不能。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM