added device id as CLI argument
This commit is contained in:
@@ -18,7 +18,8 @@ class BoardPose(abc.ABC):
|
||||
obj_points_list = []
|
||||
img_points_list = []
|
||||
|
||||
def __init__(self):
|
||||
def __init__(self, device_id: int):
|
||||
self.device_id = device_id
|
||||
Path.mkdir(Path(RESULTS_FOLDER), exist_ok=True)
|
||||
|
||||
@staticmethod
|
||||
@@ -76,7 +77,7 @@ class BoardPose(abc.ABC):
|
||||
def process(self):
|
||||
|
||||
# Open camera
|
||||
cap = cv.VideoCapture(0)
|
||||
cap = cv.VideoCapture(self.device_id)
|
||||
BoardPose.cap_init(cap)
|
||||
|
||||
if not cap.isOpened():
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import cv2 as cv
|
||||
import numpy as np
|
||||
import argparse
|
||||
from ar_tag_pose.board_pose import BoardPose
|
||||
from ar_tag_pose.aruco_types import ARUCO_DICT
|
||||
|
||||
@@ -14,8 +15,8 @@ def factory(dict_type: int, board_size: cv.typing.Size, marker_length: float=100
|
||||
return detector, board, name
|
||||
|
||||
class BoardPoseAruco(BoardPose):
|
||||
def __init__(self, dict_type: int, board_size: tuple[int, int]):
|
||||
BoardPose.__init__(self)
|
||||
def __init__(self, device_id: int, dict_type: int, board_size: tuple[int, int]):
|
||||
BoardPose.__init__(self, device_id)
|
||||
self.board_size = board_size
|
||||
self.detector, self.board, self.name = factory(dict_type, board_size)
|
||||
|
||||
@@ -84,7 +85,14 @@ class BoardPoseAruco(BoardPose):
|
||||
return pose, r_vec, t_vec
|
||||
|
||||
def main():
|
||||
pose = BoardPoseAruco(10, (5, 5))
|
||||
# construct the argument parser and parse the arguments
|
||||
ap = argparse.ArgumentParser()
|
||||
ap.add_argument("-i", "--device_id", type=int,
|
||||
default=0,
|
||||
help="Camera device index ")
|
||||
args = vars(ap.parse_args())
|
||||
|
||||
pose = BoardPoseAruco(args["device_id"], 10, (5, 5))
|
||||
pose.board_image_generate(margin_length=10)
|
||||
pose.calibrate_load()
|
||||
pose.process()
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import cv2 as cv
|
||||
import numpy as np
|
||||
import argparse
|
||||
from ar_tag_pose.board_pose import BoardPose
|
||||
from ar_tag_pose.aruco_types import ARUCO_DICT
|
||||
|
||||
@@ -14,8 +15,8 @@ def factory(dict_type: int, board_size: cv.typing.Size, square_length: float = 5
|
||||
return detector, board, name
|
||||
|
||||
class BoardPoseCharuco(BoardPose):
|
||||
def __init__(self, dict_type: int, board_size: tuple[int, int]):
|
||||
BoardPose.__init__(self)
|
||||
def __init__(self, device_id: int, dict_type: int, board_size: tuple[int, int]):
|
||||
BoardPose.__init__(self, device_id)
|
||||
self.board_size = board_size
|
||||
self.detector, self.board, self.name = factory(dict_type, board_size)
|
||||
|
||||
@@ -82,7 +83,14 @@ class BoardPoseCharuco(BoardPose):
|
||||
return pose, r_vec, t_vec
|
||||
|
||||
def main():
|
||||
pose = BoardPoseCharuco(10, (6, 7))
|
||||
# construct the argument parser and parse the arguments
|
||||
ap = argparse.ArgumentParser()
|
||||
ap.add_argument("-i", "--device_id", type=int,
|
||||
default=0,
|
||||
help="Camera device index ")
|
||||
args = vars(ap.parse_args())
|
||||
|
||||
pose = BoardPoseCharuco(args["device_id"], 10, (6, 7))
|
||||
pose.board_image_generate()
|
||||
pose.calibrate_load()
|
||||
pose.process()
|
||||
|
||||
Reference in New Issue
Block a user