###======================= 라이브러리 호출 부분 =======================
## 필요한 라이브러리를 추가로 호출하세요
###===================================================================
class DetectionNode(Node):
def __init__(self): #
super().__init__('detection_node')
###======================= 토픽 관련 세팅 =======================
qos_profile = rclpy.qos.QoSProfile(depth=10)
self.image_subscription = self.create_subscription(
""" fill in """ # 메세지 타입 지정
""" fill in """ # 웹캠에서 발행하는 이미지 topic
""" fill in """ # callback 함수
""" fill in """ # set qos (Quality of Service)
)
self.captured_image_publisher = self.create_publisher(
""" fill in """ # 캡처된 프레임 퍼블리싱
""" fill in """ # 이미지 캡쳐용 topic
""" fill in """ # set qos
)
self.text_subscriber = self.create_subscription(
""" fill in """ # 메세지 타입 지정
""" fill in """ # 쿼리 텍스트 topic
""" fill in """ # callback 함수
""" fill in """ # set qos
)
self.bridge = """ fill in """
self.get_logger().info("YOLOWorld 노드 시작")
###======================= YOLOWorld load config =======================
### """ fill in """
###=============================================================
###======================= 캡쳐 이미지 저장용 디렉토리 config =======================
### """ fill in """
###=============================================================
# 클래스별 색상 저장을 위한 딕셔너리
self.label_colors = {}
# For visualization (optional)
cv2.namedWindow("YOLOWorld Object Detection", cv2.WINDOW_AUTOSIZE)
def update_class_callback(self, msg):
""" 쿼리 텍스트 topic --> object class update """
new_class = """ fill in """ # Receiving the text data (about class)
if not new_class:
self.get_logger().warn("Received empty class input. Ignoring.")
return
self.current_class = new_class
self.model.set_classes([self.current_class]) # YOLOWorld Class setting update
self.get_logger().info(f"Updated YOLOWorld class to: {self.current_class}")
def detect_callback(self, data):
###======================= 모델 추론 부분 =======================
# ROS Image 메시지를 OpenCV 이미지로 변환
cv_image = """ fill in """ # YOLO는 BGR 형식을 처리 가능
results = self.model.predict(""" fill in """,max_det=""" fill in """, iou=""" fill in """, conf=""" fill in """)
boxes = []
confidences = []
class_ids = []
###======================= 결과 시각화 코드 =======================
### """ fill in """
###=============================================================
# OpenCV 창에 탐지 결과 표시
cv2.imshow('YOLOWorld Object Detection', cv_image)
###======================= 캡처 및 저장 및 퍼블리시 =======================
def main(args=None):
""" fill in """
if __name__ == '__main__':
main()