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:
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";
}
NuiImageBuffer * pTexture = pImageFrame ->pFrameTexture;
KINECT_LOCKED_RECT LockedRect;
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;
switch(index)
{
case 0:
buf[CHANNEL*i] = scale/2;
buf[CHANNEL*i+1] = scale/2;
buf[CHANNEL*i+2]=scale/2;
break;
case 1:
buf[CHANNEL*i]=scale;
break;
case 2:
buf[CHANNEL*i+1]=scale;
break;
case 3:
buf[CHANNEL*i+2]=scale;
break;
case 4:
buf[CHANNEL*i]=scale;
buf[CHANNEL*i+1]=scale;
break;
case 5:
buf[CHANNEL*i]=scale;
buf[CHANNEL*i+2]=scale;
break;
case 6:
buf[CHANNEL*i+1]=scale;
buf[CHANNEL*i+2]=scale;
break;
case 7:
buf[CHANNEL*i]=255-scale/2;
buf[CHANNEL*i+1]=255-scale/2;
buf[CHANNEL*i+2]=255-scale/2;
break;
}
}
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