def _handle_yolo_detect(self, req):
    cv_image = None
    detection_array = Detection2DArray()
    detections = []
    boxes = None
    try:
        cv_image = self.bridge.imgmsg_to_cv2(req.image, 'bgr8')
    except CvBridgeError as e:
        rospy.logerr(e)
    try:
        boxes = self.yolo.predict(cv_image)
    except SystemError:
        pass
    for box in boxes:
        detection = Detection2D()
        results = []
        bbox = BoundingBox2D()
        center = Pose2D()
        detection.header = Header()
        detection.header.stamp = rospy.get_rostime()
        labels = box.get_all_labels()
        for i in range(0, len(labels)):
            object_hypothesis = ObjectHypothesisWithPose()
            object_hypothesis.id = i
            object_hypothesis.score = labels[i]
            results.append(object_hypothesis)
        detection.results = results
        (x, y) = box.get_xy_center()
        center.x = x
        center.y = y
        center.theta = 0.0
        bbox.center = center
        (size_x, size_y) = box.get_xy_extents()
        bbox.size_x = size_x
        bbox.size_y = size_y
        detection.bbox = bbox
        detections.append(detection)
    detection_array.header = Header()
    detection_array.header.stamp = rospy.get_rostime()
    detection_array.detections = detections
    return YoloDetectResponse(detection_array)
def _handle_yolo_detect(self, req):
    cv_image = None
    detection_array = Detection2DArray()
    detections = []
    boxes = None
    try:
        cv_image = self.bridge.imgmsg_to_cv2(req.image, 'bgr8')
    except CvBridgeError as e:
        rospy.logerr(e)
    try:
        boxes = self.yolo.predict(cv_image)
    except SystemError:
        pass
    for box in boxes:
        detection = Detection2D()
        results = []
        bbox = BoundingBox2D()
        center = Pose2D()
        detection.header = Header()
        detection.header.stamp = rospy.get_rostime()
        labels = box.get_all_labels()
        for i in range(0, len(labels)):
            object_hypothesis = ObjectHypothesisWithPose()
            object_hypothesis.id = i
            object_hypothesis.score = labels[i]
            results.append(object_hypothesis)
        detection.results = results
        (x, y) = box.get_xy_center()
        center.x = x
        center.y = y
        center.theta = 0.0
        bbox.center = center
        (size_x, size_y) = box.get_xy_extents()
        bbox.size_x = size_x
        bbox.size_y = size_y
        detection.bbox = bbox
        detections.append(detection)
    detection_array.header = Header()
    detection_array.header.stamp = rospy.get_rostime()
    detection_array.detections = detections
    return YoloDetectResponse(detection_array)