1,19 → 1,19 |
/*------------------------------------------------------------------------------------------*\ |
This file contains material supporting chapter 9 of the cookbook: |
Computer Vision Programming using the OpenCV Library. |
by Robert Laganiere, Packt Publishing, 2011. |
Computer Vision Programming using the OpenCV Library. |
by Robert Laganiere, Packt Publishing, 2011. |
|
This program is free software; permission is hereby granted to use, copy, modify, |
and distribute this source code, or portions thereof, for any purpose, without fee, |
subject to the restriction that the copyright notice may not be removed |
or altered from any source or altered source distribution. |
The software is released on an as-is basis and without any warranties of any kind. |
In particular, the software is not guaranteed to be fault-tolerant or free from failure. |
The author disclaims all warranties with regard to this software, any use, |
and any consequent failure, is purely the responsibility of the user. |
This program is free software; permission is hereby granted to use, copy, modify, |
and distribute this source code, or portions thereof, for any purpose, without fee, |
subject to the restriction that the copyright notice may not be removed |
or altered from any source or altered source distribution. |
The software is released on an as-is basis and without any warranties of any kind. |
In particular, the software is not guaranteed to be fault-tolerant or free from failure. |
The author disclaims all warranties with regard to this software, any use, |
and any consequent failure, is purely the responsibility of the user. |
|
Copyright (C) 2010-2011 Robert Laganiere, www.laganiere.name |
\*------------------------------------------------------------------------------------------*/ |
Copyright (C) 2010-2011 Robert Laganiere, www.laganiere.name |
\*------------------------------------------------------------------------------------------*/ |
|
#include <iostream> |
#include <iomanip> |
25,52 → 25,61 |
|
#include "CameraCalibrator.h" |
|
int main() |
int |
main() |
{ |
|
cv::namedWindow("Image"); |
cv::Mat image; |
std::vector<std::string> filelist; |
cv::namedWindow("Image"); |
cv::Mat image; |
std::vector<std::string> filelist; |
|
// generate list of chessboard image filename |
for (int i=1; i<=20; i++) { |
// 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; |
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); |
} |
filelist.push_back(str.str()); |
image = cv::imread(str.str(), 0); |
cv::imshow("Image", image); |
|
// 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()); |
cv::waitKey(100); |
} |
|
// Image Undistortion |
image = cv::imread(filelist[6]); |
cv::Mat uImage= cameraCalibrator.remap(image); |
// 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()); |
|
// 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; |
// Image Undistortion |
image = cv::imread(filelist[6]); |
cv::Mat uImage = cameraCalibrator.remap(image); |
|
imshow("Original Image", image); |
imshow("Undistorted Image", uImage); |
// 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; |
|
cv::waitKey(); |
return 0; |
} |
imshow("Original Image", image); |
imshow("Undistorted Image", uImage); |
|
cv::waitKey(); |
return 0; |
} |