2012-10-21 4 views
5

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

私はこの例でOpenCVを設定しており、この例の基本的な動作も理解しています。

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

この問題について考えていますか?

答えて

2

これは、OpenCVの表現にKinectの色と深さの画像と奥行き画像を変換する助けることができる:

// 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; 
} 
+1

動的CV ::マットを割り当てる必要はありません。 – vinjn

関連する問題