【问题标题】:Kinect depth Segmentation frame rateKinect 深度分割帧率
【发布时间】:2015-07-04 10:37:48
【问题描述】:

我是 kinect 项目的新手 当距离大于 400 毫米时,我正在实施深度阈值

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。 那么我还能用什么来根据真实距离分割深度呢?

【问题讨论】:

    标签: c++ opencv kinect


    【解决方案1】:

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

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

    【讨论】:

    • 谢谢,它确实将 fps 从 8 提升到 15!
    • @ChengMa 很高兴能帮到你。如果它解决了您的问题,请接受答案。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-04-02
    • 1970-01-01
    • 2012-12-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-06-24
    相关资源
    最近更新 更多