From 4431f3a574bc47775d94c80f0bdd7e5914240b10 Mon Sep 17 00:00:00 2001 From: Jens Ahrensfeld Date: Mon, 24 Nov 2025 21:53:21 +0100 Subject: [PATCH] draw detectedMarkers --- cam_pose_aruco_board.py | 5 +++-- cam_pose_charuco_board.py | 6 +++++- cam_pose_charuco_diamond.py | 4 ++++ 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/cam_pose_aruco_board.py b/cam_pose_aruco_board.py index dea5074..f8eee5c 100644 --- a/cam_pose_aruco_board.py +++ b/cam_pose_aruco_board.py @@ -64,6 +64,9 @@ def process(detector: cv.aruco.ArucoDetector, board, img, mtx, dist): # Load pre detector.refineDetectedMarkers(img, board, corners, ids, rejected, mtx, dist) + # Draw a square around the markers + cv.aruco.drawDetectedMarkers(img, corners) + if len(corners) > 0: # Estimate pose of each marker and return the values rvec and tvec---(different from those of camera coefficients) pose, rvec, tvec = cv.aruco.estimatePoseBoard(corners, ids, board, mtx, dist, None, None) @@ -72,8 +75,6 @@ def process(detector: cv.aruco.ArucoDetector, board, img, mtx, dist): # Load pre # Draw Axis cv.drawFrameAxes(img, mtx, dist, rvec, tvec, 0.02) - # Draw a square around the markers - cv.aruco.drawDetectedMarkers(img, corners) cv.imshow('img', img) diff --git a/cam_pose_charuco_board.py b/cam_pose_charuco_board.py index f56953e..3784e3e 100644 --- a/cam_pose_charuco_board.py +++ b/cam_pose_charuco_board.py @@ -31,7 +31,7 @@ def main(): # load the ArUCo dictionary, grab the ArUCo parameters, and detect # the markers print("[INFO] detecting '{}' tags...".format(args["type"])) - detector, board = factory(ARUCO_DICT[args["type"]], (6,7)) + detector, board = factory(ARUCO_DICT[args["type"]], (3,3)) # load the input image from disk and resize it print("[INFO] start processing...") @@ -61,9 +61,13 @@ def process(detector: cv.aruco.CharucoDetector, board, img, mtx, dist): # Load p gray = cv.cvtColor(img, cv.COLOR_BGR2GRAY) charuco_corners, charuco_ids, marker_corners, marker_ids = detector.detectBoard(gray) if charuco_corners is not None: + # Draw a square around the markers cv.aruco.drawDetectedCornersCharuco(img, charuco_corners, charuco_ids) + # Draw a square around the markers + cv.aruco.drawDetectedMarkers(img, marker_corners) + if len(charuco_ids) > 5: obj_points, img_points = board.matchImagePoints(charuco_corners, charuco_ids) pose, rvec, tvec = cv.solvePnP(obj_points, img_points, mtx, dist, None, None) diff --git a/cam_pose_charuco_diamond.py b/cam_pose_charuco_diamond.py index 0276f46..81032fe 100644 --- a/cam_pose_charuco_diamond.py +++ b/cam_pose_charuco_diamond.py @@ -61,6 +61,10 @@ def process_video(detector: cv.aruco.CharucoDetector, board): def process(detector: cv.aruco.CharucoDetector, board, img, mtx, dist): # Load previously saved data gray = cv.cvtColor(img, cv.COLOR_BGR2GRAY) diamond_corners, diamond_ids, marker_corners, marker_ids = detector.detectDiamonds(gray) + + # Draw a square around the markers + cv.aruco.drawDetectedMarkers(img, marker_corners) + if diamond_corners is not None: # Draw a square around the markers cv.aruco.drawDetectedDiamonds(img, diamond_corners, diamond_ids)