Slides Calibration

Download Slides Calibration

Post on 29-Nov-2014

75 views

Category:

Documents

0 download

Embed Size (px)

TRANSCRIPT

<p>OpenCV and rewire camera</p> <p>Camera CalibrationLuis Baumela, Juan Bekios-Calfa</p> <p>Luis Baumela, Juan Bekios-Calfa</p> <p>Camera Calibration</p> <p>OpenCV and rewire camera</p> <p>Outline</p> <p>Camara calibration Homography estimate</p> <p>Luis Baumela, Juan Bekios-Calfa</p> <p>Camera Calibration</p> <p>OpenCV and rewire camera</p> <p>Camara calibration</p> <p>http://opencv.willowgarage.com/documentation/python/camera calibration and 3d reconstruction.html</p> <p>The functions in this section use the so-called pinhole camera model. That is, a scene view is formed by projecting 3D points into the image plane using a perspective transformation. sm = A[R|t]M X t1 Y t2 Z t3 1 </p> <p>u fx v = 0 s 1 0</p> <p>0 fy 0</p> <p>cx r11 r12 r13 cy r21 r22 r23 1 r31 r22 r33</p> <p>Luis Baumela, Juan Bekios-Calfa</p> <p>Camera Calibration</p> <p>OpenCV and rewire camera</p> <p>Camara calibrationWhere (X , Y , Z ) are the coordinates of a 3D point in the world coordinate space. (u, v ) are the coordinates of the projection point in pixels. A is called a camera matrix, or a matrix of intrinsic parameters. (cx , cy ) is a principal point (that is usually at the image center). fx , fy are the focal lengths expressed in pixel-related units. The joint rotation-translation matrix [R|t] is called a matrix of extrinsic parameters. A=?, R=?, t=?</p> <p>Luis Baumela, Juan Bekios-Calfa</p> <p>Camera Calibration</p> <p>OpenCV and rewire camera</p> <p>Camara calibrationhttp://grauonline.de/wordpress/?p=5</p> <p>Luis Baumela, Juan Bekios-Calfa</p> <p>Camera Calibration</p> <p>OpenCV and rewire camera</p> <p>Camara calibrationhttp://www.jesusllor.es/?p=37</p> <p>Luis Baumela, Juan Bekios-Calfa</p> <p>Camera Calibration</p> <p>OpenCV and rewire camera</p> <p>Camara calibrationhttp://www.jesusllor.es/?p=37</p> <p>Luis Baumela, Juan Bekios-Calfa</p> <p>Camera Calibration</p> <p>OpenCV and rewire camera</p> <p>Camara calibration</p> <p>Code:import glob import cv PATH_ORIGIN = "../../images/chessboard/test/*.jpg" list_files = glob.glob(PATH_ORIGIN) # Create a structure for a gray image rgb_image = cv.LoadImage(list_files[0], cv.CV_LOAD_IMAGE_COLOR) gray_image = cv.CreateImage(cv.GetSize(rgb_image), cv.IPL_DEPTH_8U, 1) # Window to show images cv.NamedWindow("Show image", 1) cv.NamedWindow("Show corners", 1)</p> <p>Luis Baumela, Juan Bekios-Calfa</p> <p>Camera Calibration</p> <p>OpenCV and rewire camera</p> <p>Camara calibrationCode: # Board size chessboard_dim = (7,7) #width, height # Get the image data n_boards = len(list_files) # Number of boards print "Number of boards", n_boards board_w = chessboard_dim[0] board_h = chessboard_dim[1] board_n = board_w * board_h # Datos por tablero</p> <p>Luis Baumela, Juan Bekios-Calfa</p> <p>Camera Calibration</p> <p>OpenCV and rewire camera</p> <p>Camara calibration</p> <p>Code:# Save the image information and objects in the world image_points = cv.CreateMat(n_boards*board_n, 2, cv.CV_32FC1) object_points = cv.CreateMat(n_boards*board_n, 3, cv.CV_32FC1) points_counts = cv.CreateMat(n_boards, 1, cv.CV_32SC1) intrinsic_matrix = cv.CreateMat(3, 3, cv.CV_32FC1) distortion_coeffs = cv.CreateMat(4, 1, cv.CV_32FC1)</p> <p>Luis Baumela, Juan Bekios-Calfa</p> <p>Camera Calibration</p> <p>OpenCV and rewire camera</p> <p>Camara calibrationCode:successes = 0 total_corners = 0 # Read images of a directory for file_image in list_files: print "Image file: ", file_image # Load image rgb_image = cv.LoadImage(file_image, cv.CV_LOAD_IMAGE_COLOR) cv.ShowImage("Mostrar imagen", rgb_image) # Corners detected (It works best if the image is in color) found_all, corners = cv.FindChessboardCorners(rgb_image, chessboard_dim, cv.CV_CALIB_CB_ADAPTIVE_THRESH|cv.CV_CALIB_CB_NORMALIZE_IMAGE) # Improving detection of corners cv.CvtColor(rgb_image, gray_image, cv.CV_RGB2GRAY) corners = cv.FindCornerSubPix(gray_image, corners, (5,5), (-1,-1), (cv.CV_TERMCRIT_EPS+cv.CV_TERMCRIT_ITER, 30, 0.1))</p> <p>Luis Baumela, Juan Bekios-Calfa</p> <p>Camera Calibration</p> <p>OpenCV and rewire camera</p> <p>Camara calibrationCode:# Draw corners cv.DrawChessboardCorners(rgb_image, chessboard_dim, corners, found_all) cv.ShowImage("Mostrar esquinas", rgb_image) # If we got a good board, add it to our data counter_count = len(corners) print "Counter count: ", counter_count if (counter_count == board_n): step = successes * board_n print "step: ", step i = step j = 0 while j &lt; board_n: # Agregar los datos a las matrices image_points[i, 0] = corners[j][0] image_points[i, 1] = corners[j][1] object_points[i, 0] = j//board_w object_points[i, 1] = j%board_w object_points[i, 2] = 0.0 j += 1 i += 1 points_counts[successes, 0] = board_n total_corners += board_n successes += 1 else: break cv.WaitKey()</p> <p>Luis Baumela, Juan Bekios-Calfa</p> <p>Camera Calibration</p> <p>OpenCV and rewire camera</p> <p>Camara calibrationCode:# CALIBRATE THE CAMERA! cv.SetZero(intrinsic_matrix) cv.SetZero(distortion_coeffs) intrinsic_matrix[0, 0] = 1.0 intrinsic_matrix[1, 1] = 1.0 print "n_board", n_boards print "total_corners", total_corners rvects = cv.CreateMat(n_boards, 3, cv.CV_32FC1) tvects = cv.CreateMat(n_boards, 3, cv.CV_32FC1) cv.CalibrateCamera2(object_points, image_points, points_counts, cv.GetSize(gray_image), intrinsic_matrix, distortion_coeffs, rvects, tvects, 0)</p> <p>Luis Baumela, Juan Bekios-Calfa</p> <p>Camera Calibration</p> <p>OpenCV and rewire camera</p> <p>Camara calibrationCode: print print "Intrinsic matrix" for i in xrange(3): print [intrinsic_matrix[i,j] for j in xrange(3)] print "Vector rotation" for i in xrange(n_boards): print rvects[i,0], rvects[i,1], rvects[i,2]</p> <p>Luis Baumela, Juan Bekios-Calfa</p> <p>Camera Calibration</p>

Recommended

View more >