Esempio n. 1
0
int main(void) {
	printf("Hello World!\n");
	
	cv::Mat depthMat(cv::Size(640,480), CV_16UC1);
	cv::Mat depthf(cv::Size(640,480), CV_8UC1);
	cv::Mat rgbMat(cv::Size(640,480), CV_8UC3, cv::Scalar(0));
	
	std::list<cv::Mat> images;
	
	Freenect::Freenect freenect;
	CvKinect& device = freenect.createDevice<CvKinect>(0);
	
	device.startVideo();
	
	cv::namedWindow("rgb", CV_WINDOW_AUTOSIZE);
	cv::namedWindow("depth", CV_WINDOW_AUTOSIZE);
	
	while (true) {
		device.getVideo(rgbMat);
		
		// if (images.size() > 0) {
		// 	cv::imshow("rgb", images.front());
		// } else {
			cv::imshow("rgb", rgbMat);
		// }
		
		char key = cv::waitKey(5);
		
		if (key == 'x') {
			break;
		} else if (key == 's') {
			images.push_back(rgbMat.clone());
		}
	}
	
	device.stopVideo();
	
	std::cout << "Images: " << images.size() << std::endl;
	
	for (std::list<cv::Mat>::iterator iter = images.begin(); iter != images.end(); ++iter) {
		cv::imshow("rgb", *iter);
	
		cv::Mat greyMat(cv::Size(640, 480), CV_8UC1, cv::Scalar(0));
	
		cv::cvtColor(*iter, greyMat, CV_RGB2GRAY);
		std::vector<cv::Point2f> corners;
		
		bool found = cv::findChessboardCorners(greyMat, cv::Size(7, 7), corners);
		
		std::cout << "Corners found: " << corners.size() << std::endl;
	}
	
	cv::destroyWindow("depth");
	cv::destroyWindow("rgb");
	
	std::cout << "Exit" << std::endl;
	
	return 0;
}
Esempio n. 2
0
void RGBDViewer::onSaveRGBDImage() {
	CLOG(LTRACE) << name() << "::onSaveRGBDImage";

	std::time_t rawtime;
	std::tm* timeinfo;
	char buffer [80];

	// Generate time postfix.
	std::time(&rawtime);
	timeinfo = std::localtime(&rawtime);
	std::strftime(buffer,80,"%Y-%m-%d-%H-%M-%S",timeinfo);

	// Change compression to lowest.
        vector<int> param;
	param.push_back(CV_IMWRITE_PNG_COMPRESSION);
	param.push_back(0); // MAX_MEM_LEVEL = 9 

	try {
		// Save rgb image.
		if (rgb_img.empty()) {
			LOG(LWARNING) << name() << ": rgb image empty";
		} else {
			std::string tmp_name = std::string(dir) + std::string("/") + std::string(filename) + "_" + buffer + std::string("_rgb.png");
			imwrite(tmp_name, rgb_img, param);
			CLOG(LINFO) << "RGB image saved to file " << tmp_name <<std::endl;
		}
		// Save depth image.
		if (depth_img.empty()) {
			LOG(LWARNING) << name() << ": depth image empty";
		} else {
			std::string tmp_name = std::string(dir) + std::string("/") + std::string(filename) + "_" + buffer + std::string("_depth.png");
			cv::Mat depthf  (cv::Size(640,480),CV_16UC1);
        		depth_img.convertTo(depthf, CV_16UC1, 1);//255.0/2048.0);
			imwrite(tmp_name, depthf);//, param);
			CLOG(LINFO) << "Depth image saved to file " << tmp_name <<std::endl;
		}
	} catch (std::exception &ex) {
		CLOG(LERROR) << "CvWindow::onSaveRGBDImage failed: " << ex.what() << "\n";
	}
}