refactored
This commit is contained in:
+12
-1
@@ -25,6 +25,12 @@ class ArTagPose(abc.ABC):
|
||||
cap.set(cv.CAP_PROP_EXPOSURE, 30)
|
||||
cap.set(cv.CAP_PROP_AUTO_EXPOSURE, 1)
|
||||
|
||||
def board_image_generate(self, margin_length: int=0):
|
||||
image_size = self.get_board_image_size(margin_length)
|
||||
image = self.board.generateImage(image_size, None, margin_length, 1)
|
||||
name = self.get_name()
|
||||
cv.imwrite(f"results/{name}.png", image)
|
||||
|
||||
def is_calibrated(self):
|
||||
return self.mtx is not None and self.dist is not None
|
||||
|
||||
@@ -112,8 +118,13 @@ class ArTagPose(abc.ABC):
|
||||
cv.imshow('img', img)
|
||||
cv.destroyAllWindows()
|
||||
|
||||
|
||||
@abc.abstractmethod
|
||||
def get_name(self):
|
||||
def get_name(self) -> str:
|
||||
pass
|
||||
|
||||
@abc.abstractmethod
|
||||
def get_board_image_size(self, margin_length: int) -> tuple[int,int]:
|
||||
pass
|
||||
|
||||
@abc.abstractmethod
|
||||
|
||||
@@ -3,17 +3,13 @@ import numpy as np
|
||||
from ar_tag_pose import ArTagPose
|
||||
from aruco_types import ARUCO_DICT
|
||||
|
||||
def factory(dict_type: int, board_size: cv.typing.Size, marker_length: float=100.0, marker_sep=10, margins=10):
|
||||
def factory(dict_type: int, board_size: cv.typing.Size, marker_length: float=100.0, marker_sep=10):
|
||||
aruco_dict = cv.aruco.getPredefinedDictionary(dict_type)
|
||||
params = cv.aruco.DetectorParameters()
|
||||
board = cv.aruco.GridBoard(size=board_size, markerLength=marker_length, markerSeparation=marker_sep, dictionary=aruco_dict)
|
||||
detector = cv.aruco.ArucoDetector(aruco_dict, params)
|
||||
board = cv.aruco.GridBoard(board_size, markerLength=marker_length, markerSeparation=marker_sep, dictionary=aruco_dict)
|
||||
im_w = int(board_size[0] * (marker_length + marker_sep) - marker_sep + 2 * margins)
|
||||
im_h = int(board_size[1] * (marker_length + marker_sep) - marker_sep + 2 * margins)
|
||||
image = board.generateImage((im_w, im_h), None, margins, 1)
|
||||
keyname = [key for key, val in ARUCO_DICT.items() if val == dict_type][0]
|
||||
name = f"aruco_board_w{board_size[0]}_h{board_size[1]}_{keyname}"
|
||||
cv.imwrite(f"results/{name}.png", image)
|
||||
|
||||
return detector, board, name
|
||||
|
||||
@@ -25,6 +21,14 @@ class ArTagPoseArucoBoard(ArTagPose):
|
||||
def get_name(self):
|
||||
return self.name
|
||||
|
||||
def get_board_image_size(self, margin_length=10):
|
||||
grid_size = self.board.getGridSize()
|
||||
marker_length = self.board.getMarkerLength()
|
||||
marker_sep = self.board.getMarkerSeparation()
|
||||
w = int(grid_size[0] * (marker_length + marker_sep) - marker_sep + 2 * margin_length)
|
||||
h = int(grid_size[1] * (marker_length + marker_sep) - marker_sep + 2 * margin_length)
|
||||
return w, h
|
||||
|
||||
def calibrate_points(self, image: cv.typing.MatLike):
|
||||
success = False
|
||||
img_size = (0,0)
|
||||
@@ -80,6 +84,7 @@ class ArTagPoseArucoBoard(ArTagPose):
|
||||
|
||||
def main():
|
||||
pose = ArTagPoseArucoBoard(10, (5,5))
|
||||
pose.board_image_generate()
|
||||
pose.calibrate_load()
|
||||
pose.process()
|
||||
|
||||
|
||||
@@ -3,29 +3,27 @@ import numpy as np
|
||||
from ar_tag_pose import ArTagPose
|
||||
from aruco_types import ARUCO_DICT
|
||||
|
||||
def factory(dict_type: int, board_size: cv.typing.Size, square_length: float = 5.0, marker_length: float = 3.0, margin_length=0):
|
||||
im_w = 800
|
||||
im_h = 600
|
||||
def factory(dict_type: int, board_size: cv.typing.Size, square_length: float = 5.0, marker_length: float = 3.0):
|
||||
aruco_dict = cv.aruco.getPredefinedDictionary(dict_type)
|
||||
board = cv.aruco.CharucoBoard(board_size, square_length, marker_length, aruco_dict)
|
||||
params = cv.aruco.CharucoParameters()
|
||||
board = cv.aruco.CharucoBoard(size=board_size, squareLength=square_length, markerLength=marker_length, dictionary=aruco_dict)
|
||||
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]
|
||||
name = f"aruco_board_w{board_size[0]}_h{board_size[1]}_{keyname}"
|
||||
cv.imwrite(f"results/{name}.png", image)
|
||||
|
||||
return detector, board, name
|
||||
|
||||
class ArTagPoseCharucoBoard(ArTagPose):
|
||||
def __init__(self, dict_type: int, board_size: tuple[int, int]):
|
||||
ArTagPose.__init__(self)
|
||||
self.board_size = board_size
|
||||
self.detector, self.board, self.name = factory(dict_type, board_size)
|
||||
|
||||
def get_name(self):
|
||||
return self.name
|
||||
|
||||
def get_board_image_size(self, margin_length=0):
|
||||
return 800, 600
|
||||
|
||||
def calibrate_points(self, image: cv.typing.MatLike):
|
||||
success = False
|
||||
img_size = (0,0)
|
||||
@@ -84,6 +82,7 @@ class ArTagPoseCharucoBoard(ArTagPose):
|
||||
|
||||
def main():
|
||||
pose = ArTagPoseCharucoBoard(10, (6,7))
|
||||
pose.board_image_generate()
|
||||
pose.calibrate_load()
|
||||
pose.process()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user