- use simpler id matching
- multiple boards at the same time working
This commit is contained in:
@@ -1,7 +1,6 @@
|
|||||||
import abc
|
import abc
|
||||||
import cv2 as cv
|
import cv2 as cv
|
||||||
import numpy as np
|
import numpy as np
|
||||||
from reedsolo import RSCodec, ReedSolomonError
|
|
||||||
|
|
||||||
RESULTS_FOLDER = "results"
|
RESULTS_FOLDER = "results"
|
||||||
|
|
||||||
@@ -14,7 +13,6 @@ class BoardDetector(abc.ABC):
|
|||||||
t_vecs = None
|
t_vecs = None
|
||||||
obj_points_list = []
|
obj_points_list = []
|
||||||
img_points_list = []
|
img_points_list = []
|
||||||
rs = None
|
|
||||||
board_id = None
|
board_id = None
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return self.name
|
return self.name
|
||||||
@@ -22,22 +20,22 @@ class BoardDetector(abc.ABC):
|
|||||||
def __init__(self, name: str, board_id: str, n_syms: int):
|
def __init__(self, name: str, board_id: str, n_syms: int):
|
||||||
self.name = name
|
self.name = name
|
||||||
self.board_id = board_id
|
self.board_id = board_id
|
||||||
msg_size = len(board_id)
|
offset = int(board_id)*n_syms
|
||||||
n_rs = n_syms - msg_size
|
self.ids = np.array([x + offset for x in range(n_syms)])
|
||||||
self.rs = RSCodec(n_rs, c_exp=7)
|
print(f"{self.name}: markers: {self.ids}")
|
||||||
|
|
||||||
msg = bytes(f"{board_id}", 'utf-8')
|
def match_ids(self, ids: np.array):
|
||||||
byte_string = self.rs.encode(msg)
|
offset = int(self.board_id) * len(self.ids)
|
||||||
self.ids = np.array([x for x in byte_string])
|
if ids is None:
|
||||||
print(f"{name}: markers: {self.ids}")
|
return False
|
||||||
|
|
||||||
def decode(self, ids: np.array):
|
for n in range(len(ids)):
|
||||||
print(ids)
|
if (ids[n] - offset) < 0:
|
||||||
try:
|
return False
|
||||||
msg = self.rs.decode(ids)
|
if (ids[n] - offset) > len(self.ids):
|
||||||
return msg[0:len(self.board_id)]
|
return False
|
||||||
except ReedSolomonError:
|
|
||||||
return None
|
return True
|
||||||
|
|
||||||
@abc.abstractmethod
|
@abc.abstractmethod
|
||||||
def get_board_name(self) -> str:
|
def get_board_name(self) -> str:
|
||||||
|
|||||||
@@ -36,6 +36,9 @@ class BoardDetectorAruco(BoardDetector):
|
|||||||
obj_points = None
|
obj_points = None
|
||||||
img_points = None
|
img_points = None
|
||||||
corners, ids, _ = self.detector.detectMarkers(image)
|
corners, ids, _ = self.detector.detectMarkers(image)
|
||||||
|
if not self.match_ids(ids):
|
||||||
|
return False, None, None
|
||||||
|
|
||||||
if corners is not None:
|
if corners is not None:
|
||||||
if len(ids) >= len(self.board.getIds()):
|
if len(ids) >= len(self.board.getIds()):
|
||||||
_obj_points, _img_points = self.board.matchImagePoints(corners, ids)
|
_obj_points, _img_points = self.board.matchImagePoints(corners, ids)
|
||||||
@@ -65,6 +68,9 @@ class BoardDetectorAruco(BoardDetector):
|
|||||||
if not self.is_calibrated():
|
if not self.is_calibrated():
|
||||||
return pose, None, None
|
return pose, None, None
|
||||||
|
|
||||||
|
if not self.match_ids(ids):
|
||||||
|
return pose, None, None
|
||||||
|
|
||||||
# Draw marker axis
|
# Draw marker axis
|
||||||
if draw_marker_axis:
|
if draw_marker_axis:
|
||||||
_r_vecs, _t_vecs, _ = cv.aruco.estimatePoseSingleMarkers(corners, markerLength=0.1, cameraMatrix=self.mtx, distCoeffs=self.dist)
|
_r_vecs, _t_vecs, _ = cv.aruco.estimatePoseSingleMarkers(corners, markerLength=0.1, cameraMatrix=self.mtx, distCoeffs=self.dist)
|
||||||
|
|||||||
@@ -154,12 +154,6 @@ class Detector(abc.ABC):
|
|||||||
|
|
||||||
cv.destroyAllWindows()
|
cv.destroyAllWindows()
|
||||||
|
|
||||||
def gen_marker_list():
|
|
||||||
msg = bytes(f"{n:0{msg_size}d}", 'utf-8')
|
|
||||||
byte_string = rs.encode(msg)
|
|
||||||
marker_list = [x for x in byte_string]
|
|
||||||
print(marker_list)
|
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
# construct the argument parser and parse the arguments
|
# construct the argument parser and parse the arguments
|
||||||
|
|||||||
Reference in New Issue
Block a user