forked from ros-perception/vision_msgs
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rolled BoundingRect into BoundingBox2D
Added helper functions to make it easier to go from corner-size representation to center-size representation, plus associated tests.
- Loading branch information
Showing
8 changed files
with
142 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} |