Click here to Skip to main content
15,886,806 members

Kinect SDK and openCV image processing throwing an unhandled exception error

Erin Burke asked:

Open original thread
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:

C++
//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;
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
Tags: C++, Kinect, Image Processing

Plain Text
ASM
ASP
ASP.NET
BASIC
BAT
C#
C++
COBOL
CoffeeScript
CSS
Dart
dbase
F#
FORTRAN
HTML
Java
Javascript
Kotlin
Lua
MIDL
MSIL
ObjectiveC
Pascal
PERL
PHP
PowerShell
Python
Razor
Ruby
Scala
Shell
SLN
SQL
Swift
T4
Terminal
TypeScript
VB
VBScript
XML
YAML

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the http://www.codeproject.com/info/cpol10.aspx.



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900