- aruco board: use solvePnP
- refactored
This commit is contained in:
+15
-12
@@ -58,22 +58,25 @@ def process_video(detector: cv.aruco.CharucoDetector, board):
|
||||
if k == ord('q'):
|
||||
break
|
||||
|
||||
def process(detector: cv.aruco.CharucoDetector, board, img, mtx, dist): # Load previously saved data
|
||||
def process(detector: cv.aruco.CharucoDetector, board: cv.aruco.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)
|
||||
if diamond_ids is not None and len(diamond_ids) > 0:
|
||||
obj_points, img_points = board.matchImagePoints(diamond_corners, diamond_ids)
|
||||
pose, rvec, tvec = cv.solvePnP(obj_points, img_points, mtx, dist, None, None)
|
||||
if pose:
|
||||
# Draw Axis
|
||||
cv.drawFrameAxes(img, mtx, dist, rvec, tvec, 10)
|
||||
cv.aruco.drawDetectedCornersCharuco(img, diamond_corners, diamond_ids)
|
||||
|
||||
# Draw a square around the markers
|
||||
cv.aruco.drawDetectedMarkers(img, marker_corners)
|
||||
|
||||
if len(diamond_ids) >= len(board.getIds()):
|
||||
# Draw a square around the markers
|
||||
cv.aruco.drawDetectedDiamonds(img, diamond_corners, diamond_ids)
|
||||
if False and diamond_ids is not None and len(diamond_ids) > 0:
|
||||
obj_points, img_points = board.matchImagePoints(diamond_corners, diamond_ids)
|
||||
pose, rvec, tvec = cv.solvePnP(obj_points, img_points, mtx, dist, None, None)
|
||||
if pose:
|
||||
# Draw Axis
|
||||
cv.drawFrameAxes(img, mtx, dist, rvec, tvec, 10)
|
||||
|
||||
cv.imshow('img', img)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user