Reputation: 44
I need to calibrate a camera with openCV and python.
My script can't find a match point. To simplify things, I'm using the Charuco pattern (with margin of white pixels) as my input image. Even so, no points are found. Here's the basic self-sufficient script.
import cv2
import numpy as np
aruco_dict = cv2.aruco.getPredefinedDictionary(cv2.aruco.DICT_4X4_50)
board = cv2.aruco.CharucoBoard((5, 7),0.01, 0.008, aruco_dict)
board.setLegacyPattern(True)
b = board.generateImage((200,200),marginSize = 20)
#image = cv2.imread('charuco_board.png')
#gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
gray = b
# first detection
aruco_detector = cv2.aruco.ArucoDetector(aruco_dict)
marker_corners, marker_ids, rejected_candidates = aruco_detector.detectMarkers(image)
print(marker_corners)
# refine
if marker_ids is not None:
charuco_params = cv2.aruco.CharucoParameters()
charuco_detector = cv2.aruco.CharucoDetector(board, charuco_params)
charuco_corners, charuco_ids, _ = charuco_detector.detectBoard(gray, marker_corners, marker_ids)
image_copy = image.copy()
image_markers = cv2.aruco.drawDetectedMarkers(image_copy, marker_corners, marker_ids)
image_charuco = cv2.aruco.drawDetectedCornersCharuco(image_markers, charuco_corners, charuco_ids)
cv2.imshow('Detected ChArUco Corners', image_charuco)
cv2.waitKey(0)
cv2.destroyAllWindows()
else:
print("No corners detected.")
Edit : it seams that aruco 4X4_50 is broken. Working script :
import cv2
import numpy as np
aruco_dict = cv2.aruco.getPredefinedDictionary(cv2.aruco.DICT_6X6_250)
board = cv2.aruco.CharucoBoard((5, 7),0.01, 0.008, aruco_dict)
board.setLegacyPattern(True)
b = board.generateImage((2000,2000),marginSize = 20)
cv2.imwrite('charuco_board.png',b)
gray = b
# first detection
aruco_detector = cv2.aruco.ArucoDetector(aruco_dict)
marker_corners, marker_ids, rejected_candidates = aruco_detector.detectMarkers(b)
print(marker_corners)
# refine
if marker_ids is not None:
charuco_params = cv2.aruco.CharucoParameters()
charuco_detector = cv2.aruco.CharucoDetector(board, charuco_params)
#charuco_corners, charuco_ids, markerCorners, markerIds = charuco_detector.detectBoard(gray, marker_corners, marker_ids)
charuco_corners, charuco_ids, markerCorners, markerIds = charuco_detector.detectBoard(gray)
image_copy = b.copy()
image_markers = cv2.aruco.drawDetectedMarkers(image_copy, marker_corners, marker_ids)
image_charuco = cv2.aruco.drawDetectedCornersCharuco(image_markers, charuco_corners, charuco_ids)
cv2.imshow('Detected ChArUco Corners', image_charuco)
cv2.waitKey(0)
cv2.destroyAllWindows()
else:
print("No corners detected.")
Upvotes: 0
Views: 32