- fixed buggy filtering of detector rotation
- added SmoothRotation class - rotation object is member of each detector
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
import abc
|
import abc
|
||||||
import numpy as np
|
import numpy as np
|
||||||
from calibration import Calibration
|
from calibration import Calibration
|
||||||
|
from smooth_rotation import SmoothRotation
|
||||||
|
|
||||||
RESULTS_FOLDER = "results"
|
RESULTS_FOLDER = "results"
|
||||||
|
|
||||||
@@ -11,6 +12,7 @@ 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
|
||||||
|
self.rotation = SmoothRotation()
|
||||||
|
|
||||||
# Create IDs
|
# Create IDs
|
||||||
offset = int(board_id)*n_syms
|
offset = int(board_id)*n_syms
|
||||||
|
|||||||
@@ -88,6 +88,7 @@ class BoardDetectorAruco(BoardDetector):
|
|||||||
if pose:
|
if pose:
|
||||||
# Draw Axis
|
# Draw Axis
|
||||||
cv.drawFrameAxes(image, calibration.mtx, calibration.dist, r_vec, t_vec, self.board.getMarkerLength()*1.5)
|
cv.drawFrameAxes(image, calibration.mtx, calibration.dist, r_vec, t_vec, self.board.getMarkerLength()*1.5)
|
||||||
|
self.rotation.set_vec(r_vec, t_vec)
|
||||||
|
|
||||||
return pose, r_vec, t_vec
|
return pose, r_vec, t_vec
|
||||||
|
|
||||||
|
|||||||
@@ -88,6 +88,7 @@ class BoardDetectorCharuco(BoardDetector):
|
|||||||
if pose:
|
if pose:
|
||||||
# Draw
|
# Draw
|
||||||
cv.drawFrameAxes(image, calibration.mtx, calibration.dist, r_vec, t_vec, 10)
|
cv.drawFrameAxes(image, calibration.mtx, calibration.dist, r_vec, t_vec, 10)
|
||||||
|
self.rotation.set_vec(r_vec, t_vec)
|
||||||
|
|
||||||
return pose, r_vec, t_vec
|
return pose, r_vec, t_vec
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import argparse
|
|||||||
import mimetypes
|
import mimetypes
|
||||||
import json
|
import json
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from ar_tag_pose.utils import to_tf, to_euler, draw_text
|
from ar_tag_pose.utils import draw_text
|
||||||
from calibration import Calibration
|
from calibration import Calibration
|
||||||
from detector_board import BoardDetector
|
from detector_board import BoardDetector
|
||||||
from detector_board_aruco import BoardDetectorAruco
|
from detector_board_aruco import BoardDetectorAruco
|
||||||
@@ -171,9 +171,7 @@ class Detector(abc.ABC):
|
|||||||
frame_num = 0
|
frame_num = 0
|
||||||
out = None
|
out = None
|
||||||
pose_center = True
|
pose_center = True
|
||||||
rot = np.array([0,0,0])
|
alpha_rot = 0.3
|
||||||
# ToDo: fixed filter with multiple detectors
|
|
||||||
alpha_rot = 1.0
|
|
||||||
scale_target_width = 800
|
scale_target_width = 800
|
||||||
show_undistorted_image = False
|
show_undistorted_image = False
|
||||||
read_key = ReadKey()
|
read_key = ReadKey()
|
||||||
@@ -229,14 +227,12 @@ class Detector(abc.ABC):
|
|||||||
success, r_vec, t_vec = det.process(img, self.calibration, True, False, False, pose_center)
|
success, r_vec, t_vec = det.process(img, self.calibration, True, False, False, pose_center)
|
||||||
if success:
|
if success:
|
||||||
if len(self.rotation_order) == 3:
|
if len(self.rotation_order) == 3:
|
||||||
_rot = to_euler(to_tf(r_vec, t_vec), rotation_order=self.rotation_order)
|
rot = det.rotation.get(self.rotation_order, alpha_rot)
|
||||||
rot = (1-alpha_rot)*rot + alpha_rot*_rot
|
|
||||||
self.print_angle(img, f"{str(det)}-{self.rotation_order}", rot, (30, int(y_pos/k_scale)), self.rotation_order, 1./k_scale)
|
self.print_angle(img, f"{str(det)}-{self.rotation_order}", rot, (30, int(y_pos/k_scale)), self.rotation_order, 1./k_scale)
|
||||||
y_pos += 30
|
y_pos += 30
|
||||||
else:
|
else:
|
||||||
for rotation_order in ['XYZ', 'XZY', 'YXZ', 'YZX', 'ZXY', 'ZYX']:
|
for rotation_order in ['XYZ', 'XZY', 'YXZ', 'YZX', 'ZXY', 'ZYX']:
|
||||||
_rot = to_euler(to_tf(r_vec, t_vec), rotation_order=rotation_order)
|
rot = det.rotation.get(rotation_order, alpha_rot)
|
||||||
rot = (1 - alpha_rot) * rot + alpha_rot * _rot
|
|
||||||
self.print_angle(img,f"{str(det)}-{rotation_order}", rot, (30, int(y_pos/k_scale)), rotation_order, 1./k_scale)
|
self.print_angle(img,f"{str(det)}-{rotation_order}", rot, (30, int(y_pos/k_scale)), rotation_order, 1./k_scale)
|
||||||
y_pos += 30
|
y_pos += 30
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,18 @@
|
|||||||
|
import numpy as np
|
||||||
|
from ar_tag_pose.utils import to_tf, to_euler
|
||||||
|
|
||||||
|
|
||||||
|
class SmoothRotation:
|
||||||
|
def __init__(self):
|
||||||
|
self.rot = np.array([0,0,0])
|
||||||
|
self.r_vec = np.array([0,0,0])
|
||||||
|
self.t_vec = np.array([0,0,0])
|
||||||
|
|
||||||
|
def set_vec(self, r_vec: np.ndarray, t_vec: np.ndarray):
|
||||||
|
self.r_vec = r_vec
|
||||||
|
self.t_vec = t_vec
|
||||||
|
|
||||||
|
def get(self, rotation_order: str, alpha: float=1.0) -> np.ndarray:
|
||||||
|
rot = to_euler(to_tf(self.r_vec, self.t_vec), rotation_order=rotation_order)
|
||||||
|
self.rot = (1 - alpha) * self.rot + alpha * rot
|
||||||
|
return self.rot
|
||||||
Reference in New Issue
Block a user