Skip missed ChArUco detections in the Python calibration sample (#31174)

When a calibration batch contains an image without a ChArUco board, detectBoard can return None for the corners. Taking its length raises TypeError and stops processing the remaining images.

Skip corner matching and drawing for a missed detection. If no image provides calibration points, report that before calling calibrateCamera.
This commit is contained in:
Aryan Yadav
2026-12-02 11:46:40 +05:30
committed by GitHub
parent 085c194218
commit e4f0d420a9

View File

@@ -130,7 +130,7 @@ def main():
frame_obj_points = pattern_points
elif pattern_type == 'charucoboard':
corners, charucoIds, _, _ = charuco_detector.detectBoard(img)
if (len(corners) > 0):
if corners is not None and len(corners) >= 4:
frame_obj_points, frame_img_points = board.matchImagePoints(corners, charucoIds)
found = True
else:
@@ -143,7 +143,7 @@ def main():
vis = cv.cvtColor(img, cv.COLOR_GRAY2BGR)
if pattern_type == 'chessboard':
cv.drawChessboardCorners(vis, pattern_size, corners, found)
elif pattern_type == 'charucoboard':
elif pattern_type == 'charucoboard' and charucoIds is not None:
cv.aruco.drawDetectedCornersCharuco(vis, corners, charucoIds=charucoIds)
_path, name, _ext = splitfn(fn)
outfile = os.path.join(debug_dir, name + '_board.png')
@@ -170,6 +170,10 @@ def main():
img_points.append(corners)
obj_points.append(pattern_points)
if not img_points:
print("No calibration patterns found")
return
# calculate camera distortion
rms, camera_matrix, dist_coefs, _rvecs, _tvecs = cv.calibrateCamera(obj_points, img_points, (w, h), None, None)