From a94b93182d1691ff3ef9ebbbc61d0f1cca1ff493 Mon Sep 17 00:00:00 2001 From: Miguelmelon Date: Tue, 21 May 2024 09:14:10 +0200 Subject: [PATCH] First ROS package working --- people_tracking_v2/CMakeLists.txt | 2 +- .../scripts/{yolo2.py => yolo.py} | 2 +- .../launchers/yolo_launcher.launch | 2 +- .../src/people_tracking/yolo.py | 49 ------------------- 4 files changed, 3 insertions(+), 52 deletions(-) rename people_tracking_v2/scripts/{yolo2.py => yolo.py} (95%) delete mode 100644 people_tracking_v2/src/people_tracking/yolo.py diff --git a/people_tracking_v2/CMakeLists.txt b/people_tracking_v2/CMakeLists.txt index 5648818..b945c76 100644 --- a/people_tracking_v2/CMakeLists.txt +++ b/people_tracking_v2/CMakeLists.txt @@ -11,7 +11,7 @@ catkin_package() install(PROGRAMS scripts/face_recognition_node.py scripts/pose_estimation_node.py - scripts/yolo2.py + scripts/yolo.py DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION} ) diff --git a/people_tracking_v2/scripts/yolo2.py b/people_tracking_v2/scripts/yolo.py similarity index 95% rename from people_tracking_v2/scripts/yolo2.py rename to people_tracking_v2/scripts/yolo.py index 11e4ed6..0a92c38 100755 --- a/people_tracking_v2/scripts/yolo2.py +++ b/people_tracking_v2/scripts/yolo.py @@ -12,7 +12,7 @@ def __init__(self): self.bridge = CvBridge() self.model = YOLO("yolov8l.pt") - self.image_sub = rospy.Subscriber("/cv_camera/image_raw", Image, self.image_callback) + self.image_sub = rospy.Subscriber("/Webcam/image_raw", Image, self.image_callback) self.detection_pub = rospy.Publisher("/yolo_detections", String, queue_size=10) def image_callback(self, data): diff --git a/people_tracking_v2/src/people_tracking/launchers/yolo_launcher.launch b/people_tracking_v2/src/people_tracking/launchers/yolo_launcher.launch index 35e85ef..6efcd9e 100644 --- a/people_tracking_v2/src/people_tracking/launchers/yolo_launcher.launch +++ b/people_tracking_v2/src/people_tracking/launchers/yolo_launcher.launch @@ -20,7 +20,7 @@ diff --git a/people_tracking_v2/src/people_tracking/yolo.py b/people_tracking_v2/src/people_tracking/yolo.py deleted file mode 100644 index 901bd2c..0000000 --- a/people_tracking_v2/src/people_tracking/yolo.py +++ /dev/null @@ -1,49 +0,0 @@ -#!/usr/bin/env python - -import cv2 -from ultralytics import YOLO - -def main(): - cap = cv2.VideoCapture(0) - - model = YOLO("yolov8l.pt") - - while True: - ret, frame = cap.read() - if not ret: - break - - # Run the YOLOv8 model on the frame - result = model(frame)[0] - - # Print the result to understand its structure - print(result) - - # Extract the detections from the result - boxes = result.boxes.xyxy.cpu().numpy() - scores = result.boxes.conf.cpu().numpy() - labels = result.boxes.cls.cpu().numpy() - - # Draw bounding boxes and labels on the frame - for box, score, label in zip(boxes, scores, labels): - x1, y1, x2, y2 = map(int, box) - color = (0, 255, 0) # Set your desired color for bounding boxes - thickness = 3 - frame = cv2.rectangle(frame, (x1, y1), (x2, y2), color, thickness) - frame = cv2.putText( - frame, f'{int(label)}: {score:.2f}', (x1, y1 - 10), - cv2.FONT_HERSHEY_SIMPLEX, 0.5, color, 1 - ) - - # Display the frame - cv2.imshow("YOLOv8", frame) - - # Exit the loop if 'Esc' key is pressed - if cv2.waitKey(30) == 27: - break - - cap.release() - cv2.destroyAllWindows() - -if __name__ == "__main__": - main()