#include "opencv2/core/core.hpp" #include "opencv2/highgui/highgui.hpp" #include using namespace cv; using namespace std; int main(){ VideoCapture capture; capture.open(CAP_OPENNI2); //registration if(capture.get( CAP_PROP_OPENNI_REGISTRATION ) == 0) capture.set(CAP_PROP_OPENNI_REGISTRATION,1); if( !capture.isOpened() ){ cout << "Can not open a capture object." << endl; return -1; } cout << "ready" << endl; for(;;){ Mat depthMap,depthShow; if( !capture.grab() ){ cout << "Can not grab images." << endl; return -1; }else{ if( capture.retrieve( depthMap, CAP_OPENNI_DEPTH_MAP ) ){ const float scaleFactor = 0.05f; depthMap.convertTo( depthShow, CV_8UC1, scaleFactor ); imshow("depth",depthShow); } } if( waitKey( 30 ) == 27 ) break;//esc to exit } }