Skip to content

Commit

Permalink
Fixed various errors and failing test cases
Browse files Browse the repository at this point in the history
Signed-off-by: wittenator <[email protected]>
  • Loading branch information
wittenator committed Oct 30, 2023
1 parent 33f0cd9 commit 5ddf1ea
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 20 deletions.
27 changes: 17 additions & 10 deletions ros_gz_bridge/src/convert/vision_msgs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,22 @@ convert_ros_to_gz(
{
convert_ros_to_gz(ros_msg.header, (*gz_msg.mutable_header()));

ignition::msgs::AxisAligned2DBox box = gz_msg.box();
ignition::msgs::Vector2d min_corner = box.min_corner();
ignition::msgs::Vector2d max_corner = box.max_corner();
ignition::msgs::AxisAligned2DBox * box = new ignition::msgs::AxisAligned2DBox();
ignition::msgs::Vector2d * min_corner = new ignition::msgs::Vector2d();
ignition::msgs::Vector2d * max_corner = new ignition::msgs::Vector2d();

auto id = ros_msg.results.at(0).hypothesis.class_id;
gz_msg.set_label(std::stoi(id));
if (ros_msg.results.size() != 0) {
auto id = ros_msg.results.at(0).hypothesis.class_id;
gz_msg.set_label(std::stoi(id));
}

min_corner.set_x(ros_msg.bbox.center.position.x - ros_msg.bbox.size_x / 2);
min_corner.set_y(ros_msg.bbox.center.position.y - ros_msg.bbox.size_y / 2);
max_corner.set_x(ros_msg.bbox.center.position.x + ros_msg.bbox.size_x / 2);
max_corner.set_y(ros_msg.bbox.center.position.y + ros_msg.bbox.size_y / 2);
min_corner->set_x(ros_msg.bbox.center.position.x - ros_msg.bbox.size_x / 2);
min_corner->set_y(ros_msg.bbox.center.position.y - ros_msg.bbox.size_y / 2);
max_corner->set_x(ros_msg.bbox.center.position.x + ros_msg.bbox.size_x / 2);
max_corner->set_y(ros_msg.bbox.center.position.y + ros_msg.bbox.size_y / 2);
box->set_allocated_min_corner(min_corner);
box->set_allocated_max_corner(max_corner);
gz_msg.set_allocated_box(box);
}

template<>
Expand All @@ -48,7 +53,8 @@ convert_gz_to_ros(
{
convert_gz_to_ros(gz_msg.header(), ros_msg.header);

ros_msg.results.at(0).hypothesis.class_id = gz_msg.label();
ros_msg.results.resize(1);
ros_msg.results.at(0).hypothesis.class_id = std::to_string(gz_msg.label());
ros_msg.results.at(0).hypothesis.score = 1.0;

ros_msg.bbox.center.position.x = (
Expand Down Expand Up @@ -87,4 +93,5 @@ convert_gz_to_ros(
ros_msg.detections.push_back(ros_box);
}
}

} // namespace ros_gz_bridge
19 changes: 11 additions & 8 deletions ros_gz_bridge/test/utils/gz_test_msg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1471,14 +1471,17 @@ void createTestMsg(ignition::msgs::AnnotatedAxisAligned2DBox & _msg)

_msg.set_label(1);

ignition::msgs::AxisAligned2DBox box = _msg.box();
ignition::msgs::Vector2d min_corner = box.min_corner();
ignition::msgs::Vector2d max_corner = box.max_corner();

min_corner.set_x(1.0);
min_corner.set_y(2.0);
max_corner.set_x(4.0);
max_corner.set_y(6.0);
ignition::msgs::AxisAligned2DBox * box = new ignition::msgs::AxisAligned2DBox();
ignition::msgs::Vector2d * min_corner = new ignition::msgs::Vector2d();
ignition::msgs::Vector2d * max_corner = new ignition::msgs::Vector2d();

min_corner->set_x(2.0);
min_corner->set_y(2.0);
max_corner->set_x(4.0);
max_corner->set_y(6.0);
box->set_allocated_min_corner(min_corner);
box->set_allocated_max_corner(max_corner);
_msg.set_allocated_box(box);
}

void compareTestMsg(const std::shared_ptr<ignition::msgs::AnnotatedAxisAligned2DBox> & _msg)
Expand Down
4 changes: 2 additions & 2 deletions ros_gz_bridge/test/utils/ros_test_msg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1351,8 +1351,8 @@ void createTestMsg(vision_msgs::msg::Detection2D & _msg)
_msg.header = header_msg;

vision_msgs::msg::ObjectHypothesisWithPose class_prob;
class_prob.hypothesis.class_id = std::to_string(1);
class_prob.hypothesis.score = 0.1;
class_prob.hypothesis.class_id = "1";
class_prob.hypothesis.score = 1.0;
_msg.results.push_back(class_prob);

_msg.bbox.size_x = 2.0;
Expand Down

0 comments on commit 5ddf1ea

Please sign in to comment.