Skip to content

Commit

Permalink
fix: cv2.aruco.interpolateCornersCharuco is deprecated (backport #979) (
Browse files Browse the repository at this point in the history
#980)

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.

updated Syntax
```
charucodetector = cv2.aruco.CharucoDetector(board)
charuco_corners, charuco_ids, marker_corners, marker_ids = charucodetector.detectBoard(image)
```
before 4.8.0
```
marker_corners, marker_ids, rejectedImgPoints = cv2.aruco.detectMarkers( image, dictionary)
retval, charuco_corners, charuco_ids = cv2.aruco.interpolateCornersCharuco( marker_corners, marker_ids, image, board)
```

See the changed examples in the main opencv2 repo:


https://github.com/opencv/opencv/blob/f9a59f2592993d3dcc080e495f4f5e02dd8ec7ef/samples/python/calibrate.py#L110<hr>This
is an automatic backport of pull request #979 done by
[Mergify](https://mergify.com).

Co-authored-by: Földi Tamás <tfoldi@xsi.hu>
  • Loading branch information
mergify[bot] and tfoldi authored May 24, 2024
1 parent 8b85e5c commit 9ea34bd
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
24 changes: 18 additions & 6 deletions camera_calibration/src/camera_calibration/calibrator.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,13 @@ def __init__(self, pattern="chessboard", n_cols = 0, n_rows = 0, dim = 0.0, mark
"7x7_100" : cv2.aruco.DICT_7X7_100,
"7x7_250" : cv2.aruco.DICT_7X7_250,
"7x7_1000" : cv2.aruco.DICT_7X7_1000}[aruco_dict])
self.charuco_board = cv2.aruco.CharucoBoard_create(self.n_cols, self.n_rows, self.dim, self.marker_size,
self.aruco_dict)
if cv2.__version__ >= '4.8.0':
self.charuco_board = cv2.aruco.CharucoBoard((self.n_cols, self.n_rows), self.dim, self.marker_size,
self.aruco_dict)
else:
self.charuco_board = cv2.aruco.CharucoBoard_create(self.n_cols, self.n_rows, self.dim, self.marker_size,
self.aruco_dict)


# Make all private!!!!!
def lmin(seq1, seq2):
Expand Down Expand Up @@ -268,10 +273,17 @@ def _get_charuco_corners(img, board, refine):
else:
mono = img

marker_corners, marker_ids, _ = cv2.aruco.detectMarkers(img, board.aruco_dict)
if len(marker_corners) == 0:
return (False, None, None)
_, square_corners, ids = cv2.aruco.interpolateCornersCharuco(marker_corners, marker_ids, img, board.charuco_board)

if cv2.__version__ >= '4.8.0':
charucodetector = cv2.aruco.CharucoDetector(board.charuco_board)
square_corners, ids, marker_corners, marker_ids = charucodetector.detectBoard(mono)
else:
marker_corners, marker_ids, _ = cv2.aruco.detectMarkers(img, board.aruco_dict)

if len(marker_corners) == 0:
return (False, None, None)
_, square_corners, ids = cv2.aruco.interpolateCornersCharuco(marker_corners, marker_ids, img, board.charuco_board, minMarkers=1)

return ((square_corners is not None) and (len(square_corners) > 5), square_corners, ids)

def _get_circles(img, board, pattern):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ def on_model_change(self, model_select_val):
self.c.set_cammodel( CAMERA_MODEL.PINHOLE if model_select_val < 0.5 else CAMERA_MODEL.FISHEYE)

def on_scale(self, scalevalue):
if self.c.calibrated:
if self.c and self.c.calibrated:
self.c.set_alpha(scalevalue / 100.0)

def button(self, dst, label, enable):
Expand Down

0 comments on commit 9ea34bd

Please sign in to comment.