Skip to content

Commit

Permalink
fix: consider when roi size is zero, rois is empty
Browse files Browse the repository at this point in the history
fix

Signed-off-by: Taekjin LEE <[email protected]>
  • Loading branch information
technolojin committed Jun 20, 2024
1 parent 44d10ae commit 55884b4
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions perception/traffic_light_classifier/src/nodelet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ void TrafficLightClassifierNodelet::imageRoiCallback(
if (classifier_ptr_.use_count() == 0) {
return;
}
if (input_rois_msg->rois.size() == 0) {
return;
}

cv_bridge::CvImagePtr cv_ptr;
try {
Expand All @@ -105,31 +108,34 @@ void TrafficLightClassifierNodelet::imageRoiCallback(
if (input_roi.traffic_light_type != classify_traffic_light_type_) {
continue;
}
// skip if the roi is not detected
// skip if the roi size is zero
if (input_roi.roi.height == 0 || input_roi.roi.width == 0) {
// debug message
RCLCPP_WARN(
this->get_logger(), "roi size is wrong, height %d, width %d", input_roi.roi.height,
input_roi.roi.width);
continue;
}

// create a signal message
output_msg.signals.emplace_back();
auto & signal = output_msg.signals.back();
signal.traffic_light_id = input_roi.traffic_light_id;
signal.traffic_light_type = input_roi.traffic_light_type;

// crop the roi image to be classified
const auto & roi_img = cv_ptr->image(cv::Rect(
input_roi.roi.x_offset, input_roi.roi.y_offset, input_roi.roi.width, input_roi.roi.height));
images.push_back(roi_img);

// check if the roi is a harsh backlight
if (is_harsh_backlight(roi_img)) {
backlight_indices.push_back(output_msg.signals.size() - 1);
}
images.push_back(roi_img);
}

output_msg.signals.resize(images.size());
if (!classifier_ptr_->getTrafficSignals(images, output_msg)) {
RCLCPP_ERROR(this->get_logger(), "failed classify image, abort callback");
return;
// infer the traffic light signals only when there are images
if (!images.empty()) {
output_msg.signals.resize(images.size());
if (!classifier_ptr_->getTrafficSignals(images, output_msg)) {
RCLCPP_ERROR(this->get_logger(), "failed classify image, abort callback");
return;
}
}

// append the undetected rois as unknown
Expand Down

0 comments on commit 55884b4

Please sign in to comment.