Opencv2.3 read the depth information and color image of Kinect
By http://blog.csdn.net/moc062066
Opencv2.3 can directly read the depth information and color image of Kinect, but it is required when compiling opencv.Note thatFor more information, see here.
// Moc062066 // 20111021 /// * # include <opencv2/CORE/core. HPP> // basic opencv structures (CV: mat, scalar) # include <opencv2/highgui. HPP> // opencv window I/ousing namespace CV; */# include <opencv2/opencv. HPP> using namespace CV; # include <iostream> using namespace STD; static void help () {cout <"Usage: Hit any key to quit! "<Endl <" Kinect opening... "<Endl;} int main (INT argc, char ** argv) {help (); videocapture capture (cv_cap_openni); If (! Capture. isopened () {cerr <"no device has derected! "<Endl; Return-1 ;}cout <" width "<capture. get (cv_cap_prop_frame_width) <Endl <"heigth" <capture. get (cv_cap_prop_frame_height) <Endl; STD: String rgb_wnd = "RGB camera"; STD: String depth_wnd = "depth camera"; namedwindow (rgb_wnd, cv_window_autosize ); namedwindow (depth_wnd, cv_window_autosize); For (;) {mat depthmap; MAT rgbimage; capture. grab (); // depthmap XYZ in meters (cv_32fc3). XYZ is the space location capture of each point in the retrieved vertex cloud. retrieve (depthmap, cv_cap_openni_point_cloud_map); // color image (cv_8uc3) capture. retrieve (rgbimage, token); imshow (rgb_wnd, rgbimage); imshow (depth_wnd, depthmap); If (waitkey (30)> = 0) {break ;}} return 0 ;}
Result: