From 8e9b1b31db2301fafc5f152d1987ffbcf7e02db0 Mon Sep 17 00:00:00 2001 From: Matthijs van der Burgh Date: Tue, 12 Dec 2023 23:09:59 +0100 Subject: [PATCH] (tracking) cleanup --- people_tracking/CMakeLists.txt | 33 +++++------- .../{detect_person.msg => DetectPerson.msg} | 0 people_tracking/package.xml | 25 ++++++--- .../src/{ => people_tracking}/UKFclass.py | 0 .../src/{ => people_tracking}/colour_check.py | 0 .../src/{ => people_tracking}/depth_image.py | 0 .../{ => people_tracking}/face_detection.py | 0 .../src/{ => people_tracking}/listener.py | 6 +-- .../{ => people_tracking}/people_tracker.py | 0 .../{ => people_tracking}/person_detection.py | 0 .../src/{ => people_tracking}/skelly.py | 0 .../src/{ => people_tracking}/yolo.py | 52 +++---------------- 12 files changed, 42 insertions(+), 74 deletions(-) rename people_tracking/msg/{detect_person.msg => DetectPerson.msg} (100%) rename people_tracking/src/{ => people_tracking}/UKFclass.py (100%) mode change 100755 => 100644 rename people_tracking/src/{ => people_tracking}/colour_check.py (100%) rename people_tracking/src/{ => people_tracking}/depth_image.py (100%) rename people_tracking/src/{ => people_tracking}/face_detection.py (100%) rename people_tracking/src/{ => people_tracking}/listener.py (95%) rename people_tracking/src/{ => people_tracking}/people_tracker.py (100%) rename people_tracking/src/{ => people_tracking}/person_detection.py (100%) rename people_tracking/src/{ => people_tracking}/skelly.py (100%) rename people_tracking/src/{ => people_tracking}/yolo.py (51%) diff --git a/people_tracking/CMakeLists.txt b/people_tracking/CMakeLists.txt index 89044b7..1ae736b 100644 --- a/people_tracking/CMakeLists.txt +++ b/people_tracking/CMakeLists.txt @@ -2,26 +2,23 @@ cmake_minimum_required(VERSION 3.0.2) project(people_tracking) find_package(catkin REQUIRED COMPONENTS - rgbd - rgbd_image_buffer - roscpp - sensor_msgs - people_recognition_msgs - - rospy - std_msgs - message_generation + message_generation + people_recognition_msgs + rgbd + rgbd_image_buffer + roscpp + sensor_msgs + visualization_msgs ) -# TODO still needed? catkin_python_setup() add_message_files( - FILES - detect_person.msg - DetectedPerson.msg - ColourCheckedTarget.msg - ColourTarget.msg + FILES + ColourCheckedTarget.msg + ColourTarget.msg + DetectPerson.msg + DetectedPerson.msg ) add_service_files( @@ -31,15 +28,11 @@ add_service_files( generate_messages( DEPENDENCIES - std_msgs sensor_msgs ) - - catkin_package( - CATKIN_DEPENDS - message_runtime + CATKIN_DEPENDS message_runtime sensor_msgs ) include_directories( diff --git a/people_tracking/msg/detect_person.msg b/people_tracking/msg/DetectPerson.msg similarity index 100% rename from people_tracking/msg/detect_person.msg rename to people_tracking/msg/DetectPerson.msg diff --git a/people_tracking/package.xml b/people_tracking/package.xml index 0622e05..8a49096 100644 --- a/people_tracking/package.xml +++ b/people_tracking/package.xml @@ -20,17 +20,28 @@ python3-setuptools - cv_bridge - image_recognition_msgs - image_recognition_util - people_recognition_msgs - rgbd - rgbd_image_buffer - rospy sensor_msgs + people_recognition_msgs + rgbd + rgbd_image_buffer + roscpp + visualization_msgs + message_generation + + cv_bridge + image_recognition_util message_runtime + people_recognition_msgs + rgbd + rgbd_image_buffer + roscpp + rospy + std_msgs + visualization_msgs + + catkin_lint_cmake python3-sphinx python-sphinx-autoapi-pip diff --git a/people_tracking/src/UKFclass.py b/people_tracking/src/people_tracking/UKFclass.py old mode 100755 new mode 100644 similarity index 100% rename from people_tracking/src/UKFclass.py rename to people_tracking/src/people_tracking/UKFclass.py diff --git a/people_tracking/src/colour_check.py b/people_tracking/src/people_tracking/colour_check.py similarity index 100% rename from people_tracking/src/colour_check.py rename to people_tracking/src/people_tracking/colour_check.py diff --git a/people_tracking/src/depth_image.py b/people_tracking/src/people_tracking/depth_image.py similarity index 100% rename from people_tracking/src/depth_image.py rename to people_tracking/src/people_tracking/depth_image.py diff --git a/people_tracking/src/face_detection.py b/people_tracking/src/people_tracking/face_detection.py similarity index 100% rename from people_tracking/src/face_detection.py rename to people_tracking/src/people_tracking/face_detection.py diff --git a/people_tracking/src/listener.py b/people_tracking/src/people_tracking/listener.py similarity index 95% rename from people_tracking/src/listener.py rename to people_tracking/src/people_tracking/listener.py index 94439e3..5f6c1d2 100755 --- a/people_tracking/src/listener.py +++ b/people_tracking/src/people_tracking/listener.py @@ -5,7 +5,7 @@ from ultralytics import YOLO from cv_bridge import CvBridge from sensor_msgs.msg import Image -from people_tracking.msg import detect_person +from people_tracking.msg import DetectPerson laptop = True name_subscriber_RGB = '/hero/head_rgbd_sensor/rgb/image_raw' if not laptop else 'video_frames' @@ -23,7 +23,7 @@ def __init__(self) -> None: rospy.init_node('listener', anonymous=True) self.publisher = rospy.Publisher('/hero/segmented_image', Image, queue_size=10) # self.subscriber = rospy.Subscriber(name_subscriber_RGB, Image, self.callback, queue_size=1) - self.publisher2 = rospy.Publisher('/hero/test_msg', detect_person, queue_size= 10) + self.publisher2 = rospy.Publisher('/hero/test_msg', DetectPerson, queue_size= 10) self.latest_image = None # To store the most recent image @@ -33,7 +33,7 @@ def __init__(self) -> None: self.subscriber = rospy.Subscriber(name_subscriber_RGB, Image, self.image_callback, queue_size=1) def msg_callback(self): - msg = detect_person() + msg = DetectPerson() msg.name = "hi" msg.age = 5 self.publisher2.publish(msg) diff --git a/people_tracking/src/people_tracker.py b/people_tracking/src/people_tracking/people_tracker.py similarity index 100% rename from people_tracking/src/people_tracker.py rename to people_tracking/src/people_tracking/people_tracker.py diff --git a/people_tracking/src/person_detection.py b/people_tracking/src/people_tracking/person_detection.py similarity index 100% rename from people_tracking/src/person_detection.py rename to people_tracking/src/people_tracking/person_detection.py diff --git a/people_tracking/src/skelly.py b/people_tracking/src/people_tracking/skelly.py similarity index 100% rename from people_tracking/src/skelly.py rename to people_tracking/src/people_tracking/skelly.py diff --git a/people_tracking/src/yolo.py b/people_tracking/src/people_tracking/yolo.py similarity index 51% rename from people_tracking/src/yolo.py rename to people_tracking/src/people_tracking/yolo.py index ecc560e..d45b5c1 100755 --- a/people_tracking/src/yolo.py +++ b/people_tracking/src/people_tracking/yolo.py @@ -1,38 +1,4 @@ #!/usr/bin/env python -# Software License Agreement (BSD License) -# -# Copyright (c) 2008, Willow Garage, Inc. -# All rights reserved. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions -# are met: -# -# * Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# * Redistributions in binary form must reproduce the above -# copyright notice, this list of conditions and the following -# disclaimer in the documentation and/or other materials provided -# with the distribution. -# * Neither the name of Willow Garage, Inc. nor the names of its -# contributors may be used to endorse or promote products derived -# from this software without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS -# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE -# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, -# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN -# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -# POSSIBILITY OF SUCH DAMAGE. -# -# Revision $Id$ - import rospy import cv2 @@ -42,12 +8,8 @@ from sensor_msgs.msg import Image -laptop = True -name_subscriber_RGB = '/hero/head_rgbd_sensor/rgb/image_raw' if not laptop else 'video_frames' - - class PeopleTracker: - def __init__(self) -> None: + def __init__(self, name_subscriber_RGB: str) -> None: # Initialize YOLO model_path = "~/MEGA/developers/Donal/yolov8n-seg.pt" @@ -59,11 +21,12 @@ def __init__(self) -> None: rospy.init_node('listener', anonymous=True) self.publisher = rospy.Publisher('/hero/segmented_image', Image) self.subscriber = rospy.Subscriber(name_subscriber_RGB, Image, self.callback, queue_size = 1) + self.cv_bridge = CvBridge() @staticmethod def detect(model, frame): """ - Return segemented image per class type. + Return segemented image per class type. """ results = model(frame) result = results[0] @@ -74,8 +37,7 @@ def detect(model, frame): def callback(self, data): rospy.loginfo("got message") seconds = rospy.get_time() - bridge = CvBridge() - cv_image = bridge.imgmsg_to_cv2(data, desired_encoding='passthrough') + cv_image = self.cv_bridge.imgmsg_to_cv2(data, desired_encoding='passthrough') cv_image = cv2.GaussianBlur(cv_image, (5, 5), 0) # cv_image = cv2.cvtColor(cv_image, cv2.COLOR_RGB2BGR) rospy.loginfo("converted message") @@ -99,9 +61,11 @@ def callback(self, data): self.publisher.publish(image_message) # Send image with boundaries human -if __name__ == '__main__': +if __name__ == "__main__": + laptop = True + name_subscriber_RGB = "/hero/head_rgbd_sensor/rgb/image_raw" if not laptop else "video_frames" try: - node_pt = PeopleTracker() + node_pt = PeopleTracker(name_subscriber_RGB) rospy.spin() except rospy.exceptions.ROSInterruptException: pass