// Gets the colour and depth data from the Kinect sensor. bool GetColorAndDepthImages(ColorImage& colorImage, DepthImage& depthImage) { XnStatus rc = XN_STATUS_OK; // Read a new frame, blocking operation rc = deviceContext.WaitAnyUpdateAll(); if (rc != XN_STATUS_OK) { /*LOGE("Read failed: %s\n", xnGetStatusString(rc));*/ throw rc; } // Get handles to new data static ImageMetaData colorImageMetaData; static DepthMetaData depthImageMetaData; colorImageGenerator.GetMetaData(colorImageMetaData); depthImageGenerator.GetMetaData(depthImageMetaData); // Validate images if (!depthImageGenerator.IsValid() || !colorImageGenerator.IsValid()) { /*LOGE("Error: Color or depth image is invalid.");*/ throw 1; } if (colorImageMetaData.Timestamp() <= mostRecentRGB) return false; // Fetch pointers to data const XnRGB24Pixel* pColorImage = colorImageMetaData.RGB24Data(); //g_depth.GetRGB24ImageMap() const XnDepthPixel* pDepthImage = depthImageMetaData.Data();// g_depth.GetDepthMap(); // Copy data over to arrays memcpy(colorImage.data, pColorImage, sizeof(colorImage.data)); memcpy(depthImage.data, pDepthImage, sizeof(depthImage.data)); colorImage.rows = colorImage.maxRows; colorImage.cols = colorImage.maxCols; depthImage.rows = depthImage.maxRows; depthImage.cols = depthImage.maxCols; mostRecentRGB = colorImageMetaData.Timestamp(); return true; }
void OpencvModule::DrawEdges(ImageMetaData& g_imageMD){ int key=0; //for opencv Mat, accessing buffer Mat rgb(480,640,CV_8UC3,(uchar*)g_imageMD.WritableData()); cvtColor(rgb,gray,CV_RGB2GRAY); //EdgesRgb Canny(gray,grayedge,fThresCanny1,fThresCanny2); cvtColor(grayedge,rgbedge,CV_GRAY2BGR); float aux=((float)g_imageMD.Timestamp())/1E6; QVariant time_double(aux); putText(rgbedge,"Time:", cvPoint(460,30),5,1,cvScalar(255, 255, 255, 0),1,1); putText(rgbedge,time_double.toString().toStdString(), cvPoint(535,30),6,0.6,cvScalar(255, 255, 255, 0),1,1); imshow("Caremedia Kinect Viewer",rgbedge); key = waitKey(5); }
void OpencvModule::DrawRGB(ImageMetaData& g_imageMD){ int key=0; Mat RGB(480,640,CV_8UC3,(uchar*)g_imageMD.WritableData()); cvtColor(RGB,image_BGR,CV_RGB2BGR); float aux=((float)g_imageMD.Timestamp())/1E6; QVariant time_double(aux); putText(image_BGR,"Time:", cvPoint(460,30),5,1,cvScalar(255, 255, 255, 0),1,1); putText(image_BGR,time_double.toString().toStdString(), cvPoint(535,30),6,0.6,cvScalar(255, 255, 255, 0),1,1); imshow("Caremedia Kinect Viewer",image_BGR); key = waitKey(5); }