Skip to content

Commit 108fed5

Browse files
mergify[bot]tfoldi
andauthored
fix: cv2.aruco.interpolateCornersCharuco is deprecated (backport #979) (#1090)
There has been API Changes in the newer releases of opencv2 (from 4.8.0). The PR addresses this by supporting both the old and new APIs. Co-authored-by: Földi Tamás <tfoldi@xsi.hu>
1 parent b381f6a commit 108fed5

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

camera_calibration/src/camera_calibration/calibrator.py

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,13 @@ def __init__(self, pattern="chessboard", n_cols = 0, n_rows = 0, dim = 0.0, mark
8888
"7x7_100" : cv2.aruco.DICT_7X7_100,
8989
"7x7_250" : cv2.aruco.DICT_7X7_250,
9090
"7x7_1000" : cv2.aruco.DICT_7X7_1000}[aruco_dict])
91-
self.charuco_board = cv2.aruco.CharucoBoard_create(self.n_cols, self.n_rows, self.dim, self.marker_size,
92-
self.aruco_dict)
91+
if cv2.__version__ >= '4.8.0':
92+
self.charuco_board = cv2.aruco.CharucoBoard((self.n_cols, self.n_rows), self.dim, self.marker_size,
93+
self.aruco_dict)
94+
else:
95+
self.charuco_board = cv2.aruco.CharucoBoard_create(self.n_cols, self.n_rows, self.dim, self.marker_size,
96+
self.aruco_dict)
97+
9398

9499
# Make all private!!!!!
95100
def lmin(seq1, seq2):
@@ -268,10 +273,17 @@ def _get_charuco_corners(img, board, refine):
268273
else:
269274
mono = img
270275

271-
marker_corners, marker_ids, _ = cv2.aruco.detectMarkers(img, board.aruco_dict)
272-
if len(marker_corners) == 0:
273-
return (False, None, None)
274-
_, square_corners, ids = cv2.aruco.interpolateCornersCharuco(marker_corners, marker_ids, img, board.charuco_board)
276+
277+
if cv2.__version__ >= '4.8.0':
278+
charucodetector = cv2.aruco.CharucoDetector(board.charuco_board)
279+
square_corners, ids, marker_corners, marker_ids = charucodetector.detectBoard(mono)
280+
else:
281+
marker_corners, marker_ids, _ = cv2.aruco.detectMarkers(img, board.aruco_dict)
282+
283+
if len(marker_corners) == 0:
284+
return (False, None, None)
285+
_, square_corners, ids = cv2.aruco.interpolateCornersCharuco(marker_corners, marker_ids, img, board.charuco_board, minMarkers=1)
286+
275287
return ((square_corners is not None) and (len(square_corners) > 5), square_corners, ids)
276288

277289
def _get_circles(img, board, pattern):

camera_calibration/src/camera_calibration/camera_calibrator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ def on_model_change(self, model_select_val):
317317
self.c.set_cammodel( CAMERA_MODEL.PINHOLE if model_select_val < 0.5 else CAMERA_MODEL.FISHEYE)
318318

319319
def on_scale(self, scalevalue):
320-
if self.c.calibrated:
320+
if self.c and self.c.calibrated:
321321
self.c.set_alpha(scalevalue / 100.0)
322322

323323
def button(self, dst, label, enable):

0 commit comments

Comments
 (0)