Skip to content

Commit

Permalink
Numbering simultaneaous detections
Browse files Browse the repository at this point in the history
  • Loading branch information
Miguelmelon committed May 22, 2024
1 parent db4f437 commit 731f75b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
4 changes: 2 additions & 2 deletions people_tracking_v2/scripts/HoC.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ def detection_callback(self, msg):
if self.current_image is None:
return

for detection in msg.detections:
for i, detection in enumerate(msg.detections):
x1, y1, x2, y2 = detection.x1, detection.y1, detection.x2, detection.y2
roi = self.current_image[int(y1):int(y2), int(x1):int(x2)]
hoc = self.compute_hoc(roi)
rospy.loginfo(f'HoC for detection: {hoc}')
rospy.loginfo(f'HoC for detection #{i + 1}: {hoc}')

def compute_hoc(self, roi):
hsv = cv2.cvtColor(roi, cv2.COLOR_BGR2HSV)
Expand Down
5 changes: 3 additions & 2 deletions people_tracking_v2/scripts/yolo.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def image_callback(self, data):
human_detections = [(box, score, label) for box, score, label in zip(boxes, scores, labels) if int(label) == 0]
rospy.loginfo(f"Human Detections: {len(human_detections)}") # Log the number of human detections

for box, score, label in human_detections:
for i, (box, score, label) in enumerate(human_detections):
detection = Detection()
detection.x1 = float(box[0])
detection.y1 = float(box[1])
Expand All @@ -52,9 +52,10 @@ def image_callback(self, data):
x1, y1, x2, y2 = map(int, box)
color = (0, 255, 0) # Set your desired color for bounding boxes
thickness = 3
label_text = f'#{i+1} {int(label)}: {score:.2f}'
cv2.rectangle(cv_image, (x1, y1), (x2, y2), color, thickness)
cv2.putText(
cv_image, f'{int(label)}: {score:.2f}', (x1, y1 - 10),
cv_image, label_text, (x1, y1 - 10),
cv2.FONT_HERSHEY_SIMPLEX, 0.5, color, 1
)

Expand Down

0 comments on commit 731f75b

Please sign in to comment.