int OpencvModule::DrawDepth(DepthMetaData& g_depthMD){ if (!cvGetWindowHandle("Caremedia Kinect Viewer")) // if(window has been closed) { if (windowopened) {windowopened=false; return 0; } else windowopened = true; } int key=0; //for opencv Mat, accessing buffer Mat depth16(480,640,CV_16UC1,(unsigned short*)g_depthMD.WritableData()); depth16.convertTo(depth8,CV_8U,-255/4096.0,255); Pseudocolor->pseudocolor(depth8,rgbdepth); //CvFont font; //cvInitFont(&font, CV_FONT_HERSHEY_SIMPLEX, 1.0, 1.0, 0, 1, CV_AA); float aux=((float)g_depthMD.Timestamp())/1E6; QVariant time_double(aux); QTime t = videostarttime.addSecs((int)aux).addMSecs((int)(aux - (int)aux ) * 1000); float percent = (float)100*(float)g_depthMD.FrameID() / (float)NumFrames; QString a; putText(rgbdepth,"Time:"+t.toString().toStdString(), cvPoint(460,30),5,1,cvScalar(255, 255, 255, 0),1,1); putText(rgbdepth, a.setNum(percent,'f',2).append("%").toStdString(), cvPoint(5,30),6,0.6,cvScalar(255, 255, 255, 0),1,1); imshow("Caremedia Kinect Viewer",rgbdepth); key = waitKey(5); }
bool pointerNextFrame(int &xInOut, int &yInOut, int &zInOut) { rs::device & dev = *app_state.dev; if (dev.is_streaming()) dev.wait_for_frames(); auto t1 = std::chrono::high_resolution_clock::now(); nexttime += std::chrono::duration<float>(t1 - t0).count(); t0 = t1; ++frames; if (nexttime > 0.5f) { fps = frames / nexttime; frames = 0; nexttime = 0; } const rs::stream tex_stream = app_state.tex_streams[app_state.index]; app_state.depth_scale = dev.get_depth_scale(); app_state.extrin = dev.get_extrinsics(rs::stream::depth, tex_stream); app_state.depth_intrin = dev.get_stream_intrinsics(rs::stream::depth); app_state.tex_intrin = dev.get_stream_intrinsics(tex_stream); app_state.identical = app_state.depth_intrin == app_state.tex_intrin && app_state.extrin.is_identity(); // setup the OpenCV Mat structures cv::Mat depth16(app_state.depth_intrin.height, app_state.depth_intrin.width, CV_16U, (uchar *)dev.get_frame_data(rs::stream::depth)); rs::intrinsics color_intrin = dev.get_stream_intrinsics(rs::stream::color); cv::Mat rgb(color_intrin.height, color_intrin.width, CV_8UC3, (uchar *)dev.get_frame_data(rs::stream::color)); // ignore depth greater than 800 mm's. depth16.setTo(10000, depth16 > 800); depth16.setTo(10000, depth16 == 0); cv::Mat depth8u = depth16 < 800; cv::Point handPoint(0, 0); for (int y = 0; y < depth8u.rows; ++y) { uchar *d = depth8u.row(y).ptr(); for (int x = 0; x < depth8u.cols; ++x) { if (d[x]) { int floodCount = cv::floodFill(depth8u, cv::Point(x, y), 255); // we have found the top most point if (floodCount > 100) { handPoint = cv::Point(x, y); break; } } } if (handPoint != cv::Point(0, 0)) break; } if (handPoint != cv::Point(0, 0)) cv::circle(depth8u, handPoint, 10, 128, cv::FILLED); imshow("depth8u", depth8u); cv::cvtColor(rgb, rgb, cv::COLOR_BGR2RGB); imshow("rgb", rgb); xInOut = handPoint.x; yInOut = handPoint.y; zInOut = 0; // not using this yet. if (handPoint == cv::Point(0, 0)) return false; return true; }