Click here to Skip to main content
13,050,617 members (84,044 online)
Rate this:
Please Sign up or sign in to vote.
Hi all, im very new to programing and playing around with both opencv and the kinect sdk and was just looking for alittle help.

I have managed, by following the sdk examples, display the depth stream and RGB stream of the kinect using openCv, however now i cant seem to do any image processing on the depth stream with out getting an Unhandled exception error.

The error I keep getting states

Unhandled exception at 0x75acb9bc in AdvancedTopic1.exe: Microsoft C++ exception: cv::Exception at memory location 0x002bf41c..

Thanks for any help in advanced

Any way this is my code so far:

//Create Depth Image
int createDepthImage(HANDLE h, IplImage* depth)
const NUI_IMAGE_FRAME * pImageFrame = NULL;
HRESULT hr = NuiImageStreamGetNextFrame(h, 0, &pImageFrame);
if (FAILED (hr))
cout << "Create Depth Image Failed\n";
//system ("PAUSE");
NuiImageBuffer * pTexture = pImageFrame ->pFrameTexture;
pTexture->LockRect (0, &LockedRect, NULL, 0);
if (LockedRect.Pitch != 0)
USHORT * pBuff = (USHORT*) LockedRect.pBits;
for(int i=0; i<(320*240); i++)
BYTE index = pBuff[i]&0x07;
USHORT realDepth = (pBuff[i]&0xFFF8)>>3;
BYTE scale = 255 - (BYTE)(256*realDepth/0x0fff);
buf[CHANNEL*i] = buf[CHANNEL*i+1] =buf[CHANNEL *i+2] =0;
case 0:
buf[CHANNEL*i] = scale/2;
buf[CHANNEL*i+1] = scale/2;
case 1:
case 2:
case 3:
case 4:
case 5:
case 6:
case 7:
cvSetData(depth, buf, 320*CHANNEL);
NuiImageStreamReleaseFrame(h, pImageFrame);
cvShowImage("Depth Image",depth);
cvCvtColor(depth, depth, CV_RGB2GRAY);
return 0;
<pre lang="c++">
The error i keep getting states
Unhandled exception at 0x75acb9bc in AdvancedTopic1.exe: Microsoft C++ exception: cv::Exception at memory location 0x002bf41c..
Thanks for any help in advanced
Posted 24-Oct-11 1:12am
Updated 24-Oct-11 1:14am
Chuck O'Toole 24-Oct-11 7:28am
Sorry dude, Ido not see the definition of 'buf' nor 'CHANNEL', both of which are prime candidates for causing buffer overflows. Need to see them before you can get more help.
Erin Burke 24-Oct-11 7:44am
Sorry forgot to include them
#define CHANNEL 3
BYTE buf[320*240*CHANNEL];

is that all you need?
cariolihome 24-Oct-11 16:26pm
Did You tried to debug code ?
You can locate error more precisely

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Well, just looking at the numbers:

If 'i' can reach 320*240 (from the for loop control)

And if 'CHANNEL' is a constant 3

Then 'buf[CHANNEL*i+1]' and 'buf[CHANNEL*i+2]' are referencing cells outside the defined boundaries of 'buf'.

That's just from looking, I didn't bother trying to debug this thing.
Erin Burke 24-Oct-11 19:15pm
I see thanks for pointing that out, but i cant seem to fix it. if i increase the defined boundaries it throws an exception with out any image processing. Is there another way to convert the depth data to an image that will be easier to manipulate
Chuck O'Toole 24-Oct-11 20:41pm
1) you're asking the wrong guy how to fix your code, I have no idea what any of that image processing is doing
2) rather than worry about making the bounds bigger, you might want to spend time figuring out why you're adding 1 or 2 to set values. Just what the heck do you think you're doing in that code (this is not a question I care about, it's a question you should be asking yourself).
3) all I did was check your array bounds and use, not any logic about processing images.
Erin Burke 24-Oct-11 20:48pm
Thanks for your help anyway, i was not so much asking you personally but rather the community
Chuck O'Toole 25-Oct-11 12:11pm
I guess the one thing I was trying to point out is, you have an algorithm that obviously uses some value of each pixel, computes a 'scale', and store that in a buffer. Where did you get it? Why does that algorithm modify 3 cells in some places? What is the algorithm trying to do with those 3 values? Now, whatever the algorithm, you've obviously missed some important part of the implementation because you compute values that are outside the array bounds, which I doubt is intended behavior of the algorithm. So go back to basics, just what, in words, is 'scale' and why do you need to record it in 3 places sometimes? Answer those and you'll know why it's broken.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170713.1 | Last Updated 24 Oct 2011
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100