Skip to content

Commit 5afc813

Browse files
author
Your Name
committedOct 1, 2024·
add_height_limitation_to_filter
1 parent 637f58f commit 5afc813

19 files changed

+187
-219
lines changed
 

‎perception/shape_estimation/CMakeLists.txt

+5-4
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,11 @@ ament_auto_add_library(shape_estimation_lib SHARED
2121
lib/model/bounding_box.cpp
2222
lib/model/convex_hull.cpp
2323
lib/model/cylinder.cpp
24-
lib/filter/car_filter.cpp
25-
lib/filter/bus_filter.cpp
26-
lib/filter/truck_filter.cpp
27-
lib/filter/trailer_filter.cpp
24+
# lib/filter/car_filter.cpp
25+
# lib/filter/bus_filter.cpp
26+
# lib/filter/truck_filter.cpp
27+
# lib/filter/trailer_filter.cpp
28+
lib/filter/vehicle_filter.cpp
2829
lib/filter/no_filter.cpp
2930
lib/filter/utils.cpp
3031
lib/corrector/no_corrector.cpp

‎perception/shape_estimation/config/shape_estimation.param.yaml

+35
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,38 @@
66
use_vehicle_reference_shape_size: false
77
use_boost_bbox_optimizer: false
88
fix_filtered_objects_label_to_unknown: true
9+
# car config
10+
shapes.car.shape.min_width: 1.5
11+
shapes.car.shape.max_width: 2.5
12+
shapes.car.shape.min_length: 3.0
13+
shapes.car.shape.max_length: 5.8
14+
shapes.car.shape.min_height: 0.3
15+
shapes.car.shape.max_height: 12.0
16+
# truck config
17+
shapes.truck.shape.min_width: 1.5
18+
shapes.truck.shape.max_width: 3.5
19+
shapes.truck.shape.min_length: 4.0
20+
shapes.truck.shape.max_length: 18.0
21+
shapes.truck.shape.min_height: 0.3
22+
shapes.truck.shape.max_height: 18.0
23+
# bus config
24+
shapes.bus.shape.min_width: 2.0
25+
shapes.bus.shape.max_width: 3.2
26+
shapes.bus.shape.min_length: 5.0
27+
shapes.bus.shape.max_length: 17.0
28+
shapes.bus.shape.min_height: 0.3
29+
shapes.bus.shape.max_height: 17.0
30+
# trailer config
31+
shapes.trailer.shape.min_width: 1.5
32+
shapes.trailer.shape.max_width: 3.2
33+
shapes.trailer.shape.min_length: 5.0
34+
shapes.trailer.shape.max_length: 25.0
35+
shapes.trailer.shape.min_height: 0.3
36+
shapes.trailer.shape.max_height: 25.0
37+
# bicycle and motorcycle config
38+
shapes.bicycle.shape.min_width: 0.3
39+
shapes.bicycle.shape.max_width: 1.2
40+
shapes.bicycle.shape.min_length: 1.0
41+
shapes.bicycle.shape.max_length: 2.8
42+
shapes.bicycle.shape.min_height: 0.1
43+
shapes.bicycle.shape.max_height: 3.0

‎perception/shape_estimation/include/shape_estimation/filter/bus_filter.hpp

-33
This file was deleted.

‎perception/shape_estimation/include/shape_estimation/filter/car_filter.hpp

-33
This file was deleted.

‎perception/shape_estimation/include/shape_estimation/filter/filter.hpp

+2-5
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,8 @@
1515
#ifndef SHAPE_ESTIMATION__FILTER__FILTER_HPP_
1616
#define SHAPE_ESTIMATION__FILTER__FILTER_HPP_
1717

18-
#include "shape_estimation/filter/bus_filter.hpp"
19-
#include "shape_estimation/filter/car_filter.hpp"
20-
#include "shape_estimation/filter/filter_interface.hpp"
18+
2119
#include "shape_estimation/filter/no_filter.hpp"
22-
#include "shape_estimation/filter/trailer_filter.hpp"
23-
#include "shape_estimation/filter/truck_filter.hpp"
20+
#include "shape_estimation/filter/vehicle_filter.hpp"
2421

2522
#endif // SHAPE_ESTIMATION__FILTER__FILTER_HPP_

‎perception/shape_estimation/include/shape_estimation/filter/filter_interface.hpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#ifndef SHAPE_ESTIMATION__FILTER__FILTER_INTERFACE_HPP_
1616
#define SHAPE_ESTIMATION__FILTER__FILTER_INTERFACE_HPP_
1717

18+
#include "shape_estimation/shape_estimator.hpp"
1819
#include <autoware_auto_perception_msgs/msg/shape.hpp>
1920
#include <geometry_msgs/msg/pose.hpp>
2021

@@ -29,7 +30,8 @@ class ShapeEstimationFilterInterface
2930

3031
virtual bool filter(
3132
const autoware_auto_perception_msgs::msg::Shape & shape,
32-
const geometry_msgs::msg::Pose & pose) = 0;
33+
const geometry_msgs::msg::Pose & pose,
34+
const ShapeParameters & param ) = 0;
3335
};
3436

3537
#endif // SHAPE_ESTIMATION__FILTER__FILTER_INTERFACE_HPP_

‎perception/shape_estimation/include/shape_estimation/filter/no_filter.hpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ class NoFilter : public ShapeEstimationFilterInterface
2626

2727
bool filter(
2828
const autoware_auto_perception_msgs::msg::Shape & shape,
29-
const geometry_msgs::msg::Pose & pose) override;
29+
const geometry_msgs::msg::Pose & pose,
30+
const ShapeParameters & shape_param
31+
) override;
3032
};
3133

3234
#endif // SHAPE_ESTIMATION__FILTER__NO_FILTER_HPP_

‎perception/shape_estimation/include/shape_estimation/filter/truck_filter.hpp

-33
This file was deleted.

‎perception/shape_estimation/include/shape_estimation/filter/utils.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ namespace utils
2121
{
2222
bool filterVehicleBoundingBox(
2323
const autoware_auto_perception_msgs::msg::Shape & shape, const float min_width,
24-
const float max_width, const float max_length);
24+
const float max_width, const float max_length, const float min_height, const float max_height);
2525
} // namespace utils
2626

2727
#endif // SHAPE_ESTIMATION__FILTER__UTILS_HPP_

‎perception/shape_estimation/include/shape_estimation/filter/trailer_filter.hpp ‎perception/shape_estimation/include/shape_estimation/filter/vehicle_filter.hpp

+7-6
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,23 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
#ifndef SHAPE_ESTIMATION__FILTER__TRAILER_FILTER_HPP_
16-
#define SHAPE_ESTIMATION__FILTER__TRAILER_FILTER_HPP_
15+
#ifndef SHAPE_ESTIMATION__FILTER__VEHICLE_FILTER_HPP_
16+
#define SHAPE_ESTIMATION__FILTER__VEHICLE_FILTER_HPP_
1717

1818
#include "shape_estimation/filter/filter_interface.hpp"
1919
#include "utils.hpp"
2020

21-
class TrailerFilter : public ShapeEstimationFilterInterface
21+
class VehicleFilter : public ShapeEstimationFilterInterface
2222
{
2323
public:
24-
TrailerFilter() = default;
24+
VehicleFilter() = default;
2525

26-
~TrailerFilter() = default;
26+
~VehicleFilter() = default;
2727

2828
bool filter(
2929
const autoware_auto_perception_msgs::msg::Shape & shape,
30-
const geometry_msgs::msg::Pose & pose) override;
30+
const geometry_msgs::msg::Pose & pose,
31+
const ShapeParameters & shape_param ) override;
3132
};
3233

3334
#endif // SHAPE_ESTIMATION__FILTER__TRAILER_FILTER_HPP_

‎perception/shape_estimation/include/shape_estimation/shape_estimator.hpp

+25-2
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,23 @@
2727

2828
#include <string>
2929

30+
struct ShapeLimitations
31+
{
32+
float min_width;
33+
float max_width;
34+
float min_length;
35+
float max_length;
36+
float min_height;
37+
float max_height;
38+
};
39+
40+
struct ShapeParameters
41+
{
42+
std::string name;
43+
ShapeLimitations shape_limitations;
44+
std::string get_name() const { return name; }
45+
};
46+
3047
struct ReferenceYawInfo
3148
{
3249
float yaw;
@@ -55,18 +72,24 @@ class ShapeEstimator
5572
geometry_msgs::msg::Pose & pose_output);
5673
bool applyFilter(
5774
const uint8_t label, const autoware_auto_perception_msgs::msg::Shape & shape,
58-
const geometry_msgs::msg::Pose & pose);
75+
const geometry_msgs::msg::Pose & pose, const ShapeParameters & shape_limitation);
5976
bool applyCorrector(
6077
const uint8_t label, const bool use_reference_yaw,
6178
const boost::optional<ReferenceShapeSizeInfo> & ref_shape_size_info,
6279
autoware_auto_perception_msgs::msg::Shape & shape, geometry_msgs::msg::Pose & pose);
80+
// add labelToString function
81+
ShapeParameters getShapeLimitation(const std::string & name);
82+
std::string labelToString(const uint8_t label);
83+
6384

6485
bool use_corrector_;
6586
bool use_filter_;
6687
bool use_boost_bbox_optimizer_;
88+
// add shapes_ constructor
89+
std::vector<ShapeParameters> shapes_;
6790

6891
public:
69-
ShapeEstimator(bool use_corrector, bool use_filter, bool use_boost_bbox_optimizer = false);
92+
ShapeEstimator(std::vector<ShapeParameters> & shapes, bool use_corrector, bool use_filter, bool use_boost_bbox_optimizer = false);
7093

7194
virtual ~ShapeEstimator() = default;
7295

‎perception/shape_estimation/lib/filter/car_filter.cpp

-25
This file was deleted.

‎perception/shape_estimation/lib/filter/no_filter.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616

1717
bool NoFilter::filter(
1818
[[maybe_unused]] const autoware_auto_perception_msgs::msg::Shape & shape,
19-
[[maybe_unused]] const geometry_msgs::msg::Pose & pose)
19+
[[maybe_unused]] const geometry_msgs::msg::Pose & pose,
20+
[[maybe_unused]] const ShapeParameters & shape_param)
2021
{
2122
return true;
2223
}

‎perception/shape_estimation/lib/filter/trailer_filter.cpp

-25
This file was deleted.

‎perception/shape_estimation/lib/filter/truck_filter.cpp

-25
This file was deleted.

‎perception/shape_estimation/lib/filter/utils.cpp

+9-1
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,18 @@
1313
// limitations under the License.
1414

1515
#include "shape_estimation/filter/utils.hpp"
16+
#include <iostream>
1617

1718
namespace utils
1819
{
1920
bool filterVehicleBoundingBox(
2021
const autoware_auto_perception_msgs::msg::Shape & shape, const float min_width,
21-
const float max_width, const float max_length)
22+
const float max_width, const float max_length, const float min_height, const float max_height)
2223
{
2324
const float x = shape.dimensions.x;
2425
const float y = shape.dimensions.y;
2526
const float s = x * y;
27+
const float z = shape.dimensions.z;
2628

2729
if (shape.type != autoware_auto_perception_msgs::msg::Shape::BOUNDING_BOX) {
2830
return true;
@@ -41,6 +43,12 @@ bool filterVehicleBoundingBox(
4143
if (max_length * max_width < s) {
4244
return false;
4345
}
46+
47+
if (max_height < z || z < min_height) {
48+
std::cout <<"Filtered (min_height:" << min_height << ", max_height:" << max_height << ")" <<std::endl;
49+
std::cout <<"Removed (x:" << x << ", y:" << y << ", z: " << z << ")" <<std::endl;
50+
return false;
51+
}
4452
return true;
4553
}
4654
} // namespace utils

‎perception/shape_estimation/lib/filter/bus_filter.cpp ‎perception/shape_estimation/lib/filter/vehicle_filter.cpp

+12-7
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,19 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
#include "shape_estimation/filter/bus_filter.hpp"
15+
#include "shape_estimation/filter/vehicle_filter.hpp"
16+
#include <iostream>
1617

17-
bool BusFilter::filter(
18+
bool VehicleFilter::filter(
1819
const autoware_auto_perception_msgs::msg::Shape & shape,
19-
[[maybe_unused]] const geometry_msgs::msg::Pose & pose)
20+
[[maybe_unused]] const geometry_msgs::msg::Pose & pose,
21+
[[maybe_unused]] const ShapeParameters & shape_param)
2022
{
21-
constexpr float min_width = 2.0;
22-
constexpr float max_width = 3.2;
23-
constexpr float max_length = 17.0;
24-
return utils::filterVehicleBoundingBox(shape, min_width, max_width, max_length);
23+
std::cout << "VehicleFilter::filter with " << shape_param.name << std::endl;
24+
float min_width = shape_param.shape_limitations.min_width;
25+
float max_width = shape_param.shape_limitations.max_width;
26+
float max_length = shape_param.shape_limitations.max_length;
27+
float min_height = shape_param.shape_limitations.min_height;
28+
float max_height = shape_param.shape_limitations.max_height;
29+
return utils::filterVehicleBoundingBox(shape, min_width, max_width, max_length, min_height, max_height);
2530
}

‎perception/shape_estimation/lib/shape_estimator.cpp

+63-14
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,11 @@
2323

2424
using Label = autoware_auto_perception_msgs::msg::ObjectClassification;
2525

26-
ShapeEstimator::ShapeEstimator(bool use_corrector, bool use_filter, bool use_boost_bbox_optimizer)
26+
ShapeEstimator::ShapeEstimator(std::vector<ShapeParameters> & shapes, bool use_corrector, bool use_filter, bool use_boost_bbox_optimizer)
2727
: use_corrector_(use_corrector),
2828
use_filter_(use_filter),
29-
use_boost_bbox_optimizer_(use_boost_bbox_optimizer)
29+
use_boost_bbox_optimizer_(use_boost_bbox_optimizer),
30+
shapes_(shapes)
3031
{
3132
}
3233

@@ -38,6 +39,11 @@ bool ShapeEstimator::estimateShapeAndPose(
3839
{
3940
autoware_auto_perception_msgs::msg::Shape shape;
4041
geometry_msgs::msg::Pose pose;
42+
43+
//get str name of label
44+
std::string label_str = labelToString(label);
45+
ShapeParameters shape_limitation = getShapeLimitation(label_str);
46+
4147
// estimate shape
4248
bool reverse_to_unknown = false;
4349
if (!estimateOriginalShapeAndPose(label, cluster, ref_yaw_info, shape, pose)) {
@@ -46,7 +52,7 @@ bool ShapeEstimator::estimateShapeAndPose(
4652

4753
// rule based filter
4854
if (use_filter_) {
49-
if (!applyFilter(label, shape, pose)) {
55+
if (!applyFilter(label, shape, pose, shape_limitation)) {
5056
reverse_to_unknown = true;
5157
}
5258
}
@@ -91,22 +97,15 @@ bool ShapeEstimator::estimateOriginalShapeAndPose(
9197

9298
bool ShapeEstimator::applyFilter(
9399
const uint8_t label, const autoware_auto_perception_msgs::msg::Shape & shape,
94-
const geometry_msgs::msg::Pose & pose)
100+
const geometry_msgs::msg::Pose & pose, const ShapeParameters & shape_limitation)
95101
{
96102
std::unique_ptr<ShapeEstimationFilterInterface> filter_ptr;
97-
if (label == Label::CAR) {
98-
filter_ptr.reset(new CarFilter);
99-
} else if (label == Label::BUS) {
100-
filter_ptr.reset(new BusFilter);
101-
} else if (label == Label::TRUCK) {
102-
filter_ptr.reset(new TruckFilter);
103-
} else if (label == Label::TRAILER) {
104-
filter_ptr.reset(new TrailerFilter);
103+
if (label == Label::CAR || label == Label::BUS || label == Label::TRUCK || label == Label::TRAILER) {
104+
filter_ptr.reset(new VehicleFilter);
105105
} else {
106106
filter_ptr.reset(new NoFilter);
107107
}
108-
109-
return filter_ptr->filter(shape, pose);
108+
return filter_ptr->filter(shape, pose, shape_limitation);
110109
}
111110

112111
bool ShapeEstimator::applyCorrector(
@@ -134,3 +133,53 @@ bool ShapeEstimator::applyCorrector(
134133

135134
return corrector_ptr->correct(shape, pose);
136135
}
136+
137+
// get shape_limitation by name
138+
ShapeParameters ShapeEstimator::getShapeLimitation(const std::string & name)
139+
{
140+
for (const auto & param : shapes_) {
141+
if (param.name == name) {
142+
// debug print
143+
std::cout << "Shape Limitation in Query: " << param.name << std::endl;
144+
// std::cout << "min_width: " << param.shape_limitations.min_width << std::endl;
145+
// std::cout << "max_width: " << param.shape_limitations.max_width << std::endl;
146+
// std::cout << "min_length: " << param.shape_limitations.min_length << std::endl;
147+
// std::cout << "max_length: " << param.shape_limitations.max_length << std::endl;
148+
// std::cout << "min_height: " << param.shape_limitations.min_height << std::endl;
149+
// std::cout << "max_height: " << param.shape_limitations.max_height << std::endl;
150+
return param;
151+
}
152+
}
153+
ShapeParameters shape_limitation;
154+
shape_limitation.name = "unknown";
155+
shape_limitation.shape_limitations.min_width = 0.0;
156+
shape_limitation.shape_limitations.max_width = 99.0;
157+
shape_limitation.shape_limitations.min_length = 0.0;
158+
shape_limitation.shape_limitations.max_length = 99.0;
159+
shape_limitation.shape_limitations.min_height = 0.0;
160+
shape_limitation.shape_limitations.max_height = 99.0;
161+
return shape_limitation;
162+
}
163+
164+
165+
// convert label(uint8_t) to string
166+
std::string ShapeEstimator::labelToString(const uint8_t label)
167+
{
168+
if (label == Label::CAR) {
169+
return "car";
170+
} else if (label == Label::TRUCK) {
171+
return "truck";
172+
} else if (label == Label::BUS) {
173+
return "bus";
174+
} else if (label == Label::TRAILER) {
175+
return "trailer";
176+
} else if (label == Label::BICYCLE) {
177+
return "bicycle";
178+
} else if (label == Label::MOTORCYCLE) {
179+
return "bicycle";
180+
} else if (label == Label::PEDESTRIAN) {
181+
return "pedestrian";
182+
} else {
183+
return "unknown";
184+
}
185+
}

‎perception/shape_estimation/src/node.cpp

+20-2
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131

3232
#include <memory>
3333
#include <string>
34+
#include <vector>
3435

3536
using Label = autoware_auto_perception_msgs::msg::ObjectClassification;
3637

@@ -50,8 +51,25 @@ ShapeEstimationNode::ShapeEstimationNode(const rclcpp::NodeOptions & node_option
5051
fix_filtered_objects_label_to_unknown_ =
5152
declare_parameter<bool>("fix_filtered_objects_label_to_unknown");
5253
RCLCPP_INFO(this->get_logger(), "using boost shape estimation : %d", use_boost_bbox_optimizer);
53-
estimator_ =
54-
std::make_unique<ShapeEstimator>(use_corrector, use_filter, use_boost_bbox_optimizer);
54+
55+
// get shape params
56+
// set shapes as blank std::vector<ShapeParameters> constructor
57+
std::vector<ShapeParameters> shapes;
58+
{
59+
std::vector<std::string> shape_names = {"bus", "car", "truck", "trailer", "bicycle"};
60+
for (const auto & name : shape_names) {
61+
ShapeParameters shape_param;
62+
shape_param.name = name;
63+
shape_param.shape_limitations.min_width = this->declare_parameter<float>("shapes." + name + ".shape.min_width");
64+
shape_param.shape_limitations.max_width = this->declare_parameter<float>("shapes." + name + ".shape.max_width");
65+
shape_param.shape_limitations.min_length = this->declare_parameter<float>("shapes." + name + ".shape.min_length");
66+
shape_param.shape_limitations.max_length = this->declare_parameter<float>("shapes." + name + ".shape.max_length");
67+
shape_param.shape_limitations.min_height = this->declare_parameter<float>("shapes." + name + ".shape.min_height");
68+
shape_param.shape_limitations.max_height = this->declare_parameter<float>("shapes." + name + ".shape.max_height");
69+
shapes.push_back(shape_param);
70+
}
71+
}
72+
estimator_ = std::make_unique<ShapeEstimator>(shapes, use_corrector, use_filter, use_boost_bbox_optimizer);
5573

5674
processing_time_publisher_ =
5775
std::make_unique<tier4_autoware_utils::DebugPublisher>(this, "shape_estimation");

0 commit comments

Comments
 (0)
Please sign in to comment.