Ask Your Question
0

camera calibration in python

asked 2013-04-09 04:27:05 -0600

vividou gravatar image

Hello,

I am wondering if there is an example in python using the cv2 version for camera calibration using a chessboard pattern?

if not, here is a part of my code:

fn = ('home/image.jpg')
pattern_size = (7, 9)

img = cv2.imread(fn, cv2.CV_LOAD_IMAGE_GRAYSCALE)
h, w = img.shape
found, corners = cv2.findChessboardCorners(img, pattern_size)
cv2.drawChessboardCorners(img, pattern_size, corners, found)

Then:

square_size = 1.0
pattern_points = np.zeros( (np.prod(pattern_size), 3), np.float32 )
pattern_points[:,:2] = np.indices(pattern_size).T.reshape(-1, 2)
pattern_points *= square_size

img_points.append(corners.reshape(-1, 2))
obj_points.append(pattern_points)

rms, camera_matrix, dist_coefs, rvecs, tvecs = cv2.calibrateCamera(obj_points, img_points, (w, h))

I am not sure about the use of cv2.calibrateCamera as I get an error with cameraMatrix which seems required but I don't know how to set it.

If someone could give me some inputs, It would be great.

Best Rergards

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
4

answered 2013-04-09 06:48:46 -0600

In the samples of opencv (samples/python2/), there is a calibrate.py which is doing exactly what you want.

edit flag offensive delete link more

Question Tools

Stats

Asked: 2013-04-09 04:27:05 -0600

Seen: 2,533 times

Last updated: Apr 09 '13