OptiTrack SDK and OpenCV trouble!

Post Reply
Has981
Posts: 4
Joined: Sun Sep 13, 2009 7:49 am

OptiTrack SDK and OpenCV trouble!

Post by Has981 »

Hi all, I'm trying to use OpenCv with the OptiTrack SDK but I'm getting a crash when calling m_frame->GetFrameImage(...)

This strange phenomenon seems to happen if certain OpenCv functions are called anywhere in my programme. I've been able to connect to the camera and obtain an OpenCv frame using the GetFrameImage function after I took out the seemingly conflicting functions... here are the OpenCv functions I had to remove in order to get it to run:

cvNamedWindow
cvDestroyWindow
cvShowImage
cvWaitKey
cvLoadImage
cvSaveImage
cvCreateCameraCapture
cvSetCaptureProperty
cvGetCaptureProperty
cvReleaseCapture

Of course now I'm not able to check if my programme is working correctly but at least it's not crashing. Also, it doesn't seem to matter where any of these functions are being called as long as there is a call at some point. Of course there might be other functions that would cause a crash which I'm not using in my programme.

here is a simple programme I've written while trying to get to the bottom of this:

http://pastebin.com/m3f7f63ef

Does anybody have an idea about whats causing this to happen? Or how to fix it? would very much appreciate any kind of help.

Note: my OptiTrack SDK is: Official Release - Version 1.3.035
and my camera is the SLIM V100 (with the chassis).

Thanks in advance.
VincentG
Posts: 7728
Joined: Mon Jul 17, 2006 5:00 am
Location: Corvallis, Oregon

Re: OptiTrack SDK and OpenCV trouble!

Post by VincentG »

I would recommend try reducing your CHANNELS definition to 1 (from 3) and try to perform everything using 1-byte per pixel buffers.
beckdo
Posts: 520
Joined: Tue Jan 02, 2007 2:02 pm

Re: OptiTrack SDK and OpenCV trouble!

Post by beckdo »

The GetFrameImage() method is dangerous because you're passing a pointer to a buffer for the SDK to populate with camera image data. There is an assumption about how large that buffer is. If you don't have it sized correctly, it will cause memory corruption and subsequent strangeness.
Has981
Posts: 4
Joined: Sun Sep 13, 2009 7:49 am

Re: OptiTrack SDK and OpenCV trouble!

Post by Has981 »

Thanks Vincent and Doug for the suggestions...

As for the # Channels, I've tried reducing that to 1 as suggested but I'm still getting the crash.

In order to make sure I'm passing the correct-sized buffer to GetFrameImage(), I tried to pass a dynamically created array of bytes rather than the IplImage. The tmpBuffer has a size of: m_width * m_height * CHANNELS * sizeof(byte) which should be an exact fit according to the documentation of the SDK. (PixelWidth x PixelHeight x (BitsPerPixel / 8)) sadly to no avail. Same crash when mentioned OpenCv functions exist in the code.

Here is the modified code:
http://pastebin.com/d5153784d
(changes are at line 8, 142 and 153)
Any thoughts?
Thanks
beckdo
Posts: 520
Joined: Tue Jan 02, 2007 2:02 pm

Re: OptiTrack SDK and OpenCV trouble!

Post by beckdo »

well, let me make one more suggestion to rule out the suggested issue. What happens if you don't call GetFrameImage(). Does that keep things stable? If it's still unstable. We'll try to roll-up our sleeves and see what's causing the problems during execution.
Has981
Posts: 4
Joined: Sun Sep 13, 2009 7:49 am

Re: OptiTrack SDK and OpenCV trouble!

Post by Has981 »

Doug, I did as you said and *did not* crash (but as you can guess now I don't have an image to process). Since I'm pretty newbe I'm not quite sure I'm following you on this.. are you suggesting the problem is in the call to GetFrameImage specifically? The parameters look fine to me.
VincentG
Posts: 7728
Joined: Mon Jul 17, 2006 5:00 am
Location: Corvallis, Oregon

Re: OptiTrack SDK and OpenCV trouble!

Post by VincentG »

Please send a copy of your sample projec to support.
Post Reply