I am new to kinect project And I am implementing a depth threshold when distance is greater than 400mm

`for (UINT y = 0; y < pImg->rows; ++y) { // Get row pointers for Mats const USHORT* pDepthRow = depth->ptr<USHORT>(y); for (UINT x = 0; x < pImg->cols; ++x) { USHORT raw_depth = pDepthRow[x]; SHORT realDepth = NuiDepthPixelToDepth(raw_depth); // If depth value is valid, convert and copy it if (raw_depth != 65535) { if(realDepth >400 ) //greater than 400mm { pImg->at<Vec4b>(y,x)[0] = 255; pImg->at<Vec4b>(y,x)[1] = 255; pImg->at<Vec4b>(y,x)[2] = 255; pImg->at<Vec4b>(y,x)[3] = 255; } else { pImg->at<Vec4b>(y,x)[0] = 0; pImg->at<Vec4b>(y,x)[1] = 0; pImg->at<Vec4b>(y,x)[2] = 0; pImg->at<Vec4b>(y,x)[3] = 0; } } } `

It seems get the correct result but reduces the frame rate massively. When I want to get rid of the loop by using the cv::inRange, but this function only support 8U1C when the raw depth is 16U. So what else can I use to segment the depth according to the real distance?

-------------Problems Reply------------

Try to improve performance by storing a reference to the pixel. Change this:

`if (realDepth > 400) //greater than 400mm`

{

pImg->at<Vec4b>(y,x)[0] = 255;

pImg->at<Vec4b>(y,x)[1] = 255;

pImg->at<Vec4b>(y,x)[2] = 255;

pImg->at<Vec4b>(y,x)[3] = 255;

}

else

{

pImg->at<Vec4b>(y,x)[0] = 0;

pImg->at<Vec4b>(y,x)[1] = 0;

pImg->at<Vec4b>(y,x)[2] = 0;

pImg->at<Vec4b>(y,x)[3] = 0;

}

To this:

(I don´t know what `T`

is because I dont know what `pImg`

is. `T`

should be equal to the return value of the `at`

method. I assume it is `Vec4b`

.)

`T& pixel = pImg->at<Vec4b>(y, x); // probably Vec4b& pixel = ..`

if (realDepth > 400) //greater than 400mm

{

pixel[0] = 255;

pixel[1] = 255;

pixel[2] = 255;

pixel[3] = 255;

}

else

{

pixel[0] = 0;

pixel[1] = 0;

pixel[2] = 0;

pixel[3] = 0;

}