draw detectedMarkers

This commit is contained in:
2025-11-24 21:53:21 +01:00
parent 92f55249b9
commit 4431f3a574
3 changed files with 12 additions and 3 deletions
+3 -2
View File
@@ -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)
+5 -1
View File
@@ -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)
+4
View File
@@ -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)