|
5 | 5 | import numpy as np
|
6 | 6 | from ultralytics import YOLO
|
7 | 7 | from sensor_msgs.msg import Image
|
8 |
| -from people_tracking_v2.msg import Detection, DetectionArray, SegmentedImages |
| 8 | +from people_tracking_v2.msg import Detection, DetectionArray, SegmentedImages, DecisionResult |
9 | 9 | from cv_bridge import CvBridge, CvBridgeError
|
10 |
| -from std_msgs.msg import Int32 # Import the Int32 message type for operator ID |
11 | 10 |
|
12 | 11 | import sys
|
13 | 12 | import os
|
@@ -37,8 +36,8 @@ def __init__(self):
|
37 | 36 | self.bounding_box_image_pub = rospy.Publisher("/bounding_box_image", Image, queue_size=10)
|
38 | 37 | self.detection_pub = rospy.Publisher("/detections_info", DetectionArray, queue_size=10)
|
39 | 38 |
|
40 |
| - # Subscriber for operator ID |
41 |
| - self.operator_id_sub = rospy.Subscriber('/decision/result', Int32, self.operator_id_callback) |
| 39 | + # Subscriber for operator ID and decision source |
| 40 | + self.operator_id_sub = rospy.Subscriber('/decision/result', DecisionResult, self.operator_id_callback) |
42 | 41 |
|
43 | 42 | # Initialize the Kalman Filter for the operator
|
44 | 43 | self.kalman_filter_operator = KalmanFilterCV()
|
@@ -74,9 +73,15 @@ def reset_operator_id(self, event):
|
74 | 73 | rospy.loginfo("Operator ID reset to -1")
|
75 | 74 |
|
76 | 75 | def operator_id_callback(self, msg):
|
77 |
| - """Callback function to update the operator ID.""" |
78 |
| - self.operator_id = msg.data |
79 |
| - rospy.loginfo(f"Received operator ID: {self.operator_id}") |
| 76 | + """Callback function to update the operator ID and handle the decision source.""" |
| 77 | + self.operator_id = msg.operator_id |
| 78 | + self.decision_source = msg.decision_source |
| 79 | + rospy.loginfo(f"Received operator ID: {self.operator_id} from {self.decision_source}") |
| 80 | + |
| 81 | + if self.decision_source not in ["IoU", "HoC + Pose to start IoU"]: |
| 82 | + self.operator_initialized = False |
| 83 | + self.operator_box = None |
| 84 | + rospy.loginfo("Kalman Filter stopped due to decision source.") |
80 | 85 |
|
81 | 86 | def depth_image_callback(self, data):
|
82 | 87 | """Store the latest depth image. Only the most recent depth images are stored."""
|
@@ -191,7 +196,7 @@ def image_callback(self, data):
|
191 | 196 | cv2.circle(bounding_box_image, (x_center, y_center), 5, (0, 0, 255), -1)
|
192 | 197 |
|
193 | 198 | # Initialize the operator using the detection with the specified operator ID
|
194 |
| - if not self.operator_initialized and self.operator_id is not None: |
| 199 | + if not self.operator_initialized and self.operator_id is not None and self.decision_source in ["IoU", "HoC + Pose to start IoU"]: |
195 | 200 | for detection in detection_array.detections:
|
196 | 201 | if detection.id == self.operator_id:
|
197 | 202 | self.operator_box = [detection.x1, detection.y1, detection.x2, detection.y2]
|
|
0 commit comments