1515from message_filters import Subscriber , ApproximateTimeSynchronizer
1616from cv_bridge import CvBridge
1717from .visualization_utils import *
18+ from .parking_utils import *
1819import time
1920import math
2021import ros_numpy
@@ -322,8 +323,8 @@ def initialize(self):
322323 self .vis_3d_cones_bboxes = False
323324
324325 # Subscribers
325- self .rgb_sub = Subscriber ('/camera_fl/arena_camera_node /image_raw' , Image )
326- self .lidar_sub = Subscriber ('/ouster /points' , PointCloud2 )
326+ self .rgb_sub = Subscriber ('/camera/fl /image_raw' , Image )
327+ self .lidar_sub = Subscriber ('/lidar/top /points' , PointCloud2 )
327328 self .sync = ApproximateTimeSynchronizer ([self .rgb_sub , self .lidar_sub ],
328329 queue_size = 10 , slop = 0.1 )
329330 self .sync .registerCallback (self .synchronized_callback )
@@ -334,6 +335,7 @@ def initialize(self):
334335 self .pub_cones_image_detection = rospy .Publisher ("cones_detection/annotated_image" , Image , queue_size = 1 )
335336 self .pub_cones_bboxes_markers = rospy .Publisher ("cones_detection/bboxes/markers" , MarkerArray , queue_size = 10 )
336337 self .pub_cones_centers_pc2 = rospy .Publisher ("cones_detection/centers/point_cloud" , PointCloud2 , queue_size = 10 )
338+ self .pub_parking_spot_marker = rospy .Publisher ("parking_spot_detection/marker" , MarkerArray , queue_size = 10 )
337339
338340 # Detection model
339341 self .model_path = os .getcwd () + '/GEMstack/knowledge/detection/cone.pt'
@@ -357,16 +359,7 @@ def initialize(self):
357359 self .R_c2l = self .T_c2l [:3 , :3 ]
358360 self .camera_origin_in_lidar = self .T_c2l [:3 , 3 ]
359361
360- def viz_object_states (self , cv_image , boxes ):
361- cone_3d_centers = list ()
362- cone_3d_dims = list ()
363-
364- for track_id , agent in self .current_agents .items ():
365- if agent .pose .x != None and agent .pose .y != None and agent .pose .z != None :
366- cone_3d_centers .append ((agent .pose .x , agent .pose .y , agent .pose .z ))
367- if agent .dimensions != None and agent .dimensions [0 ] != None and agent .dimensions [1 ] != None and agent .dimensions [2 ] != None :
368- cone_3d_dims .append (agent .dimensions )
369-
362+ def viz_object_states (self , cone_3d_centers , cone_3d_dims , cv_image , boxes ):
370363 # Transform top lidar pointclouds to vehicle frame for visualization
371364 if self .vis_lidar_pc :
372365 latest_lidar_vehicle = transform_lidar_points (self .latest_lidar_unfiltered , self .T_l2v )
@@ -383,8 +376,11 @@ def viz_object_states(self, cv_image, boxes):
383376 self .pub_cones_image_detection .publish (ros_img )
384377
385378 # Create vehicle marker
386- ros_vehicle_marker = create_bbox_marker ([[0.0 , 0.0 , 0.0 ]], [[0.8 , 0.5 , 0.3 ]], (0.0 , 1 .0 , 0 .0 , 1 ), "vehicle" )
379+ ros_vehicle_marker = create_bbox_marker ([[0.0 , 0.0 , 0.0 ]], [[0.8 , 0.5 , 0.3 ]], (0.0 , 0 .0 , 1 .0 , 1 ), "vehicle" )
387380 self .pub_vehicle_marker .publish (ros_vehicle_marker )
381+ # Delete previous parking spot markers
382+ ros_delete_parking_spot_markers = delete_markers ("parking_spot" , 1 )
383+ self .pub_parking_spot_marker .publish (ros_delete_parking_spot_markers )
388384 # Draw 3D cone centers and dimensions
389385 if len (cone_3d_centers ) > 0 and len (cone_3d_dims ) > 0 :
390386 if self .vis_3d_cones_centers :
@@ -397,11 +393,25 @@ def viz_object_states(self, cv_image, boxes):
397393
398394 if self .vis_3d_cones_bboxes :
399395 # Delete previous markers
400- ros_delete_bboxes_markers = delete_bbox_marker ( )
396+ ros_delete_bboxes_markers = delete_markers ( "markers" , 15 )
401397 self .pub_cones_bboxes_markers .publish (ros_delete_bboxes_markers )
402398 # Create bbox markers from cone dimensions
403399 ros_cones_bboxes_markers = create_bbox_marker (cone_3d_centers , cone_3d_dims , (1.0 , 0.0 , 0.0 , 0.4 ), "vehicle" )
404400 self .pub_cones_bboxes_markers .publish (ros_cones_bboxes_markers )
401+
402+ def detect_parking_spot (self , cone_3d_centers ):
403+ cone_ground_centers = np .array (cone_3d_centers )
404+ cone_ground_centers_2D = cone_ground_centers [:, :2 ]
405+ # print(f"-----cone_ground_centers_2D: {cone_ground_centers_2D}")
406+ candidates = findAllCandidateParkingLot (cone_ground_centers_2D )
407+ # print(f"-----candidates: {candidates}")
408+ if len (candidates ) > 0 :
409+ closest_spot = candidates [0 ]
410+ # print(f"-----closest_spot: {closest_spot}")
411+ # Create parking spot marker
412+ ros_parking_spot_marker = create_parking_spot_marker (closest_spot , ref_frame = "vehicle" )
413+ self .pub_parking_spot_marker .publish (ros_parking_spot_marker )
414+ return
405415
406416
407417 def synchronized_callback (self , image_msg , lidar_msg ):
@@ -573,9 +583,23 @@ def update(self, vehicle: VehicleState) -> Dict[str, AgentState]:
573583 f"Velocity: (vx: { agent .velocity [0 ]:.3f} , vy: { agent .velocity [1 ]:.3f} , vz: { agent .velocity [2 ]:.3f} )\n "
574584 )
575585
586+ # Now retrieve all cone agents from current agent items
587+ cone_3d_centers = list ()
588+ cone_3d_dims = list ()
589+
590+ for track_id , agent in self .current_agents .items ():
591+ if agent .pose .x != None and agent .pose .y != None and agent .pose .z != None :
592+ cone_3d_centers .append ((agent .pose .x , agent .pose .y , agent .pose .z ))
593+ if agent .dimensions != None and agent .dimensions [0 ] != None and agent .dimensions [1 ] != None and agent .dimensions [2 ] != None :
594+ cone_3d_dims .append (agent .dimensions )
595+
596+ # Detect parking spot if 4 or more cones are detected
597+ if len (cone_3d_centers ) >= 4 :
598+ self .detect_parking_spot (cone_3d_centers )
599+
576600 # Add Visualization
577601 cv_image = self .latest_image .copy ()
578- self .viz_object_states (cv_image , bboxes )
602+ self .viz_object_states (cone_3d_centers , cone_3d_dims , cv_image , bboxes )
579603
580604 return agents
581605
0 commit comments