我正在使用OpenCV为模拟器编写插件。我做了一个OpenCV项目(单个 - 不是插件),它工作正常。当我将OpenCV库添加到插件项目时,我添加了所有需要的库。 Visual Studio 2010不会突出显示任何带红色的代码行。一切看起来都很好,编译得很好。
但是在执行过程中,程序在任何cv :: function上都会出现运行时错误。例如:cv::imread
或cv::imwrite
。但是,如果我将其替换为cvLoadImage()
和cvSaveImage()
,则可以正常使用。
为什么会这样?我不想在old-api-style
(cvFnName)中重写整个脚本。这意味着我应该将所有Mat对象更改为IplImages,依此类推。
更新
// preparing template
ifstream ifile(tmplfilename);
if ( !FILE_LOADED && ifile ) {
// loading template file
Mat tmpl = cv::imread(tmplfilename, 1); // << here occurs error
FILE_LOADED = true;
}
Mat src;
Bmp2Mat(hDC, hBitmap, src);
TargetDetector detector(src, tmpl);
detector.detectTarget();
如果我改为:
if ( !FILE_LOADED && ifile ) {
IplImage* tmpl = 0;
tmpl = cvLoadImage(tmplfilename, 1); // no error occurs
}
然后没有错误发生。
早期它显示了一些运行时错误。现在,我想复制确切的消息,它只是崩溃应用程序(模拟器,我插件)。它显示窗口错误 - 杀死进程或否。 (我无法显示确切的消息,因为我现在正在使用俄语窗口)
更新2
.vcproj文件:
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Source Files">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="Header Files">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hpp;hxx;hm;inl;inc;xsd</Extensions>
</Filter>
<Filter Include="Resource Files">
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="main.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="screenCapture.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<Library Include="..\..\..\lib\orbiter.lib" />
<Library Include="..\..\..\lib\Orbitersdk.lib" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="screenCapture.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
</Project>
我在.main.cpp
中的内容:
#pragma comment (lib, "gdiplus.lib")
#include <orbitersdk.h>
#include <windows.h>
#include <gdiplus.h>
#include <io.h>
#include <stdio.h>
#include <time.h>
#include <comdef.h>
#include <cv.h>
#include <cxcore.h>
#include <highgui.h>
#include "screenCapture.h"
另一次更新:
我在VS2010的输出中收到了这条消息:
First-chance exception at 0x5c4dd90c (msvcr100d.dll) in orbiter.exe: 0xC0000005: Access violation reading location 0x00706d62.
Unhandled exception at 0x5c4dd90c (msvcr100d.dll) in orbiter.exe: 0xC0000005: Access violation reading location 0x00706d62.
The program '[1744] orbiter.exe: Native' has exited with code -1073741819 (0xc0000005).
错误的截图(正如我所说,抱歉,这是俄语): http://img846.imageshack.us/img846/3316/russinerror.png 我的免费翻译:
Execution of program "orbiter.exe" was terminated
Windows can find a solution:
-> Find a decision in the Internet and close the application
-> Close the application