简体   繁体   中英

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.

The error I get is:

Unhandled exception at 0x000007feefbf4938 in Testing.exe: 0xC0000005: Access violation writing location 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. I've had similar problems when I tried to load files with mixed release and debug dlls.

See this post.

No guesses on why your load line would cause an access violation only for release build. So, the next step is to instrument your OpenCV release binaries with logging, or printfs, or whatever works for you. This type of debugging works in this scenario since you have the source for OpenCV and the ability to recompile with VS2010.

I believe your error is in the 'loading' of the XML file and your 'working directory' setting in your project settings.

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?

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

Try adding these lines of code to another project, with release version working and where you already use opencv. If it works, then the problem is in the configuration settings.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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