본문 바로가기

카테고리 없음

Chessboard Pdf Open Cv Sift

  1. Opencv Chessboard Calibration

BasicsToday’s cheap pinhole cameras introduces a lot of distortion to images. Two major distortions are radial distortion and tangential distortion.Due to radial distortion, straight lines will appear curved. Its effect is more as we move away from the center of image. For example, one image is shown below, where two edges of a chess board are marked with red lines.

But you can see that border is not a straight line and doesn’t match with the red line. All the expected straight lines are bulged out. Visit for more details. Extrinsic parameters corresponds to rotation and translation vectors which translates a coordinates of a 3D point to a coordinate system.For stereo applications, these distortions need to be corrected first. To find all these parameters, what we have to do is to provide some sample images of a well defined pattern (eg, chess board). We find some specific points in it ( square corners in chess board). We know its coordinates in real world space and we know its coordinates in image.

Opencv Chessboard Calibration

With these data, some mathematical problem is solved in background to get the distortion coefficients. That is the summary of the whole story. For better results, we need atleast 10 test patterns. CodeAs mentioned above, we need atleast 10 test patterns for camera calibration. OpenCV comes with some images of chess board (see samples/cpp/left01.jpg - left14.jpg), so we will utilize it.

For sake of understanding, consider just one image of a chess board. Important input datas needed for camera calibration is a set of 3D real world points and its corresponding 2D image points.

2D image points are OK which we can easily find from the image. (These image points are locations where two black squares touch each other in chess boards)What about the 3D points from real world space? Those images are taken from a static camera and chess boards are placed at different locations and orientations. So we need to know values. But for simplicity, we can say chess board was kept stationary at XY plane, (so Z=0 always) and camera was moved accordingly. This consideration helps us to find only X,Y values.

Now for X,Y values, we can simply pass the points as (0,0), (1,0), (2,0). Which denotes the location of points. In this case, the results we get will be in the scale of size of chess board square. But if we know the square size, (say 30 mm), and we can pass the values as (0,0),(30,0),(60,0)., we get the results in mm. (In this case, we don’t know square size since we didn’t take those images, so we pass in terms of square size).3D points are called object points and 2D image points are called image points.

See alsoThis function may not be able to find the required pattern in all the images. So one good option is to write the code such that, it starts the camera and check each frame for required pattern. Once pattern is obtained, find the corners and store it in a list. Also provides some interval before reading next frame so that we can adjust our chess board in different direction. Continue this process until required number of good patterns are obtained.

Even in the example provided here, we are not sure out of 14 images given, how many are good. So we read all the images and take the good ones. Import numpy as np import cv2 import glob # termination criteria criteria = ( cv2.

Opencv

TERMCRITERIAEPS + cv2. TERMCRITERIAMAXITER, 30, 0.001 ) # prepare object points, like (0,0,0), (1,0,0), (2,0,0).,(6,5,0) objp = np. Zeros (( 6. 7, 3 ), np. Float32 ) objp :,: 2 = np. Mgrid 0: 7, 0: 6.

Reshape ( - 1, 2 ) # Arrays to store object points and image points from all the images. Objpoints = # 3d point in real world space imgpoints = # 2d points in image plane. Images = glob. Glob ( '.jpg' ) for fname in images: img = cv2. Imread ( fname ) gray = cv2. CvtColor ( img, cv2.

Chessboard

COLORBGR2GRAY ) # Find the chess board corners ret, corners = cv2. FindChessboardCorners ( gray, ( 7, 6 ), None ) # If found, add object points, image points (after refining them) if ret True: objpoints. Append ( objp ) corners2 = cv2. CornerSubPix ( gray, corners,( 11, 11 ),( - 1, - 1 ), criteria ) imgpoints. Append ( corners2 ) # Draw and display the corners img = cv2. DrawChessboardCorners ( img, ( 7, 6 ), corners2, ret ) cv2.

Imshow ( 'img', img ) cv2. WaitKey ( 500 ) cv2. DestroyAllWindows One image with pattern drawn on it is shown below. UndistortionWe have got what we were trying. Now we can take an image and undistort it. OpenCV comes with two methods, we will see both. But before that, we can refine the camera matrix based on a free scaling parameter using cv2.getOptimalNewCameraMatrix.

Opencv

If the scaling parameter alpha=0, it returns undistorted image with minimum unwanted pixels. So it may even remove some pixels at image corners. If alpha=1, all pixels are retained with some extra black images.

It also returns an image ROI which can be used to crop the result.So we take a new image ( left12.jpg in this case. That is the first image in this chapter).

Re-projection ErrorRe-projection error gives a good estimation of just how exact is the found parameters. This should be as close to zero as possible. Given the intrinsic, distortion, rotation and translation matrices, we first transform the object point to image point using cv2.projectPoints. Then we calculate the absolute norm between what we got with our transformation and the corner finding algorithm. To find the average error we calculate the arithmetical mean of the errors calculate for all the calibration images.