Skip to content

Commit 5e87e70

Browse files
committed
Allow variable checkerboard sizes
1 parent ca6b137 commit 5e87e70

1 file changed

Lines changed: 16 additions & 4 deletions

File tree

GEMstack/offboard/calibration/intrinsic_calibration.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ def main():
1616
help='Name of the camera used to identify the correct images')
1717
parser.add_argument('-o', '--out_path', type=str, required=False,
1818
help='Path to output ymal file for camera intrinsics')
19+
parser.add_argument('-w', '--board_width', type=int, required=False,
20+
help='Width in number of internal corners of the checkerboard')
21+
parser.add_argument('-h', '--board_height', type=int, required=False,
22+
help='Height in number of internal corners of the checkerboard')
1923

2024
args = parser.parse_args()
2125

@@ -26,14 +30,22 @@ def main():
2630
camera = args.camera_name
2731
image_files = glob.glob(os.path.join(folder, camera + '*.png'))
2832

33+
# Determine checkerboard shape
34+
b_width = 8
35+
if args.board_width:
36+
b_width = args.board_width
37+
b_height = 6
38+
if args.board_height:
39+
b_height = args.board_height
40+
2941
# The following code is derived from https://docs.opencv.org/4.x/dc/dbb/tutorial_py_calibration.html
3042

3143
# termination criteria
3244
criteria = (cv.TERM_CRITERIA_EPS + cv.TERM_CRITERIA_MAX_ITER, 30, 0.001)
3345

3446
# prepare object points, like (0,0,0), (1,0,0), (2,0,0) ....,(7,5,0)
35-
objp = np.zeros((6*8,3), np.float32)
36-
objp[:,:2] = np.mgrid[0:8,0:6].T.reshape(-1,2)
47+
objp = np.zeros((b_width * b_height,3), np.float32)
48+
objp[:,:2] = np.mgrid[0:b_width,0:b_height].T.reshape(-1,2)
3749

3850
# Arrays to store object points and image points from all the images.
3951
objpoints = [] # 3d point in real world space
@@ -44,7 +56,7 @@ def main():
4456
gray = cv.cvtColor(img, cv.COLOR_BGR2GRAY)
4557

4658
# Find the chess board corners
47-
ret, corners = cv.findChessboardCorners(gray, (8,6), None)
59+
ret, corners = cv.findChessboardCorners(gray, (b_width, b_height), None)
4860

4961
# If found, add object points, image points (after refining them)
5062
if ret == True:
@@ -54,7 +66,7 @@ def main():
5466
imgpoints.append(corners2)
5567

5668
# Draw and display the corners
57-
cv.drawChessboardCorners(img, (8,6), corners2, ret)
69+
cv.drawChessboardCorners(img, (b_width,b_height), corners2, ret)
5870
cv.imshow('img', img)
5971
cv.waitKey(500)
6072

0 commit comments

Comments
 (0)