Skip to content

Commit e1ab76a

Browse files
committed
Further cleaned up code and wrote some comments to help out Akul
1 parent 6b8ee50 commit e1ab76a

3 files changed

Lines changed: 29 additions & 104 deletions

File tree

GEMstack/onboard/perception/AgentTracker.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,23 @@ def assign_ids(self, agents: list) -> Dict[str,AgentState]:
1414
"""
1515
"""
1616
agents = {}
17-
17+
# Act with the assumption that you are being sent a list of AgentState objects and you need to use the object fields to keep track of them for your task
18+
# Further act on the assumption that we will decide the id's of the pedestrians by assuming that 2 pedestrians are the same pedestrian if a
19+
# previously stored AgentState pose and dimensions overlap with a newly passed in AgentState
20+
21+
# Act on the assumption that the AgentState objects are all in reference to the start frame of the vehicle
22+
23+
# some helper functions in this class, LostAgent.py, and IdTracker.py have been created to try to help you out with your task.
24+
25+
# Assume that the output returned from this function will be a dictionary of AgentState objects with the key corresponding to their id
26+
pass
27+
1828
def __convert_to_start_frame(self):
1929
"""Converts a list of AgentState agents from ouster Lidar frame of
2030
reference (which is in reference to the current frame) to start
2131
frame frame of reference
2232
"""
33+
# you can ignore this function akul
2334
pass
2435

2536
def __agents_overlap(ped1, ped2) -> bool:

GEMstack/onboard/perception/fusion.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,6 @@ def __init__(self):
2828

2929
# Setup visualization variables
3030
self.visualization = True # Set this to true for visualization, later change to get value from sys arg
31-
self.label_text = "Pedestrian "
32-
self.font = cv2.FONT_HERSHEY_SIMPLEX
33-
self.font_scale = 0.5
34-
self.font_color = (255, 255, 255) # White text
35-
self.outline_color = (0, 0, 0) # Black outline
36-
self.line_type = 1
37-
self.text_thickness = 2 # Text thickness
38-
self.outline_thickness = 1 # Thickness of the text outline
3931

4032
# Load calibration data
4133
self.R = load_extrinsics(os.getcwd() + '/GEMstack/onboard/perception/calibration/extrinsics/R.npy')

GEMstack/onboard/perception/pedestrian_detection.py

Lines changed: 17 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -78,24 +78,28 @@ def initialize(self):
7878
def detect_pedestrians(self, front_image_msg: Image, ouster_msg: PointCloud2D):
7979
"""Fuses Image and Lidar information to detect pedestrians
8080
"""
81-
# combined_point_cloud = self.combine_point_clouds # Removed because we only have transformation for a single lidar (ouster) at the moment. Probably should return np.array
81+
# TODO: make fusion_callback return some data. Call the rest of Lukas' functions and Akul's stuff inside of this function.
82+
data = self.fusion.fusion_callback(rgb_image_msg=front_image_msg, lidar_pc2_msg=ouster_msg)
83+
84+
# Original plan for how to do this:
85+
# # combined_point_cloud = self.combine_point_clouds # Removed because we only have transformation for a single lidar (ouster) at the moment. Probably should return np.array
8286

83-
point_cloud = np.array(list(pc2.read_points(ouster_msg, skip_nans=True)), dtype=np.float32)[:, :3]
87+
# point_cloud = np.array(list(pc2.read_points(ouster_msg, skip_nans=True)), dtype=np.float32)[:, :3]
8488

85-
image_pedestrians = self.detect_pedestrians_in_image(image=front_image_msg)
89+
# image_pedestrians = self.detect_pedestrians_in_image(image=front_image_msg)
8690

87-
for id in image_pedestrians:
88-
#### Scrum-20: Calculate and Convert Image Points to Lidar Frame of Reference Task:
89-
(estimated_ped_cloud, flat_center) = self.extract_ped_cloud(point_cloud=point_cloud, image_pedestrian=image_pedestrians[key])
91+
# for id in image_pedestrians:
92+
# #### Scrum-20: Calculate and Convert Image Points to Lidar Frame of Reference Task:
93+
# (estimated_ped_cloud, flat_center) = self.extract_ped_cloud(point_cloud=point_cloud, image_pedestrian=image_pedestrians[key])
9094

91-
#### Scrum-21 & 39:Calculate Pedestrian Center and Dimensions
92-
# Determine a more exact center and dimensions of the pedestrian by ignoring background point cloud points
93-
(pose, dims) = self.calc_ped_center_dims(estimated_ped_cloud, flat_center)
94-
image_pedestrians[id].pose = pose
95-
image_pedestrians[id].dims = dims
95+
# #### Scrum-21 & 39:Calculate Pedestrian Center and Dimensions
96+
# # Determine a more exact center and dimensions of the pedestrian by ignoring background point cloud points
97+
# (pose, dims) = self.calc_ped_center_dims(estimated_ped_cloud, flat_center)
98+
# image_pedestrians[id].pose = pose
99+
# image_pedestrians[id].dims = dims
96100

97-
#### Scrum-35: Associate and Track Pedestrian Id's
98-
self.associate_and_track_peds(image_pedestrians)
101+
# #### Scrum-35: Associate and Track Pedestrian Id's
102+
# self.associate_and_track_peds(image_pedestrians)
99103

100104
# TODO: refactor into pedestrian_detection.py
101105
def update(self, vehicle : VehicleState) -> Dict[str,AgentState]:
@@ -160,88 +164,6 @@ def update_object_states(track_result, flattened_pedestrians_3d_pts: list[np.nda
160164
for ind in len(num_objs)
161165
]
162166

163-
# Use cv2.Mat for GEM Car, Image for RosBag
164-
def detect_pedestrians_in_image(self, image : Union[cv2.Mat, Image]) -> dict:
165-
"""Detects pedestrians using the model provided when new image is passed.
166-
167-
Converts Image.msg to cv2 format and uses the model to detect pedestrian
168-
IF visualization is true, will publish an image with pedestrians detected.
169-
170-
Hardcoded values for now:
171-
Detected only pedestrians -> Class = 0
172-
173-
"""
174-
175-
# Use Image directly for GEM Car, convert to cv2.Mat for rosbag:
176-
if type(image) == Image:
177-
bridge = CvBridge()
178-
image = bridge.imgmsg_to_cv2(image, "bgr8")
179-
track_result = self.detector.track(source=image, classes=self.classes_to_detect, persist=True, conf=self.confidence)
180-
181-
self.last_person_boxes = []
182-
boxes = track_result[0].boxes
183-
image_pedestrians = {} # Stores a dictionary of pedestrian AgentState objects with the YOLO predicted id as the key
184-
185-
# Unpacking box dimentions detected into x,y,w,h
186-
for box in boxes:
187-
188-
xywh = box.xywh[0].tolist()
189-
self.last_person_boxes.append(xywh)
190-
x, y, w, h = xywh
191-
id = box.id.item()
192-
193-
# Stores AgentState in a dict, can be removed if not required
194-
pose = ObjectPose(t=0,x=x,y=y,z=0,yaw=0,pitch=0,roll=0,frame=ObjectFrameEnum.CURRENT)
195-
dims = (w,h,0)
196-
if(id not in pedestrians.keys()):
197-
image_pedestrians[id] = AgentState(pose=pose,dimensions=dims,outline=None,type=AgentEnum.PEDESTRIAN,activity=AgentActivityEnum.MOVING,velocity=(0,0,0),yaw_rate=0)
198-
else:
199-
image_pedestrians[id].pose = pose
200-
image_pedestrians[id].dims = dims
201-
202-
# Used for visualization
203-
if(self.visualization):
204-
self.__visualize_labeled_image(image, box, x, y, w, h)
205-
206-
#uncomment if you want to debug the detector...
207-
# print(self.last_person_boxes)
208-
# print(pedestrians.keys())
209-
#for bb in self.last_person_boxes:
210-
# x,y,w,h = bb
211-
# cv2.rectangle(image, (int(x-w/2), int(y-h/2)), (int(x+w/2), int(y+h/2)), (255, 0, 255), 3)
212-
#cv2.imwrite("pedestrian_detections.png",image)
213-
214-
# Used for visualization
215-
if(self.visualization):
216-
ros_img = bridge.cv2_to_imgmsg(image, 'bgr8')
217-
self.pub_image.publish(ros_img)
218-
219-
return image_pedestrians
220-
221-
def __visualize_labeled_image(self, image: cv2.Mat, box, x: float, y: float, w: float, h: float):
222-
# Draw bounding box
223-
cv2.rectangle(image, (int(x - w / 2), int(y - h / 2)), (int(x + w / 2), int(y + h / 2)), (255, 0, 255), 3)
224-
225-
# Define text label
226-
x = int(x - w / 2)
227-
y = int(y - h / 2)
228-
label = self.label_text + str(id) + " : " + str(round(box.conf.item(), 2))
229-
230-
# Get text size
231-
text_size, baseline = cv2.getTextSize(label, self.font, self.font_scale, self.line_type)
232-
text_w, text_h = text_size
233-
234-
# Position text above the bounding box
235-
text_x = x
236-
text_y = y - 10 if y - 10 > 10 else y + h + text_h
237-
238-
# Draw text outline for better visibility, uncomment for outline
239-
# for dx, dy in [(-1, -1), (-1, 1), (1, -1), (1, 1)]:
240-
# cv2.putText(image, label, (text_x + dx, text_y - baseline + dy), self.font, self.font_scale, self.outline_color, self.outline_thickness)
241-
242-
# Draw main text on top of the outline
243-
cv2.putText(image, label, (text_x, text_y - baseline), self.font, self.font_scale, self.font_color, self.text_thickness)
244-
245167
def extract_ped_cloud(point_cloud: np.array, image_pedestrian: AgentState):
246168
# return (estimated_ped_cloud, flat_center)
247169
pass

0 commit comments

Comments
 (0)