Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add euclidean cluster #68

Closed
wants to merge 28 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
548941c
release v0.4.0
mitsudome-r Sep 18, 2020
dc0d6a9
remove ROS1 packages temporarily
mitsudome-r Sep 29, 2020
ddd69f0
Revert "remove ROS1 packages temporarily"
mitsudome-r Oct 8, 2020
6bd43be
add COLCON_IGNORE to ros1 packages
mitsudome-r Oct 8, 2020
a8601e8
Rename launch files to launch.xml (#28)
nnmm Oct 15, 2020
1ab07dd
Rename h files to hpp (#142)
nnmm Dec 3, 2020
15f346a
Adjust copyright notice on 532 out of 699 source files (#143)
nnmm Dec 3, 2020
1b02475
Use quotes for includes where appropriate (#144)
nnmm Dec 7, 2020
2871591
Port euclidean cluster (#120)
nik-tier4 Dec 23, 2020
790d79f
Fix perception launches (#240)
TakaHoribe Dec 24, 2020
311601c
Ros2 v0.8.0 euclidean cluster (#310)
tkimura4 Feb 8, 2021
96250c0
add use_sim-time option (#454)
tkimura4 Mar 26, 2021
249696f
Format launch files (#1219)
kenji-miyake Mar 30, 2021
16fc7e0
Unify Apache-2.0 license name (#1242)
kmiya Apr 15, 2021
23d9867
Remove use_sim_time for set_parameter (#1260)
wep21 Apr 26, 2021
cefd126
Fix lint errors (#1378)
kenji-miyake May 25, 2021
7710510
Porting euclidean cluster (#1291)
KeisukeShima Jul 6, 2021
13beecf
Fix -Wunused-parameter (#1836)
kenji-miyake Aug 14, 2021
e0d6c2a
Invoke code formatter at pre-commit (#1935)
IshitaTakeshi Sep 1, 2021
47b4c9f
add sort-package-xml hook in pre-commit (#1881)
KeisukeShima Sep 9, 2021
e7d3a5c
Feature/clustering lib (#1914)
yukkysaito Sep 3, 2021
3989e4c
Detection by tracker (#1910)
yukkysaito Sep 29, 2021
eb41bad
Change formatter to clang-format and black (#2332)
kenji-miyake Nov 2, 2021
08c52c6
Add COLCON_IGNORE (#500)
kenji-miyake Nov 4, 2021
1d15137
port euclidean_cluster (#533)
yukke42 Nov 10, 2021
81a2857
add README of euclidean_cluster (#614)
yukke42 Nov 15, 2021
154422a
auto fix no ground pointcloud topic name (#704)
satoshi-ota Nov 18, 2021
d8af5f1
fix/rename segmentation namespace (#742)
satoshi-ota Nov 29, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 67 additions & 0 deletions perception/euclidean_cluster/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
cmake_minimum_required(VERSION 3.5)
project(euclidean_cluster)

if(NOT CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 14)
endif()
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options(-Wall -Wextra -Wpedantic)
endif()

find_package(ament_cmake_auto REQUIRED)
find_package(PCL REQUIRED QUIET COMPONENTS common search filters segmentation)
ament_auto_find_build_dependencies()


include_directories(
include
${PCL_COMMON_INCLUDE_DIRS}
${PCL_INCLUDE_DIRS}
)

ament_auto_add_library(cluster_lib SHARED
lib/utils.cpp
lib/euclidean_cluster.cpp
lib/voxel_grid_based_euclidean_cluster.cpp
)

target_link_libraries(cluster_lib
${PCL_LIBRARIES}
)

target_include_directories(cluster_lib
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
)

ament_auto_add_library(euclidean_cluster_node_core SHARED
src/euclidean_cluster_node.cpp
)
target_link_libraries(euclidean_cluster_node_core
${PCL_LIBRARIES}
cluster_lib
)

rclcpp_components_register_node(euclidean_cluster_node_core
PLUGIN "euclidean_cluster::EuclideanClusterNode"
EXECUTABLE euclidean_cluster_node
)

ament_auto_add_library(voxel_grid_based_euclidean_cluster_node_core SHARED
src/voxel_grid_based_euclidean_cluster_node.cpp
)
target_link_libraries(voxel_grid_based_euclidean_cluster_node_core
${PCL_LIBRARIES}
cluster_lib
)

rclcpp_components_register_node(voxel_grid_based_euclidean_cluster_node_core
PLUGIN "euclidean_cluster::VoxelGridBasedEuclideanClusterNode"
EXECUTABLE voxel_grid_based_euclidean_cluster_node
)

ament_auto_package(INSTALL_TO_SHARE
launch
config
)
102 changes: 102 additions & 0 deletions perception/euclidean_cluster/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
# euclidean_cluster

## Purpose

euclidean_cluster is a package for clustering points into smaller parts to classify objects.

This package has two clustering methods: `euclidean_cluster` and `voxel_grid_based_euclidean_cluster`.

## Inner-workings / Algorithms

### euclidean_cluster

`pcl::EuclideanClusterExtraction` is applied to points. See [official document](https://pcl.readthedocs.io/en/latest/cluster_extraction.html) for details.

### voxel_grid_based_euclidean_cluster

1. A centroid in each voxel is calculated by `pcl::VoxelGrid`.
2. The centroids are clustered by `pcl::EuclideanClusterExtraction`.
3. The input points are clustered based on the clustered centroids.

## Inputs / Outputs

### Input

| Name | Type | Description |
| ------- | ------------------------------- | ---------------- |
| `input` | `sensor_msgs::msg::PointCloud2` | input pointcloud |

### Output

| Name | Type | Description |
| ---------------- | ----------------------------------------------------------- | -------------------------------------------- |
| `output` | `autoware_perception_msgs::msg::DetectedObjectsWithFeature` | cluster pointcloud |
| `debug/clusters` | `sensor_msgs::msg::PointCloud2` | colored cluster pointcloud for visualization |

## Parameters

### Core Parameters

#### euclidean_cluster

| Name | Type | Description |
| ------------------ | ----- | -------------------------------------------------------------------------------------------- |
| `use_height` | bool | use point.z for clustering |
| `min_cluster_size` | int | the minimum number of points that a cluster needs to contain in order to be considered valid |
| `max_cluster_size` | int | the maximum number of points that a cluster needs to contain in order to be considered valid |
| `tolerance` | float | the spatial cluster tolerance as a measure in the L2 Euclidean space |

#### voxel_grid_based_euclidean_cluster

| Name | Type | Description |
| ----------------------------- | ----- | -------------------------------------------------------------------------------------------- |
| `use_height` | bool | use point.z for clustering |
| `min_cluster_size` | int | the minimum number of points that a cluster needs to contain in order to be considered valid |
| `max_cluster_size` | int | the maximum number of points that a cluster needs to contain in order to be considered valid |
| `tolerance` | float | the spatial cluster tolerance as a measure in the L2 Euclidean space |
| `voxel_leaf_size` | float | the voxel leaf size of x and y |
| `min_points_number_per_voxel` | int | the minimum number of points for a voxel |

## Assumptions / Known limits

<!-- Write assumptions and limitations of your implementation.

Example:
This algorithm assumes obstacles are not moving, so if they rapidly move after the vehicle started to avoid them, it might collide with them.
Also, this algorithm doesn't care about blind spots. In general, since too close obstacles aren't visible due to the sensing performance limit, please take enough margin to obstacles.
-->

## (Optional) Error detection and handling

<!-- Write how to detect errors and how to recover from them.

Example:
This package can handle up to 20 obstacles. If more obstacles found, this node will give up and raise diagnostic errors.
-->

## (Optional) Performance characterization

<!-- Write performance information like complexity. If it wouldn't be the bottleneck, not necessary.

Example:
### Complexity

This algorithm is O(N).

### Processing time

...
-->

## (Optional) References/External links

<!-- Write links you referred to when you implemented.

Example:
[1] {link_to_a_thesis}
[2] {link_to_an_issue}
-->

## (Optional) Future extensions / Unimplemented parts

The `use_height` option of `voxel_grid_based_euclidean_cluster` isn't implemented yet.
3 changes: 3 additions & 0 deletions perception/euclidean_cluster/config/compare_map.param.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/**:
ros__parameters:
distance_threshold: 0.5
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/**:
ros__parameters:
max_cluster_size: 1000
min_cluster_size: 10
tolerance: 0.7
use_height: false
8 changes: 8 additions & 0 deletions perception/euclidean_cluster/config/outlier.param.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/**:
ros__parameters:
input_frame: base_link
output_frame: base_link
voxel_size_x: 0.3
voxel_size_y: 0.3
voxel_size_z: 100.0
voxel_points_threshold: 3
7 changes: 7 additions & 0 deletions perception/euclidean_cluster/config/voxel_grid.param.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/**:
ros__parameters:
input_frame: base_link
output_frame: base_link
voxel_size_x: 0.15
voxel_size_y: 0.15
voxel_size_z: 0.15
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/**:
ros__parameters:
tolerance: 0.7
voxel_leaf_size: 0.3
min_points_number_per_voxel: 1
min_cluster_size: 10
max_cluster_size: 3000
use_height: false
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Copyright 2020 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.

#pragma once

#include "euclidean_cluster/euclidean_cluster_interface.hpp"
#include "euclidean_cluster/utils.hpp"

#include <pcl/point_types.h>

#include <vector>

namespace euclidean_cluster
{
class EuclideanCluster : public EuclideanClusterInterface
{
public:
EuclideanCluster();
EuclideanCluster(bool use_height, int min_cluster_size, int max_cluster_size);
EuclideanCluster(bool use_height, int min_cluster_size, int max_cluster_size, float tolerance);
bool cluster(
const pcl::PointCloud<pcl::PointXYZ>::ConstPtr & pointcloud,
std::vector<pcl::PointCloud<pcl::PointXYZ>> & clusters) override;
void setTolerance(float tolerance) { tolerance_ = tolerance; }

private:
float tolerance_;
};

} // namespace euclidean_cluster
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// 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.

#pragma once

#include <rclcpp/rclcpp.hpp>

#include <pcl/point_cloud.h>
#include <pcl/point_types.h>

#include <vector>

namespace euclidean_cluster
{
class EuclideanClusterInterface
{
public:
EuclideanClusterInterface() = default;
EuclideanClusterInterface(bool use_height, int min_cluster_size, int max_cluster_size)
: use_height_(use_height),
min_cluster_size_(min_cluster_size),
max_cluster_size_(max_cluster_size)
{
}
virtual ~EuclideanClusterInterface() = default;
void setUseHeight(bool use_height) { use_height_ = use_height; }
void setMinClusterSize(int size) { min_cluster_size_ = size; }
void setMaxClusterSize(int size) { max_cluster_size_ = size; }
virtual bool cluster(
const pcl::PointCloud<pcl::PointXYZ>::ConstPtr & pointcloud,
std::vector<pcl::PointCloud<pcl::PointXYZ>> & clusters) = 0;

protected:
bool use_height_ = true;
int min_cluster_size_;
int max_cluster_size_;
};

} // namespace euclidean_cluster
37 changes: 37 additions & 0 deletions perception/euclidean_cluster/include/euclidean_cluster/utils.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.

#pragma once

#include <autoware_perception_msgs/msg/detected_objects_with_feature.hpp>
#include <geometry_msgs/msg/pose_stamped.hpp>
#include <sensor_msgs/msg/point_cloud2.hpp>

#include <pcl/point_cloud.h>
#include <pcl/point_types.h>
#include <pcl_conversions/pcl_conversions.h>

#include <vector>

namespace euclidean_cluster
{
geometry_msgs::msg::Point getCentroid(const sensor_msgs::msg::PointCloud2 & pointcloud);
void convertPointCloudClusters2Msg(
const std_msgs::msg::Header & header,
const std::vector<pcl::PointCloud<pcl::PointXYZ>> & clusters,
autoware_perception_msgs::msg::DetectedObjectsWithFeature & msg);
void convertObjectMsg2SensorMsg(
const autoware_perception_msgs::msg::DetectedObjectsWithFeature & input,
sensor_msgs::msg::PointCloud2 & output);
} // namespace euclidean_cluster
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// 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.

#pragma once

#include "euclidean_cluster/euclidean_cluster_interface.hpp"
#include "euclidean_cluster/utils.hpp"

#include <pcl/filters/voxel_grid.h>
#include <pcl/point_types.h>

#include <vector>

namespace euclidean_cluster
{
class VoxelGridBasedEuclideanCluster : public EuclideanClusterInterface
{
public:
VoxelGridBasedEuclideanCluster();
VoxelGridBasedEuclideanCluster(bool use_height, int min_cluster_size, int max_cluster_size);
VoxelGridBasedEuclideanCluster(
bool use_height, int min_cluster_size, int max_cluster_size, float tolerance,
float voxel_leaf_size, int min_points_number_per_voxel);
bool cluster(
const pcl::PointCloud<pcl::PointXYZ>::ConstPtr & pointcloud,
std::vector<pcl::PointCloud<pcl::PointXYZ>> & clusters) override;
void setVoxelLeafSize(float voxel_leaf_size) { voxel_leaf_size_ = voxel_leaf_size; }
void setTolerance(float tolerance) { tolerance_ = tolerance; }
void setMinPointsNumberPerVoxel(int min_points_number_per_voxel)
{
min_points_number_per_voxel_ = min_points_number_per_voxel;
}

private:
pcl::VoxelGrid<pcl::PointXYZ> voxel_grid_;
float tolerance_;
float voxel_leaf_size_;
int min_points_number_per_voxel_;
};

} // namespace euclidean_cluster
Loading