Camera Calibration Example

advertisement
Camera Calibration Example
Matlab Camera Calibration toolbox
• Go to the website
http://www.vision.caltech.edu/bouguetj/calib_doc/ (an
OpenCV version is also available)
• Follow the steps listed under “Getting Started”, to
download and install the toolbox
• Go through the tutorial under “First calibration example”
– To save time, you don’t need to process all 20 images in this
example. When it asks you for a list of images to use, you can
give it a list of image indices like [2 5 8 10 12] so as to use a
subset of the images.
/* This program just grabs images from the camera, every
time you hit a key. It stores them in "jpg" file, and numbers
them "image00.jpg", "image01.jpg", "image02.jpg", etc.
*/
#include <iostream>
#include <opencv2/opencv.hpp>
#include <string>// for strings
int main(int argc, char* argv[])
{
printf("This program grabs an image from the camera every\n");
printf(" time you hit a key. Hit the ESC key to quit.\n");
cv::VideoCapture cap(0);
// open the default camera
if (!cap.isOpened()) {
// check if we succeeded
printf("error - can't open the input source\n");
cv::waitKey(1000);
return EXIT_FAILURE;
}
cv::waitKey(2000);
// Wait a little if camera needs time to start up
cv::Mat imgInput;
// Allocate image
// Run an infinite loop until user hits the ESC key.
int n = 0;
// number that is appended to each filename
while (1){
cap >> imgInput;
// get image from camera
cv::imshow("Input Image", imgInput);
// show image
// Wait for x ms (0 means wait until a keypress).
char key = cv::waitKey(1);
if (key == 27) break;
// ESC is ascii 27
// If any other key was hit, grab an image.
if (key != -1){
char mytext[80];
sprintf_s(mytext, "image%02d.jpg", n++);
printf("Writing out image to %s\n", mytext);
std::string fnameOut(mytext);
cv::imwrite(fnameOut, imgInput);
}
}
return EXIT_SUCCESS;
}
OpenCV code to grab
images from the camera
and save them to files
Process new example
• Get images from course website
• Take one image and overlay a
straight line onto the image, to
show that there is some lens
distortion
– You can do this in Matlab by
displaying the image (“imshow”)
and selecting the menu item Insert>Line.
If you want to calibrate your own
camera, take pictures of a
calibration pattern consisting of a
checkerboard. A template pattern is
available on the camera calibration
toolbox website
Note that edges of calibration pattern are not straight lines
Calibrate
• Perform a camera calibration using these images
• Give the resulting
– focal lengths
– principal point
– lens distortion parameters
• What is the residual pixel error?
• Undistort one image, and overlay a straight line onto
the image. Show that the lens distortion has been
removed.
Download