- fixed filename
- refacored
This commit is contained in:
@@ -69,7 +69,6 @@ class ArTagPose(abc.ABC):
|
||||
print("Cannot open camera")
|
||||
exit()
|
||||
|
||||
self.calibrate_load()
|
||||
cal_img_size = None
|
||||
last_rotation = [0, 0, 0]
|
||||
while True:
|
||||
|
||||
@@ -14,14 +14,15 @@ def factory(dict_type: int, board_size: cv.typing.Size, square_length: float = 5
|
||||
detector = cv.aruco.CharucoDetector(board, params)
|
||||
image = board.generateImage((im_w, im_h), None, margin_length, 1)
|
||||
keyname = [key for key, val in ARUCO_DICT.items() if val == dict_type][0]
|
||||
cv.imwrite(f"results/aruco_board_w{board_size[0]}_h{board_size[1]}_{keyname}.png", image)
|
||||
cv.imwrite(f"results/charuco_board_w{board_size[0]}_h{board_size[1]}_{keyname}.png", image)
|
||||
|
||||
return detector, board
|
||||
|
||||
class ArTagPoseCharucoBoard(ArTagPose):
|
||||
def __init__(self, dict_type: int, board_size: tuple[int, int]):
|
||||
ArTagPose.__init__(self)
|
||||
self.board_size = board_size
|
||||
self.calib_filename = f"results/cam_calib_aruco_board_w{board_size[0]}_h{board_size[1]}.npz"
|
||||
self.calib_filename = f"results/cam_calib_charuco_board_w{board_size[0]}_h{board_size[1]}.npz"
|
||||
self.detector, self.board = factory(dict_type, board_size)
|
||||
|
||||
def calibrate_save(self):
|
||||
@@ -58,8 +59,6 @@ class ArTagPoseCharucoBoard(ArTagPose):
|
||||
pose = False
|
||||
r_vec = None
|
||||
t_vec = None
|
||||
if not self.is_calibrated():
|
||||
return pose, None, None
|
||||
|
||||
gray = cv.cvtColor(image, cv.COLOR_BGR2GRAY)
|
||||
charuco_corners, charuco_ids, marker_corners, marker_ids = self.detector.detectBoard(gray)
|
||||
@@ -75,7 +74,7 @@ class ArTagPoseCharucoBoard(ArTagPose):
|
||||
cv.aruco.drawDetectedCornersCharuco(image, charuco_corners, charuco_ids)
|
||||
|
||||
# Draw marker axis
|
||||
if draw_marker_axis:
|
||||
if draw_marker_axis and self.is_calibrated():
|
||||
_r_vecs, _t_vecs, _ = cv.aruco.estimatePoseSingleMarkers(marker_corners, markerLength=0.1,
|
||||
cameraMatrix=self.mtx, distCoeffs=self.dist)
|
||||
for i in range(len(_r_vecs)):
|
||||
@@ -85,7 +84,7 @@ class ArTagPoseCharucoBoard(ArTagPose):
|
||||
obj_points, img_points = self.board.matchImagePoints(charuco_corners, charuco_ids)
|
||||
offset = int(self.board.getMarkerLength() * self.board.getSquareLength())
|
||||
obj_points -= [offset, offset, 0]
|
||||
if self.mtx is not None and self.dist is not None:
|
||||
if self.is_calibrated():
|
||||
pose, r_vec, t_vec = cv.solvePnP(obj_points, img_points, self.mtx, self.dist, useExtrinsicGuess=False,
|
||||
rvec=r_vecs, tvec=t_vecs, flags=cv.SOLVEPNP_ITERATIVE)
|
||||
if pose:
|
||||
|
||||
Reference in New Issue
Block a user