12

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?

zebra
  • 6,373
  • 20
  • 58
  • 67
  • 1
    Is this al your code? if yes, probably it's a bug in OpenCV. if not, delete ALL your code around this line and try to localize the bug – Sam Jan 16 '12 at 09:14
  • The C++ interface for Windows gave me lots of headaches already. Try this with the C interface of OpenCV and get ready to celebrate. This question deserves more upvotes. – karlphillip Jan 16 '12 at 17:11
  • 7
    Are you linking debug OpenCv libraries for debug version of you app and Release Opencv for Release version of your app ? I might be worng but you should check it. – Patryk Jan 17 '12 at 18:53

4 Answers4

9

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.

Community
  • 1
  • 1
Ben
  • 4,486
  • 6
  • 33
  • 48
  • 1
    I did the same mistake when adding **Additional Dependencies** in the Linker. changing to `opencv_world330.lib` from `opencv_world330d.lib` fixed it for me. – Sndn Dec 14 '17 at 11:29
  • Wow. Thanks for the help. Was helpless for almost two weeks and finally, this saved the day. – Poornamith Feb 15 '20 at 07:07
0

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.

Chris O
  • 5,017
  • 3
  • 35
  • 42
0

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?

g19fanatic
  • 10,567
  • 6
  • 33
  • 63
  • I will check what you suggested when I get home, but yes it exists and is proper. Like I said, this works perfectly fine in Debug mode, but not release mode. – zebra Jan 17 '12 at 23:27
  • Yep, but if you're starting the code from VS even in release mode, it still will look to the above mentioned "Working Directory" to see where it's suppose to live. If this isn't the same as debug mode AND you're using local paths anywhere (which might be the case), it might be your problem. – g19fanatic Jan 18 '12 at 12:44
0

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.