简体   繁体   English

简单的OpenCV命令在调试模式下工作,但不在发布模式下工作

[英]Simple OpenCV command works in Debug mode but not Release mode

I am trying to load in a training xml file with CascadeClassifier::load() , and it works just fine in Debug mode, but in Release mode I get a runtime error. 我正在尝试使用CascadeClassifier::load()训练xml文件,并且它在调试模式下工作正常,但在发布模式下,我收到运行时错误。

The error I get is: 我得到的错误是:

Unhandled exception at 0x000007feefbf4938 in Testing.exe: 0xC0000005: Access violation writing location 0x0000000000000027. Testing.exe中0x000007feefbf4938处的未处理异常:0xC0000005:访问冲突写入位置0x0000000000000027。

My code is as follows: 我的代码如下:

CascadeClassifier c;
if (!c.load("C:/data/haarcascade_frontalface_alt.xml"))
{
    exit(1);
}

The code crashes on the loading line. 代码在加载线上崩溃。 Why would this happen? 为什么会这样?

make sure you're linking to openCV's release dlls when running in release mode. 确保在发布模式下运行时链接到openCV的发行版dll。 I've had similar problems when I tried to load files with mixed release and debug dlls. 当我尝试使用混合版本和调试dll加载文件时,我遇到了类似的问题。

See this post. 这篇文章。

No guesses on why your load line would cause an access violation only for release build. 没有猜测为什么你的load线只会导致发布版本的访问冲突。 So, the next step is to instrument your OpenCV release binaries with logging, or printfs, or whatever works for you. 因此,下一步是使用日志记录或printfs或任何适合您的OpenCV发布二进制文件。 This type of debugging works in this scenario since you have the source for OpenCV and the ability to recompile with VS2010. 这种类型的调试在这种情况下有效,因为您拥有OpenCV的源代码以及使用VS2010重新编译的能力。

I believe your error is in the 'loading' of the XML file and your 'working directory' setting in your project settings. 我相信您的错误在于XML文件的“加载”和项目设置中的“工作目录”设置。

If you goto the Properties window of your project, make sure the 'Working Directory' in "Debugging" Options is correct. 如果转到项目的“属性”窗口,请确保“调试”选项中的“工作目录”正确无误。 Change the 'Configuration' (between Debug and Release) and you should be able to compare. 更改“配置”(在调试和发布之间),您应该能够进行比较。

You will sometimes get this error when you're trying to read a file that doesn't exist. 当您尝试读取不存在的文件时,有时会出现此错误。 Using local paths which being in the 'wrong' working directory is usually the culprit when it works in one configuration and not another. 使用位于“错误”工作目录中的本地路径通常是它在一个配置而不是另一个配置中工作的罪魁祸首。

EDIT: 编辑:

Does that file exist and is it proper XML? 该文件是否存在且是否是正确的XML?

This is quite strange. 这很奇怪。 Check your options for debug and release version, be sure that you are using the correct version of the libraries. 检查调试和发布版本的选项,确保使用正确版本的库。

I tried running the code on a project of mine, and works fine both in debug and release version, with opencv 2.3.1 我尝试在我的项目上运行代码,并且在调试和发布版本中使用opencv 2.3.1都可以正常工作

Try adding these lines of code to another project, with release version working and where you already use opencv. 尝试将这些代码行添加到另一个项目中,发布版本正常,并且您已经在使用opencv。 If it works, then the problem is in the configuration settings. 如果可行,则问题出在配置设置中。

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

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