예제 #1
0
int main()
{

	cv::namedWindow("Image");
	cv::Mat image;
	std::vector<std::string> filelist;

	// generate list of chessboard image filename
	for (int i=1; i<=20; i++) {

		std::stringstream str;
		str << "../chessboards/chessboard" << std::setw(2) << std::setfill('0') << i << ".jpg";
		std::cout << str.str() << std::endl;

		filelist.push_back(str.str());
		image= cv::imread(str.str(),0);
		cv::imshow("Image",image);
	
		 cv::waitKey(100);
	}

	// Create calibrator object
    CameraCalibrator cameraCalibrator;
	// add the corners from the chessboard
	cv::Size boardSize(6,4);
	cameraCalibrator.addChessboardPoints(
		filelist,	// filenames of chessboard image
		boardSize);	// size of chessboard
		// calibrate the camera
    //	cameraCalibrator.setCalibrationFlag(true,true);
	cameraCalibrator.calibrate(image.size());

    // Image Undistortion
    image = cv::imread(filelist[6]);
	cv::Mat uImage= cameraCalibrator.remap(image);

	// display camera matrix
	cv::Mat cameraMatrix= cameraCalibrator.getCameraMatrix();
	std::cout << " Camera intrinsic: " << cameraMatrix.rows << "x" << cameraMatrix.cols << std::endl;
	std::cout << cameraMatrix.at<double>(0,0) << " " << cameraMatrix.at<double>(0,1) << " " << cameraMatrix.at<double>(0,2) << std::endl;
	std::cout << cameraMatrix.at<double>(1,0) << " " << cameraMatrix.at<double>(1,1) << " " << cameraMatrix.at<double>(1,2) << std::endl;
	std::cout << cameraMatrix.at<double>(2,0) << " " << cameraMatrix.at<double>(2,1) << " " << cameraMatrix.at<double>(2,2) << std::endl;

    imshow("Original Image", image);
    imshow("Undistorted Image", uImage);

	cv::waitKey();
	return 0;
}
예제 #2
0
int main(){
	vector<string> filelist;
	filelist.push_back("../data/chessboard/left01.jpg");
	filelist.push_back("../data/chessboard/left02.jpg");
	filelist.push_back("../data/chessboard/left03.jpg");
	filelist.push_back("../data/chessboard/left04.jpg");
	filelist.push_back("../data/chessboard/left05.jpg");
	filelist.push_back("../data/chessboard/left06.jpg");
	filelist.push_back("../data/chessboard/left07.jpg");
	filelist.push_back("../data/chessboard/left08.jpg");
	filelist.push_back("../data/chessboard/left09.jpg");
	filelist.push_back("../data/chessboard/left11.jpg");
	filelist.push_back("../data/chessboard/left12.jpg");
	filelist.push_back("../data/chessboard/left13.jpg");
	filelist.push_back("../data/chessboard/left14.jpg");

	filelist.push_back("../data/chessboard/right01.jpg");
	filelist.push_back("../data/chessboard/right02.jpg");
	filelist.push_back("../data/chessboard/right03.jpg");
	filelist.push_back("../data/chessboard/right04.jpg");
	filelist.push_back("../data/chessboard/right05.jpg");
	filelist.push_back("../data/chessboard/right06.jpg");
	filelist.push_back("../data/chessboard/right07.jpg");
	filelist.push_back("../data/chessboard/right08.jpg");
	filelist.push_back("../data/chessboard/right09.jpg");
	filelist.push_back("../data/chessboard/right11.jpg");
	filelist.push_back("../data/chessboard/right12.jpg");
	filelist.push_back("../data/chessboard/right13.jpg");
	filelist.push_back("../data/chessboard/right14.jpg");

	cv::Size boardSize(9,6);
	CameraCalibrator ccalibrator;
	ccalibrator.addChessboardPoints(filelist, boardSize);

	cv::Size imageSize(640, 480);
	ccalibrator.calibrate(imageSize);

	ccalibrator.print();

	Mat distorted = imread(filelist[0], cv::IMREAD_GRAYSCALE);
	imshow("distorted image", distorted);
	imshow("undistorted image", ccalibrator.remap(distorted));

	waitKey();
	return 0;
}