opencv2.3读取kinect深度信息和彩色图像

opencv2.3读取kinect深度信息和彩色图像

作者:http://blog.csdn.net/moc062066

opencv2.3可以直接读取kinect的深度信息和彩色图像,但是在编译opencv的时候需要注意一点,具体参考这里。


//moc062066
//20111021
//
/*
#include <opencv2/core/core.hpp>        // Basic OpenCV structures (cv::Mat, Scalar)
#include <opencv2/highgui/highgui.hpp>  // OpenCV window I/O
using 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就是获取的点云中每一点的空间位置
		capture.retrieve(depthMap,CV_CAP_OPENNI_POINT_CLOUD_MAP);
		
		//color image (CV_8UC3)
		capture.retrieve(rgbImage,CV_CAP_OPENNI_BGR_IMAGE);
			
		imshow(rgb_wnd,rgbImage);
		imshow(depth_wnd,depthMap);

		if ( waitKey(30) >= 0 ) {
			break ;
		}
	}
	return 0 ;
}

结果:

opencv2.3读取kinect深度信息和彩色图像_第1张图片


你可能感兴趣的:(image,String,basic)