Go to most recent revision | Details | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 3 | PointedEar | 1 | /*------------------------------------------------------------------------------------------*\ |
| 2 | This file contains material supporting chapter 9 of the cookbook: |
||
| 3 | Computer Vision Programming using the OpenCV Library. |
||
| 4 | by Robert Laganiere, Packt Publishing, 2011. |
||
| 5 | |||
| 6 | This program is free software; permission is hereby granted to use, copy, modify, |
||
| 7 | and distribute this source code, or portions thereof, for any purpose, without fee, |
||
| 8 | subject to the restriction that the copyright notice may not be removed |
||
| 9 | or altered from any source or altered source distribution. |
||
| 10 | The software is released on an as-is basis and without any warranties of any kind. |
||
| 11 | In particular, the software is not guaranteed to be fault-tolerant or free from failure. |
||
| 12 | The author disclaims all warranties with regard to this software, any use, |
||
| 13 | and any consequent failure, is purely the responsibility of the user. |
||
| 14 | |||
| 15 | Copyright (C) 2010-2011 Robert Laganiere, www.laganiere.name |
||
| 16 | \*------------------------------------------------------------------------------------------*/ |
||
| 17 | |||
| 18 | #include <iostream> |
||
| 19 | #include <iomanip> |
||
| 20 | #include <vector> |
||
| 21 | #include <opencv2/core/core.hpp> |
||
| 22 | #include <opencv2/imgproc/imgproc.hpp> |
||
| 23 | #include <opencv2/highgui/highgui.hpp> |
||
| 24 | #include <opencv2/features2d/features2d.hpp> |
||
| 25 | |||
| 26 | #include "CameraCalibrator.h" |
||
| 27 | |||
| 28 | int main() |
||
| 29 | { |
||
| 30 | |||
| 31 | cv::namedWindow("Image"); |
||
| 32 | cv::Mat image; |
||
| 33 | std::vector<std::string> filelist; |
||
| 34 | |||
| 35 | // generate list of chessboard image filename |
||
| 36 | for (int i=1; i<=20; i++) { |
||
| 37 | |||
| 38 | std::stringstream str; |
||
| 39 | str << "../chessboards/chessboard" << std::setw(2) << std::setfill('0') << i << ".jpg"; |
||
| 40 | std::cout << str.str() << std::endl; |
||
| 41 | |||
| 42 | filelist.push_back(str.str()); |
||
| 43 | image= cv::imread(str.str(),0); |
||
| 44 | cv::imshow("Image",image); |
||
| 45 | |||
| 46 | cv::waitKey(100); |
||
| 47 | } |
||
| 48 | |||
| 49 | // Create calibrator object |
||
| 50 | CameraCalibrator cameraCalibrator; |
||
| 51 | // add the corners from the chessboard |
||
| 52 | cv::Size boardSize(6,4); |
||
| 53 | cameraCalibrator.addChessboardPoints( |
||
| 54 | filelist, // filenames of chessboard image |
||
| 55 | boardSize); // size of chessboard |
||
| 56 | // calibrate the camera |
||
| 57 | // cameraCalibrator.setCalibrationFlag(true,true); |
||
| 58 | cameraCalibrator.calibrate(image.size()); |
||
| 59 | |||
| 60 | // Image Undistortion |
||
| 61 | image = cv::imread(filelist[6]); |
||
| 62 | cv::Mat uImage= cameraCalibrator.remap(image); |
||
| 63 | |||
| 64 | // display camera matrix |
||
| 65 | cv::Mat cameraMatrix= cameraCalibrator.getCameraMatrix(); |
||
| 66 | std::cout << " Camera intrinsic: " << cameraMatrix.rows << "x" << cameraMatrix.cols << std::endl; |
||
| 67 | std::cout << cameraMatrix.at<double>(0,0) << " " << cameraMatrix.at<double>(0,1) << " " << cameraMatrix.at<double>(0,2) << std::endl; |
||
| 68 | std::cout << cameraMatrix.at<double>(1,0) << " " << cameraMatrix.at<double>(1,1) << " " << cameraMatrix.at<double>(1,2) << std::endl; |
||
| 69 | std::cout << cameraMatrix.at<double>(2,0) << " " << cameraMatrix.at<double>(2,1) << " " << cameraMatrix.at<double>(2,2) << std::endl; |
||
| 70 | |||
| 71 | imshow("Original Image", image); |
||
| 72 | imshow("Undistorted Image", uImage); |
||
| 73 | |||
| 74 | cv::waitKey(); |
||
| 75 | return 0; |
||
| 76 | } |