Skip to content

Commit

Permalink
feat: update data association in object merger (#1001)
Browse files Browse the repository at this point in the history
* backup

Signed-off-by: Yukihiro Saito <yukky.saito@gmail.com>

* backup

Signed-off-by: Yukihiro Saito <yukky.saito@gmail.com>

* bug fix

Signed-off-by: Yukihiro Saito <yukky.saito@gmail.com>

* backup

Signed-off-by: Yukihiro Saito <yukky.saito@gmail.com>

* backup

Signed-off-by: Yukihiro Saito <yukky.saito@gmail.com>

* ci(pre-commit): autofix

* cosmetic change

Signed-off-by: Yukihiro Saito <yukky.saito@gmail.com>

* add parameters

Signed-off-by: Yukihiro Saito <yukky.saito@gmail.com>

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
yukkysaito and pre-commit-ci[bot] authored Jun 30, 2022
1 parent 33eb634 commit ce6ccec
Show file tree
Hide file tree
Showing 19 changed files with 891 additions and 430 deletions.
16 changes: 11 additions & 5 deletions perception/detection_by_tracker/src/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,16 @@ double get2dIoU(
boost::geometry::union_(polygon1, polygon2, union_polygons);
boost::geometry::intersection(polygon1, polygon2, intersection_polygons);

double union_area = 0.0;
double intersection_area = 0.0;
for (const auto & union_polygon : union_polygons) {
union_area += boost::geometry::area(union_polygon);
}
double union_area = 0.0;
for (const auto & intersection_polygon : intersection_polygons) {
intersection_area += boost::geometry::area(intersection_polygon);
}
if (intersection_area == 0.0) return 0.0;

for (const auto & union_polygon : union_polygons) {
union_area += boost::geometry::area(union_polygon);
}
const double iou = union_area < 0.01 ? 0.0 : std::min(1.0, intersection_area / union_area);
return iou;
}
Expand Down Expand Up @@ -122,6 +124,8 @@ double get2dPrecision(
for (const auto & intersection_polygon : intersection_polygons) {
intersection_area += boost::geometry::area(intersection_polygon);
}
if (intersection_area == 0.0) return 0.0;

source_area = boost::geometry::area(source_polygon);
const double precision = std::min(1.0, intersection_area / source_area);
return precision;
Expand Down Expand Up @@ -149,13 +153,15 @@ double get2dRecall(
toPolygon2d(std::get<0>(target_object), std::get<1>(target_object), target_polygon);

std::vector<tier4_autoware_utils::Polygon2d> intersection_polygons;
boost::geometry::union_(source_polygon, target_polygon, intersection_polygons);
boost::geometry::intersection(source_polygon, target_polygon, intersection_polygons);

double intersection_area = 0.0;
double target_area = 0.0;
for (const auto & intersection_polygon : intersection_polygons) {
intersection_area += boost::geometry::area(intersection_polygon);
}
if (intersection_area == 0.0) return 0.0;

target_area += boost::geometry::area(target_polygon);
const double recall = std::min(1.0, intersection_area / target_area);
return recall;
Expand Down
16 changes: 11 additions & 5 deletions perception/multi_object_tracker/src/utils/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,16 @@ double get2dIoU(
boost::geometry::union_(polygon1, polygon2, union_polygons);
boost::geometry::intersection(polygon1, polygon2, intersection_polygons);

double union_area = 0.0;
double intersection_area = 0.0;
for (const auto & union_polygon : union_polygons) {
union_area += boost::geometry::area(union_polygon);
}
double union_area = 0.0;
for (const auto & intersection_polygon : intersection_polygons) {
intersection_area += boost::geometry::area(intersection_polygon);
}
if (intersection_area == 0.0) return 0.0;

for (const auto & union_polygon : union_polygons) {
union_area += boost::geometry::area(union_polygon);
}
const double iou = union_area < 0.01 ? 0.0 : std::min(1.0, intersection_area / union_area);
return iou;
}
Expand Down Expand Up @@ -122,6 +124,8 @@ double get2dPrecision(
for (const auto & intersection_polygon : intersection_polygons) {
intersection_area += boost::geometry::area(intersection_polygon);
}
if (intersection_area == 0.0) return 0.0;

source_area = boost::geometry::area(source_polygon);
const double precision = std::min(1.0, intersection_area / source_area);
return precision;
Expand Down Expand Up @@ -149,13 +153,15 @@ double get2dRecall(
toPolygon2d(std::get<0>(target_object), std::get<1>(target_object), target_polygon);

std::vector<tier4_autoware_utils::Polygon2d> intersection_polygons;
boost::geometry::union_(source_polygon, target_polygon, intersection_polygons);
boost::geometry::intersection(source_polygon, target_polygon, intersection_polygons);

double intersection_area = 0.0;
double target_area = 0.0;
for (const auto & intersection_polygon : intersection_polygons) {
intersection_area += boost::geometry::area(intersection_polygon);
}
if (intersection_area == 0.0) return 0.0;

target_area += boost::geometry::area(target_polygon);
const double recall = std::min(1.0, intersection_area / target_area);
return recall;
Expand Down
25 changes: 22 additions & 3 deletions perception/object_merger/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,34 @@ project(object_merger)
find_package(autoware_cmake REQUIRED)
autoware_package()

find_package(PCL REQUIRED COMPONENTS common filters)
# Ignore -Wnonportable-include-path in Clang for mussp
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options(-Wno-nonportable-include-path)
endif()

### Find Eigen Dependencies
find_package(eigen3_cmake_module REQUIRED)
find_package(Eigen3 REQUIRED)

include_directories(
SYSTEM
${EIGEN3_INCLUDE_DIR}
)

ament_auto_add_library(mu_successive_shortest_path SHARED
src/object_association_merger/data_association/mu_successive_shortest_path/mu_successive_shortest_path_wrapper.cpp
)

ament_auto_add_library(object_association_merger SHARED
src/object_association_merger/utils/utils.cpp
src/object_association_merger/data_association/data_association.cpp
src/object_association_merger/data_association/successive_shortest_path/successive_shortest_path.cpp
src/object_association_merger/node.cpp
)

target_link_libraries(object_association_merger ${PCL_LIBRARIES})
target_link_libraries(object_association_merger
mu_successive_shortest_path
Eigen3::Eigen
)

rclcpp_components_register_node(object_association_merger
PLUGIN "object_association::ObjectAssociationMergerNode"
Expand All @@ -22,4 +40,5 @@ rclcpp_components_register_node(object_association_merger

ament_auto_package(INSTALL_TO_SHARE
launch
config
)
9 changes: 8 additions & 1 deletion perception/object_merger/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,14 @@ The successive shortest path algorithm is used to solve the data association pro

## Parameters

No Parameters.
| Name | Type | Description |
| -------------------- | ------ | ------------------------------------------- |
| `can_assign_matrix` | double | Assignment table for data association |
| `max_dist_matrix` | double | Maximum distance table for data association |
| `max_area_matrix` | double | Maximum area table for data association |
| `min_area_matrix` | double | Minimum area table for data association |
| `max_rad_matrix` | double | Maximum angle table for data association |
| `base_link_frame_id` | double | association frame |

## Assumptions / Known limits

Expand Down
44 changes: 44 additions & 0 deletions perception/object_merger/config/data_association_matrix.param.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/**:
ros__parameters:
can_assign_matrix:
#UNKNOWN, CAR, TRUCK, BUS, TRAILER, MOTORBIKE, BICYCLE,PEDESTRIAN
[0, 0, 0, 0, 0, 0, 0, 0, #UNKNOWN
0, 1, 1, 1, 1, 0, 0, 0, #CAR
0, 1, 1, 1, 1, 0, 0, 0, #TRUCK
0, 1, 1, 1, 1, 0, 0, 0, #BUS
0, 1, 1, 1, 1, 0, 0, 0, #TRAILER
0, 0, 0, 0, 0, 1, 1, 1, #MOTORBIKE
0, 0, 0, 0, 0, 1, 1, 1, #BICYCLE
0, 0, 0, 0, 0, 1, 1, 1] #PEDESTRIAN

max_dist_matrix:
#UNKNOWN, CAR, TRUCK, BUS, TRAILER, MOTORBIKE, BICYCLE, PEDESTRIAN
[4.0, 4.0, 5.0, 5.0, 5.0, 2.0, 2.0, 2.0, #UNKNOWN
4.0, 2.0, 5.0, 5.0, 5.0, 1.0, 1.0, 1.0, #CAR
5.0, 5.0, 5.0, 5.0, 5.0, 1.0, 1.0, 1.0, #TRUCK
5.0, 5.0, 5.0, 5.0, 5.0, 1.0, 1.0, 1.0, #BUS
5.0, 5.0, 5.0, 5.0, 5.0, 1.0, 1.0, 1.0, #TRAILER
2.0, 1.0, 1.0, 1.0, 1.0, 3.0, 3.0, 3.0, #MOTORBIKE
2.0, 1.0, 1.0, 1.0, 1.0, 3.0, 3.0, 3.0, #BICYCLE
2.0, 1.0, 1.0, 1.0, 1.0, 3.0, 3.0, 2.0] #PEDESTRIAN
max_rad_matrix: # If value is greater than pi, it will be ignored.
#UNKNOWN, CAR, TRUCK, BUS, TRAILER MOTORBIKE, BICYCLE, PEDESTRIAN
[3.150, 3.150, 3.150, 3.150, 3.150, 3.150, 3.150, 3.150, #UNKNOWN
3.150, 1.047, 1.047, 1.047, 1.047, 3.150, 3.150, 3.150, #CAR
3.150, 1.047, 1.047, 1.047, 1.047, 3.150, 3.150, 3.150, #TRUCK
3.150, 1.047, 1.047, 1.047, 1.047, 3.150, 3.150, 3.150, #BUS
3.150, 1.047, 1.047, 1.047, 1.047, 3.150, 3.150, 3.150, #TRAILER
3.150, 3.150, 3.150, 3.150, 3.150, 3.150, 3.150, 3.150, #MOTORBIKE
3.150, 3.150, 3.150, 3.150, 3.150, 3.150, 3.150, 3.150, #BICYCLE
3.150, 3.150, 3.150, 3.150, 3.150, 3.150, 3.150, 3.150] #PEDESTRIAN

min_iou_matrix: # If value is negative, it will be ignored.
#UNKNOWN, CAR, TRUCK, BUS, TRAILER, MOTORBIKE, BICYCLE, PEDESTRIAN
[0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, #UNKNOWN
0.1, 0.3, 0.2, 0.2, 0.2, 0.1, 0.1, 0.1, #CAR
0.1, 0.2, 0.3, 0.3, 0.3, 0.1, 0.1, 0.1, #TRUCK
0.1, 0.2, 0.3, 0.3, 0.3, 0.1, 0.1, 0.1, #BUS
0.1, 0.2, 0.3, 0.3, 0.3, 0.1, 0.1, 0.1, #TRAILER
0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, #MOTORBIKE
0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, #BICYCLE
0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1] #PEDESTRIAN
Original file line number Diff line number Diff line change
Expand Up @@ -11,42 +11,49 @@
// 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.
//
//
// Author: v1.0 Yukihiro Saito
//

#ifndef OBJECT_ASSOCIATION_MERGER__DATA_ASSOCIATION_HPP_
#define OBJECT_ASSOCIATION_MERGER__DATA_ASSOCIATION_HPP_
#ifndef OBJECT_ASSOCIATION_MERGER__DATA_ASSOCIATION__DATA_ASSOCIATION_HPP_
#define OBJECT_ASSOCIATION_MERGER__DATA_ASSOCIATION__DATA_ASSOCIATION_HPP_

#include <list>
#include <memory>
#include <unordered_map>
#include <vector>

#define EIGEN_MPL2_ONLY
#include "object_association_merger/data_association/solver/gnn_solver.hpp"

#include <Eigen/Core>
#include <Eigen/Geometry>

#include <autoware_auto_perception_msgs/msg/detected_objects.hpp>
#include <geometry_msgs/msg/point.hpp>
#include <sensor_msgs/msg/point_cloud2.hpp>

class DataAssociation
{
private:
double getDistance(
const geometry_msgs::msg::Point & point0, const geometry_msgs::msg::Point & point1);
geometry_msgs::msg::Point getCentroid(const sensor_msgs::msg::PointCloud2 & pointcloud);
Eigen::MatrixXi can_assign_matrix_;
Eigen::MatrixXd max_dist_matrix_;
Eigen::MatrixXd max_area_matrix_;
Eigen::MatrixXd min_area_matrix_;
Eigen::MatrixXd max_rad_matrix_;
Eigen::MatrixXd min_iou_matrix_;
const double score_threshold_;
std::unique_ptr<gnn_solver::GnnSolverInterface> gnn_solver_ptr_;

public:
DataAssociation();
bool assign(
EIGEN_MAKE_ALIGNED_OPERATOR_NEW
DataAssociation(
std::vector<int> can_assign_vector, std::vector<double> max_dist_vector,
std::vector<double> max_rad_vector, std::vector<double> min_iou_vector);
void assign(
const Eigen::MatrixXd & src, std::unordered_map<int, int> & direct_assignment,
std::unordered_map<int, int> & reverse_assignment);
Eigen::MatrixXd calcScoreMatrix(
const autoware_auto_perception_msgs::msg::DetectedObjects & object0,
const autoware_auto_perception_msgs::msg::DetectedObjects & object1);
const autoware_auto_perception_msgs::msg::DetectedObjects & objects0,
const autoware_auto_perception_msgs::msg::DetectedObjects & objects1);
virtual ~DataAssociation() {}
};

#endif // OBJECT_ASSOCIATION_MERGER__DATA_ASSOCIATION_HPP_
#endif // OBJECT_ASSOCIATION_MERGER__DATA_ASSOCIATION__DATA_ASSOCIATION_HPP_
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Copyright 2021 Tier IV, 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 OBJECT_ASSOCIATION_MERGER__DATA_ASSOCIATION__SOLVER__GNN_SOLVER_HPP_
#define OBJECT_ASSOCIATION_MERGER__DATA_ASSOCIATION__SOLVER__GNN_SOLVER_HPP_

#include "object_association_merger/data_association/solver/gnn_solver_interface.hpp"
#include "object_association_merger/data_association/solver/mu_successive_shortest_path.hpp"
#include "object_association_merger/data_association/solver/successive_shortest_path.hpp"

#endif // OBJECT_ASSOCIATION_MERGER__DATA_ASSOCIATION__SOLVER__GNN_SOLVER_HPP_
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Copyright 2021 Tier IV, 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 OBJECT_ASSOCIATION_MERGER__DATA_ASSOCIATION__SOLVER__GNN_SOLVER_INTERFACE_HPP_
#define OBJECT_ASSOCIATION_MERGER__DATA_ASSOCIATION__SOLVER__GNN_SOLVER_INTERFACE_HPP_

#include <unordered_map>
#include <vector>

namespace gnn_solver
{
class GnnSolverInterface
{
public:
GnnSolverInterface() = default;
virtual ~GnnSolverInterface() = default;

virtual void maximizeLinearAssignment(
const std::vector<std::vector<double>> & cost, std::unordered_map<int, int> * direct_assignment,
std::unordered_map<int, int> * reverse_assignment) = 0;
};
} // namespace gnn_solver

#endif // OBJECT_ASSOCIATION_MERGER__DATA_ASSOCIATION__SOLVER__GNN_SOLVER_INTERFACE_HPP_
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Copyright 2021 Tier IV, 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 OBJECT_ASSOCIATION_MERGER__DATA_ASSOCIATION__SOLVER__MU_SUCCESSIVE_SHORTEST_PATH_HPP_
#define OBJECT_ASSOCIATION_MERGER__DATA_ASSOCIATION__SOLVER__MU_SUCCESSIVE_SHORTEST_PATH_HPP_

#include "object_association_merger/data_association/solver/gnn_solver_interface.hpp"

#include <unordered_map>
#include <vector>

namespace gnn_solver
{
class MuSSP : public GnnSolverInterface
{
public:
MuSSP() = default;
~MuSSP() = default;

void maximizeLinearAssignment(
const std::vector<std::vector<double>> & cost, std::unordered_map<int, int> * direct_assignment,
std::unordered_map<int, int> * reverse_assignment) override;
};
} // namespace gnn_solver

#endif // OBJECT_ASSOCIATION_MERGER__DATA_ASSOCIATION__SOLVER__MU_SUCCESSIVE_SHORTEST_PATH_HPP_
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Copyright 2021 Tier IV, 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 OBJECT_ASSOCIATION_MERGER__DATA_ASSOCIATION__SOLVER__SUCCESSIVE_SHORTEST_PATH_HPP_
#define OBJECT_ASSOCIATION_MERGER__DATA_ASSOCIATION__SOLVER__SUCCESSIVE_SHORTEST_PATH_HPP_

#include "object_association_merger/data_association/solver/gnn_solver_interface.hpp"

#include <unordered_map>
#include <vector>

namespace gnn_solver
{
class SSP : public GnnSolverInterface
{
public:
SSP() = default;
~SSP() = default;

void maximizeLinearAssignment(
const std::vector<std::vector<double>> & cost, std::unordered_map<int, int> * direct_assignment,
std::unordered_map<int, int> * reverse_assignment) override;
};
} // namespace gnn_solver

#endif // OBJECT_ASSOCIATION_MERGER__DATA_ASSOCIATION__SOLVER__SUCCESSIVE_SHORTEST_PATH_HPP_
Loading

0 comments on commit ce6ccec

Please sign in to comment.