1414from std_msgs .msg import String
1515
1616from cv import depthai_camera_connect
17+ from cv .config import Torpedo
1718from cv .image_tools import ImageTools
1819from cv .utils import DetectionVisualizer , calculate_relative_pose
1920
@@ -308,10 +309,17 @@ def detect(self) -> None:
308309
309310 confidence = detection .confidence
310311
311- # Calculate relative pose
312+ # Calculate relative pose, and pull scalings from config dependent on model
313+ scale_x , scale_y , scale_z = None , None , None
314+ match label :
315+ case 'torpedo_banner' :
316+ scale_x = Torpedo .TORPEDO_BANNER_X_SCALE
317+ scale_y = Torpedo .TORPEDO_BANNER_Y_SCALE
318+
312319 det_coords_robot_mm = calculate_relative_pose (bbox , tuple (model ['input_size' ]),
313- tuple (model ['sizes' ][label ]),
314- self .focal_length , self .sensor_size , 2 )
320+ tuple (model ['sizes' ][label ]),
321+ self .focal_length , self .sensor_size , 2 ,
322+ scale_x = scale_x , scale_y = scale_y , scale_z = scale_z )
315323
316324 # Find yaw angle offset
317325 left_end_compute = self .compute_angle_from_x_offset (detection .xmin * self .camera_pixel_width )
@@ -341,7 +349,7 @@ def detect(self) -> None:
341349 det_coords_robot_mm [2 ]) # Maintain original z
342350
343351 self .publish_prediction (
344- bbox , det_coords_robot_mm , yaw_offset , label , confidence ,
352+ bbox , det_coords_robot_mm , - yaw_offset , label , confidence ,
345353 (self .camera_pixel_height , self .camera_pixel_width ), self .using_sonar )
346354
347355 def publish_prediction (self , bbox : tuple , det_coords : tuple , yaw : float , label : str , confidence : float ,
@@ -367,21 +375,16 @@ def publish_prediction(self, bbox: tuple, det_coords: tuple, yaw: float, label:
367375 object_msg .label = label
368376 object_msg .score = confidence
369377
370- if label == 'torpedo_banner' :
371- object_msg .coords .x = 1.2 * det_coords [0 ]
372- object_msg .coords .y = 0.5 * det_coords [1 ]
373- object_msg .coords .z = det_coords [2 ]
374- else :
375- object_msg .coords .x = det_coords [0 ]
376- object_msg .coords .y = det_coords [1 ]
377- object_msg .coords .z = det_coords [2 ]
378+ object_msg .coords .x = det_coords [0 ]
379+ object_msg .coords .y = det_coords [1 ]
380+ object_msg .coords .z = det_coords [2 ]
378381
379382 object_msg .xmin = bbox [0 ]
380383 object_msg .ymin = bbox [1 ]
381384 object_msg .xmax = bbox [2 ]
382385 object_msg .ymax = bbox [3 ]
383386
384- object_msg .yaw = - yaw
387+ object_msg .yaw = yaw
385388
386389 object_msg .height = shape [0 ]
387390 object_msg .width = shape [1 ]
0 commit comments