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; }
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; }
void CalibraCamara( ){ // Se crea una ventana con el nombre "Image" //namedWindow("Imagen"); // Se crea una imagen vacia Mat image; // Se crea un vector que almacenara todos los nombres de las imagenes vector<string> filelist; // ciclo que genera la lista de los nombres de las imagenes //for (int i=1; i<=9; i++) { for (int i=1; i<=20; i++) { // Se genera el nombre para cada imagen incluyendo su ruta stringstream str; str << "IMG" << setw(2) << setfill('0') << i << ".png"; //str << "chessboard" << setw(2) << setfill('0') << i << ".jpg"; //cout << str.str() << endl; // Se agrega el nombre al vector filelist.push_back(str.str()); // Se muestra cada imagen image= imread(str.str(),0); imshow("Image",image); // Retardo para desplegar las imagenes waitKey(100); } // Se crea un objeto de la clase CameraCalibrator CameraCalibrator cameraCalibrator; // Se especifica el numero de esquinas verticales y horizontales internas Size boardSize(8,6); //Size boardSize(6,4); // Se abren todas las imagenes y se extraen sus puntos de las esquinas cameraCalibrator.addChessboardPoints( filelist, // Lista de los nombres de las imagenes boardSize); // Numero de esquinas del patron cvDestroyWindow("Image"); // Calibrando la camara // cameraCalibrator.setCalibrationFlag(true,true); Size size=image.size(); cameraCalibrator.calibrate(size); //Imagen sin distorcion //image = imread("PRUEBA01.png"); //imshow("Imagen Original", image); //Mat uImage= cameraCalibrator.remap(image); // Mostrar la Matriz de la camara Mat cameraMatrix= cameraCalibrator.getCameraMatrix(); ofstream archivo("conf.dat"); archivo << " Camera intrinsic: " << cameraMatrix.rows << "x" << cameraMatrix.cols << endl; archivo << cameraMatrix.at<double>(0,0) << "\t\t" << cameraMatrix.at<double>(0,1) << "\t\t" << cameraMatrix.at<double>(0,2) << endl; archivo << cameraMatrix.at<double>(1,0) << "\t\t" << cameraMatrix.at<double>(1,1) << "\t\t" << cameraMatrix.at<double>(1,2) << endl; archivo << cameraMatrix.at<double>(2,0) << "\t\t" << cameraMatrix.at<double>(2,1) << "\t\t" << cameraMatrix.at<double>(2,2) << endl; archivo.close(); /* cout << " Camera intrinsic: " << cameraMatrix.rows << "x" << cameraMatrix.cols << endl; cout << cameraMatrix.at<double>(0,0) << "\t\t" << cameraMatrix.at<double>(0,1) << "\t\t" << cameraMatrix.at<double>(0,2) << endl; cout << cameraMatrix.at<double>(1,0) << "\t\t" << cameraMatrix.at<double>(1,1) << "\t\t" << cameraMatrix.at<double>(1,2) << endl; cout << cameraMatrix.at<double>(2,0) << "\t\t" << cameraMatrix.at<double>(2,1) << "\t\t" << cameraMatrix.at<double>(2,2) << endl; imshow("Imagen ajustada, sin distorcion", uImage); cvWaitKey(); */ }