Kinect深度分割帧率

时间:2015-04-25 21:29:38

标签: c++ opencv kinect

我是kinect项目的新手 当距离大于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;
            }
        }

    }

似乎得到了正确的结果,但大幅降低了帧速率。 当我想通过使用cv :: inRange摆脱循环时,但是当原始深度为16U时,此功能仅支持8U1C。 那么我还可以根据实际距离来分割深度呢?

1 个答案:

答案 0 :(得分:0)

尝试通过存储对像素的引用来提高性能。 改变这个:

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;
}

对此:
(我不知道T是什么,因为我不知道pImg是什么。 T应该等于at方法的返回值。我认为它是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;
}