Skip to content

Commit

Permalink
fix(bytetrack): fix uninteded roi value error due to casting int to u…
Browse files Browse the repository at this point in the history
…int (autowarefoundation#5589)

* fix uint32 conversion bug in bytetrack

Signed-off-by: yoshiri <[email protected]>

* refactor outside xy variable

---------

Signed-off-by: yoshiri <[email protected]>
  • Loading branch information
YoshiRi authored and danielsanchezaran committed Dec 15, 2023
1 parent be4cb50 commit e877b59
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions perception/bytetrack/src/bytetrack_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,18 @@ void ByteTrackNode::on_rect(
bytetrack::ObjectArray objects = bytetrack_->update_tracker(object_array);
for (const auto & tracked_object : objects) {
tier4_perception_msgs::msg::DetectedObjectWithFeature object;
object.feature.roi.x_offset = tracked_object.x_offset;
object.feature.roi.y_offset = tracked_object.y_offset;
object.feature.roi.width = tracked_object.width;
object.feature.roi.height = tracked_object.height;
// fit xy offset to 0 if roi is outside of image
const int outside_x = std::max(-tracked_object.x_offset, 0);
const int outside_y = std::max(-tracked_object.y_offset, 0);
const int32_t output_x = std::max(tracked_object.x_offset, 0);
const int32_t output_y = std::max(tracked_object.y_offset, 0);
const int32_t output_width = tracked_object.width - outside_x;
const int32_t output_height = tracked_object.height - outside_y;
// convert int32 to uint32
object.feature.roi.x_offset = static_cast<uint32_t>(output_x);
object.feature.roi.y_offset = static_cast<uint32_t>(output_y);
object.feature.roi.width = static_cast<uint32_t>(output_width);
object.feature.roi.height = static_cast<uint32_t>(output_height);
object.object.existence_probability = tracked_object.score;
object.object.classification.emplace_back(
autoware_auto_perception_msgs::build<Label>().label(tracked_object.type).probability(1.0f));
Expand Down

0 comments on commit e877b59

Please sign in to comment.