5

Kinect SDK (1.6) DepthBasicsD2D C++ の例を使用して、kinect から深度フレームを取得し、データを使用して OpenCV でブロブ検出を実行したいと考えています。

この例で OpenCV を構成し、例の基本的な動作も理解しました。

しかし、どういうわけかどこにも助けがなく、Kinect からピクセル データを取得して OpenCV の IplImage/cv::Mat 構造に渡す方法を理解するのは困難です。

この問題について何か考えはありますか?

4

1 に答える 1

2

これは、kinect の色と深度の画像、および深度の画像を OpenCV 表現に変換するのに役立ちます。

// get a CV_8U matrix from a Kinect depth frame 
cv::Mat * GetDepthImage(USHORT * depthData, int width, int height) 
{
    const int imageSize = width * height; 
    cv::Mat * out = new cv::Mat(height, width, CV_8U) ;
    // map the values to the depth range
    for (int i = 0; i < imageSize; i++)
    {
        // get the lower 8 bits
        USHORT depth =  depthData[i];   
        if (depth >= kLower && depth <= kUpper) 
        {
            float y = c * (depth - kLower); 
            out->at<byte>(i) = (byte) y; 
        }
        else
        {
            out->at<byte>(i) = 0; 
        }
    }
    return out; 
};

// get a CV_8UC4 (RGB) Matrix from Kinect RGB frame
cv::Mat * GetColorImage(unsigned char * bytes, int width, int height)
{
    const unsigned int img_size = width * height * 4; 
    cv::Mat * out = new cv::Mat(height, width, CV_8UC4);

    // copy data
    memcpy(out->data, bytes, img_size); 

    return out; 
}
于 2012-11-08T19:42:51.893 に答える