2012-10-21 19 views
5

Utilizzo l'esempio C++ Kinect SDK (1.6) DepthBasicsD2D C++ per acquisire il frame di profondità da kinect e voglio eseguire il rilevamento blob in OpenCV con i dati.Kinect SDK Depth Data (C++) a OpenCV?

Ho configurato OpenCV con l'esempio e ho compreso anche il funzionamento di base dell'esempio.

Ma in qualche modo non c'è aiuto da nessuna parte ed è difficile capire come prendere i dati dei pixel da Kinect e passare alla struttura IplImage/cv :: Mat di OpenCV.

Qualche idea su questo problema?

risposta

2

Questo potrebbe aiutare a convertire le immagini a colori e profondità Kinect e le immagini di profondità per le rappresentazioni 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; 
} 
+1

Non v'è alcuna necessità di allocare dinamicamente cv :: Mat. – vinjn