Capture the IR stream from PrimeSensor

118 views
Skip to first unread message

lklaus77

unread,
Jul 6, 2011, 12:32:59 PM7/6/11
to OpenNI
Hi all,
I tried to get the IR stream from my PrimeSensor. I got a output but
it isn't shown correctly.
Here are some pictures.
http://i53.tinypic.com/2j3p4hs.png

A correct image should look like the pic in the upper left corner.
This pic is taken from the NiViewer sample.
The result image of my program is in the upper right corner. The image
is 16bit unsigned (IPL_DEPTH_16U).
And the last picture in the lower right corner is the same output from
my program as 8bit image (IPL_DEPTH_8U) instead of a 16bit image.

Does anybody know what I have done wrong?
Would be very glad for any help!
Cheer,
Klaus

This is my code

XnStatus nRetVal = XN_STATUS_OK;
nRetVal = context.Init();
nRetVal = ir.Create(context);

nRetVal = context.StartGeneratingAll();
IplImage* image = cvCreateImage(cvSize(640,480), IPL_DEPTH_16U, 1);
cvNamedWindow("Window", CV_WINDOW_AUTOSIZE);

while (true)
{
-----nRetVal = context.WaitAndUpdateAll();
-----ir.GetMetaData(irMD);
-----const XnIRPixel* pIrRow = irMD.Data();

-----for (XnUInt y = 0; y < irMD.YRes(); y++)
-----{
----------const XnIRPixel* pIRmap = pIrRow;
----------for (XnUInt x = 0; x < irMD.XRes(); x++, pIRmap++)
----------{
---------------((uchar *)(image ->imageData + y*image ->widthStep))
[x*image ->nChannels + 0] = pIrRow[x];
----------}
----------pIrRow += irMD.XRes();
-----}
-----cvShowImage("Window", image);
}

Udaya Wijenayake

unread,
Jul 7, 2011, 10:28:31 PM7/7/11
to OpenNI
Hi,

Here is the code I used for accessing IR stream. Check this and find
whats the wrong with your code.



XnStatus nRetVal = XN_STATUS_OK;
Context context;
nRetVal = context.Init();
CHECK_RC(nRetVal, "Initialize context");

IRGenerator ir;
nRetVal = ir.Create(context);

XnMapOutputMode mapMode;
mapMode.nXRes = 640;
mapMode.nYRes = 480;
mapMode.nFPS = 30;
nRetVal = ir.SetMapOutputMode(mapMode);

nRetVal = context.StartGeneratingAll();
IRMetaData irMD;

int key = 0;
int i=0;

while(key!=27)
{
context.WaitAnyUpdateAll();//wait and error processing

// data grap
ir.GetMetaData(irMD);

// ir
const XnIRPixel* pIrRow = irMD.Data();

//for opencv Mat
Mat ir16(480,640,CV_16SC1,(unsigned
short*)irMD.WritableData());
Mat irMat;
ir16.convertTo(irMat,CV_8U);

imshow("IR Stream", irMat);
key = waitKey(1);

}
Message has been deleted
Message has been deleted

lklaus77

unread,
Jul 21, 2011, 4:21:28 AM7/21/11
to OpenNI
Hm, I got it ... even a stupid mistake. I had have to change uchar
into ushort. Thank you very much Udaya Wijenayake!!
But now I have another new Problem. I get the continuous IR stream of
the IR camera, but the IR projector is jittering. Consequently I see
the point pattern every two upto three seconds. Do I have to
initialize the IR stream in another way?

void Prog::showStream()
{
Context context;
IRGenerator ir;
IRMetaData irMD;
XnStatus nRetVal = XN_STATUS_OK;

nRetVal = context.Init();
nRetVal = ir.Create(context); // create image generator

XnMapOutputMode mapModeVGA;
mapModeVGA.nXRes = 640;
mapModeVGA.nYRes = 480;
mapModeVGA.nFPS = 30;
nRetVal = ir.SetMapOutputMode(mapModeVGA);

nRetVal = context.StartGeneratingAll();
IplImage* imgIR = cvCreateImage(cvSize(640,480), IPL_DEPTH_16U, 1);
while (true)
{
nRetVal = context.WaitAndUpdateAll();
ir.GetMetaData(irMD);
const XnIRPixel* pIrRow = irMD.Data();
for (XnUInt32 y = 0; y < irMD.YRes(); y++)
{
const XnIRPixel* pIR = pIrRow;
for (XnUInt32 x = 0; x < irMD.XRes(); x++, pIR++)
{
((ushort *)(imgIR->imageData + y*imgIR->widthStep))[x*imgIR-
>nChannels + 0] = pIrRow[x];
}
pIrRow += irMD.XRes();
}
}
}

On 8 Jul., 04:28, Udaya Wijenayake <udaya.u...@gmail.com> wrote:
> Hi,
>
> Here is the code I used for accessingIRstream. Check this and find
>                 imshow("IRStream", irMat);
>                 key = waitKey(1);
>
>         }
Reply all
Reply to author
Forward
0 new messages