Skip to content

Commit 7752350

Browse files
authored
fix(bytetrack): fix uninteded roi value error due to casting int to uint (#5589)
* fix uint32 conversion bug in bytetrack Signed-off-by: yoshiri <yoshiyoshidetteiu@gmail.com> * refactor outside xy variable --------- Signed-off-by: yoshiri <yoshiyoshidetteiu@gmail.com>
1 parent ec6b1a0 commit 7752350

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

perception/bytetrack/src/bytetrack_node.cpp

+12-4
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,18 @@ void ByteTrackNode::on_rect(
8383
bytetrack::ObjectArray objects = bytetrack_->update_tracker(object_array);
8484
for (const auto & tracked_object : objects) {
8585
tier4_perception_msgs::msg::DetectedObjectWithFeature object;
86-
object.feature.roi.x_offset = tracked_object.x_offset;
87-
object.feature.roi.y_offset = tracked_object.y_offset;
88-
object.feature.roi.width = tracked_object.width;
89-
object.feature.roi.height = tracked_object.height;
86+
// fit xy offset to 0 if roi is outside of image
87+
const int outside_x = std::max(-tracked_object.x_offset, 0);
88+
const int outside_y = std::max(-tracked_object.y_offset, 0);
89+
const int32_t output_x = std::max(tracked_object.x_offset, 0);
90+
const int32_t output_y = std::max(tracked_object.y_offset, 0);
91+
const int32_t output_width = tracked_object.width - outside_x;
92+
const int32_t output_height = tracked_object.height - outside_y;
93+
// convert int32 to uint32
94+
object.feature.roi.x_offset = static_cast<uint32_t>(output_x);
95+
object.feature.roi.y_offset = static_cast<uint32_t>(output_y);
96+
object.feature.roi.width = static_cast<uint32_t>(output_width);
97+
object.feature.roi.height = static_cast<uint32_t>(output_height);
9098
object.object.existence_probability = tracked_object.score;
9199
object.object.classification.emplace_back(
92100
autoware_auto_perception_msgs::build<Label>().label(tracked_object.type).probability(1.0f));

0 commit comments

Comments
 (0)