Opencv Camera calibration: do i need to use flags?

Viewed 328

I'm doing camera calibration for a robotic arm which will be used for grasping. Notice that I'm not using any flag while calibrating each camera individually and also during stereo calibration. Is this the right way to proceed and get accurate results? Thanks The code is as follows:

import numpy as np
import cv2
import glob

# termination criteria
criteria = (cv2.TERM_CRITERIA_EPS + cv2.TERM_CRITERIA_MAX_ITER, 30, 0.001)

# prepare object points, like (0,0,0), (1,0,0), (2,0,0) ....,(6,5,0)
objp = np.zeros((12*12,3), np.float32)
objp[:,:2] = np.mgrid[0:12,0:12].T.reshape(-1,2)*26 #multiply by length of squares 


# Arrays to store object points and image points from all the images.
objpointsL = [] # 3d point in real world space
imgpointsL = [] # 2d points in image plane.
objpointsR = []
imgpointsR = []

images = glob.glob('Imageleft*tif')

for fname in images:
    img = cv2.imread(fname)
    grayL = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)

    # Find the chess board corners
    ret, cornersL = cv2.findChessboardCorners(grayL, (12,12),None)
    # If found, add object points, image points (after refining them)
    if ret == True:
        objpointsL.append(objp)

        cv2.cornerSubPix(grayL,cornersL,(11,11),(-1,-1),criteria)
        imgpointsL.append(cornersL)
        img = cv2.drawChessboardCorners(img,(12,12),cornersL,ret)
        cv2.imshow('imgL',img)
        cv2.waitKey(500)

images = glob.glob('Imageright*.tif')

for fname in images:
    img = cv2.imread(fname)
    grayR = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)

    # Find the chess board corners
    ret, cornersR = cv2.findChessboardCorners(grayR, (12,12),None)

    # If found, add object points, image points (after refining them)
    if ret == True:
        objpointsR.append(objp)

        cv2.cornerSubPix(grayR,cornersR,(11,11),(-1,-1),criteria)
        imgpointsR.append(cornersR)
        img = cv2.drawChessboardCorners(img, (12, 12), cornersR, ret)
        cv2.imshow('imgR', img)
        cv2.waitKey(500)


ret1, mtx1, dist1, rvecs1, tvecs1= cv2.calibrateCamera(objpointsL, imgpointsL, grayL.shape[::-1],None,None)
ret2, mtx2, dist2, rvecs2, tvecs2= cv2.calibrateCamera(objpointsR, imgpointsR, grayR.shape[::-1],None,None)
retval,cameraMatrix1, distCoeffs1, cameraMatrix2, distCoeffs2, R, T, E, F = cv2.stereoCalibrate(objpointsL, imgpointsL, imgpointsR,mtx1,dist1,mtx2,dist2,None)
0 Answers
Related