Various problems with OpenCv addon

I’ll describe them in sections, but they might all be related which is why I have them in one post.

Any ideas to the following would be most welcome…

1) CvMemStorage causing Access violation

My code looks like this:

  
  
// .h declare  
CvMemStorage * storage;  
  
// .cpp setup  
storage = 0;  
  
// .cpp update  
cvClearMemStorage( storage );  
  

This builds fine, but gives the following runtime error…

Unhandled exception at 0x006f6b27 in openFrameworksApp.exe: 0xC0000005: Access violation reading location 0xabababb7.

2) <default_face_cascade> not included in addon?

I believe it is built into opencv now, so doesn’t require the xml files?

// this doesnt find the cascade
cascade = (CvHaarClassifierCascade*)cvLoad("<default_face_cascade>", 0, 0, 0 );

3) cascade = crashes .exe outside of IDE

I’m using MS VC++ Express. If I run my program in windows, it crashes with the typical windows alert (i.e. do you want to report to microsoft).

If I run in the IDE by Debug > Start without Debugging, it crashes in the same way. If I just debug (Debug > Start debugging) the program runs fine.

hi chris,

quick responses, and more detail when I have more time:

**1) CvMemStorage causing Access violation **

it looks like you are not actually allocating it, so that clearning it would cause a problem. dont have a the CV reference in front of me, but take a look at the contour finder to see the allocation call

**2) <default_face_cascade> not included in addon? **

currently the addon does very basic opencv stuff and doesnt have face detection wrapped up (or much of opencv, for that matter). for now, the idea with the opencv addon is just to get basic stuff (grayscale images, contour detection) and to provide a general in to opencv , but not to do everything. since some nice projects are being built with the face detection (see the examples forum for one in particular) it would be nice to wrap it…

**3) cascade = crashes .exe outside of IDE **

somewhere in visual studio, there is a something like a “current working directory” for debugging or running the app. See the text file readme in the 0.02 download – take a look at that, it´s my first guess as to why you might see problems running in different ways. another guess is an uninitialized variable, or something like that (usually voodoo like that is based on some simple memory misusages). If you want to post the project as a zip, happy to take a look and try to debug it. you can link here or email or PM

hope that helps!
zach

Hi Zach, thanks.

Just in response to problem 2. Isn’t the openCV addon a wrapper for openCV functions? Like greyscale image, contours etc. I mean the actual openCV lib that is included is the same as the openCV 1.0 library?

( \v0.02\libs\opencv\ i mean, not \v0.02\libs\openFrameworks\computerVision\ )

I started writing my own wrapper in the same way that ofCvGreyscaleImage works, called ofCvFace. This is based on the default face example provided with openCv, the same thing Diego has used here.

Looking at Diegos code, it appears that the changes to the opencvaddon have nothing to do with face detection, but other functions relating to his specific project.

The only difference I can see between mine and in diegos is how the storage is declared.

In his, at the top of .cpp it says (above everything else, not in a function)
static CvMemStorage* storage = 0;

Where as in my .h declaration I have (private):
CvMemStorage * storage;

Then I have at the top of setup:
storage = 0;
storage = cvCreateMemStorage(0);

We both have
cvClearMemStorage( storage );

This is where my confusion comes from, there must be a big problem in the way I am declaring it?