Skip to content

Commit

Permalink
Rolled BoundingRect into BoundingBox2D
Browse files Browse the repository at this point in the history
Added helper functions to make it easier to go from corner-size representation to
center-size representation, plus associated tests.
  • Loading branch information
Kukanani committed Jun 14, 2017
1 parent 82a73fe commit 0a40838
Show file tree
Hide file tree
Showing 8 changed files with 142 additions and 25 deletions.
18 changes: 15 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@ find_package(catkin REQUIRED COMPONENTS
sensor_msgs
geometry_msgs)

add_message_files(FILES
BoundingRect.msg
include_directories(include)

add_message_files(
DIRECTORY msg
FILES
BoundingBox2D.msg
BoundingBox3D.msg
Classification2D.msg
Expand All @@ -33,4 +36,13 @@ catkin_package(CATKIN_DEPENDS
std_msgs
sensor_msgs
geometry_msgs
)
)

install(DIRECTORY include/${PROJECT_NAME}/
DESTINATION ${CATKIN_PACKAGE_INCLUDE_DESTINATION}
FILES_MATCHING PATTERN "*.h"
)

if (CATKIN_ENABLE_TESTING)
add_subdirectory(test)
endif()
3 changes: 0 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,6 @@ classifier information.
be a smartphone lying on its back, or a book lying on its side.
* BoundingBox2D, BoundingBox3D: orientable rectangular bounding boxes,
specified by the pose of their center and their size.
* BoundingRect2D: A simplified bounding box that uses the OpenCV format:
definition of the upper-left corner, as well as width and height of the box.
The BoundingRect2D cannot be rotated.

By using a very general message definition, we hope to cover as many of the
various computer vision use cases as possible. Some examples of use cases that
Expand Down
69 changes: 69 additions & 0 deletions include/vision_msgs/create_aabb.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
// Copyright 2017 Open Source Robotics Foundation, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#ifndef VISION_MSGS_BUILD_BBOX_H_
#define VISION_MSGS_BUILD_BBOX_H_

#include "vision_msgs/BoundingBox2D.h"
#include "vision_msgs/BoundingBox3D.h"

namespace vision_msgs
{
/**
* Create an axis-aligned bounding box (AABB) given the upper-left corner,
* width, and height. This allows easy conversion from the OpenCV rectangle
* representation.
*/
static inline BoundingBox2D createAABB2D(uint32_t left,
uint32_t top,
uint32_t width,
uint32_t height)
{
BoundingBox2D bbox;

bbox.center.x = left + width/2.0;
bbox.center.y = top + height/2.0;
bbox.size_x = width;
bbox.size_y = height;

return bbox;
}

/**
* Create an axis-aligned bounding box (AABB) given the upper-left-front
* corner, width, height, and depth. This allows easy conversion from the
* OpenCV rectangle representation.
*/
static inline BoundingBox3D createAABB3D(uint32_t min_x,
uint32_t min_y,
uint32_t min_z,
uint32_t size_x,
uint32_t size_y,
uint32_t size_z)
{
BoundingBox3D bbox;

bbox.center.position.x = min_x + size_x/2.0;
bbox.center.position.y = min_y + size_y/2.0;
bbox.center.position.z = min_z + size_z/2.0;
bbox.center.orientation.w = 1;
bbox.size.x = size_x;
bbox.size.y = size_y;
bbox.size.z = size_z;

return bbox;
}
}

#endif
17 changes: 0 additions & 17 deletions msg/BoundingRect.msg

This file was deleted.

2 changes: 1 addition & 1 deletion msg/Detection2D.msg
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Header header
ObjectHypothesisWithPose[] results

# 2D bounding box surrounding the object.
BoundingRect bbox
BoundingBox2D bbox

# The 2D data that generated these results (i.e. region proposal cropped out of
# the image). Not required for all use cases, so it may be empty.
Expand Down
6 changes: 5 additions & 1 deletion package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,9 @@
<depend>sensor_msgs</depend>
<depend>geometry_msgs</depend>

<export></export>
<test_depend>rosunit</test_depend>

<export>
<architecture_independent/>
</export>
</package>
2 changes: 2 additions & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
include_directories(${catkin_INCLUDE_DIRS})
catkin_add_gtest(vision_msgs_test main.cpp)
50 changes: 50 additions & 0 deletions test/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// Copyright 2017 Open Source Robotics Foundation, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#include <gtest/gtest.h>

#include "vision_msgs/BoundingBox2D.h"
#include "vision_msgs/BoundingBox3D.h"
#include "vision_msgs/create_aabb.h"

TEST(vision_msgs, CreateAABB2D)
{
vision_msgs::BoundingBox2D bbox = vision_msgs::createAABB2D(1,2,3,4);
EXPECT_FLOAT_EQ(bbox.center.x, 2.5); // 1 + 3/2
EXPECT_FLOAT_EQ(bbox.center.y, 4); // 2 + 4/2
EXPECT_EQ(bbox.size_x, 3);
EXPECT_EQ(bbox.size_y, 4);
EXPECT_EQ(bbox.center.theta, 0);
}

TEST(vision_msgs, CreateAABB3D)
{
vision_msgs::BoundingBox3D bbox = vision_msgs::createAABB3D(1,2,3,4,5,6);
EXPECT_FLOAT_EQ(bbox.center.position.x, 3); // 1 + 4/2
EXPECT_FLOAT_EQ(bbox.center.position.y, 4.5); // 2 + 5/2
EXPECT_FLOAT_EQ(bbox.center.position.z, 6); // 3 + 6/2
EXPECT_EQ(bbox.center.orientation.x, 0); // 3 + 6/2
EXPECT_EQ(bbox.center.orientation.y, 0); // 3 + 6/2
EXPECT_EQ(bbox.center.orientation.z, 0); // 3 + 6/2
EXPECT_EQ(bbox.center.orientation.w, 1); // 3 + 6/2
EXPECT_EQ(bbox.size.x, 4);
EXPECT_EQ(bbox.size.y, 5);
EXPECT_EQ(bbox.size.z, 6);
}

int main(int argc, char** argv)
{
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}

0 comments on commit 0a40838

Please sign in to comment.