Skip to content

Commit b04abe7

Browse files
author
ahemaesh
committed
Adding 3d to 2d & ICP cpp files
1 parent 8a52162 commit b04abe7

File tree

5 files changed

+421
-1
lines changed

5 files changed

+421
-1
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
cuboid_detection/bags/*
22

3+
.vscode/
4+
35
# Prerequisites
46
*.d
57

cuboid_detection/CMakeLists.txt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ find_package(catkin REQUIRED COMPONENTS
1414
pcl_ros
1515
roscpp
1616
sensor_msgs
17+
color_object_detection
1718
)
1819

1920
## System dependencies are found with CMake's conventions
@@ -146,7 +147,8 @@ include
146147
# add_executable(${PROJECT_NAME}_node src/cuboid_detection_node.cpp)
147148
# add_executable(example src/example.cpp)
148149
add_executable(ground_plane_segmentation src/ground_plane_segmentation.cpp)
149-
150+
add_executable(iterative_closest_point src/iterative_closest_point.cpp)
151+
add_executable(three_dimension_to_two_dimension src/three_dimension_to_two_dimension.cpp)
150152
## <<<<<<<<<<<<<<<<<<<<<<<
151153

152154
## Rename C++ executable without prefix
@@ -168,3 +170,6 @@ add_executable(ground_plane_segmentation src/ground_plane_segmentation.cpp)
168170
# )
169171
# target_link_libraries(example ${catkin_LIBRARIES})
170172
target_link_libraries(ground_plane_segmentation ${catkin_LIBRARIES})
173+
target_link_libraries(iterative_closest_point ${catkin_LIBRARIES})
174+
target_link_libraries(three_dimension_to_two_dimension ${catkin_LIBRARIES})
175+
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<launch>
3+
4+
<!-- Launch Ground Plane Segmentation file -->
5+
<include file="$(find cuboid_detection)/launch/ground_plane_segmentation.launch"/>
6+
7+
<!-- Lau -->
8+
<node
9+
pkg="cuboid_detection"
10+
type="three_dimension_to_two_dimension"
11+
name="three_dimension_to_two_dimension"
12+
output="screen">
13+
14+
<!-- Set topics and params -->
15+
<!-- <rosparam> -->
16+
<!-- invert (default: true): True > Box; False > Ground Plane -->
17+
<!-- invert: true -->
18+
<!-- voxel_size (default: 0.01): Lower the value, denser the point cloud, more CPU -->
19+
<!-- voxel_size: 0.005 -->
20+
<!-- distance_threshold (default: 0.01): Lower the value, more of box + table noise -->
21+
<!-- distance_threshold: 0.015 -->
22+
<!-- Topics -->
23+
<!-- input: "/camera/depth/color/points"
24+
output: "/ground_plane_segmentation/points"
25+
plane_coefficients: "/ground_plane_segmentation/coefficients"
26+
</rosparam> -->
27+
</node>
28+
29+
<node
30+
pkg="color_object_detection"
31+
type="object_detection.py"
32+
name="object_detection"
33+
output="screen">
34+
</node>
35+
36+
</launch>
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*
2+
*********************************************************
3+
* *******************************************************
4+
* *********** Iterative Closest Point (ICP) ************
5+
* *******************************************************
6+
* ************ written by Avinash on 04-02-2019 *********
7+
*********************************************************
8+
*/
9+
10+
11+
#include <iostream>
12+
#include <ros/ros.h>
13+
#include <pcl_ros/point_cloud.h>
14+
#include <pcl_conversions/pcl_conversions.h>
15+
#include <pcl/io/pcd_io.h>
16+
#include <pcl/point_types.h>
17+
#include <pcl/registration/icp.h>
18+
#include <sensor_msgs/point_cloud_conversion.h>
19+
#include <sensor_msgs/PointCloud.h>
20+
#include <sensor_msgs/PointCloud2.h>
21+
22+
23+
typedef pcl::PointCloud<pcl::PointXYZ> PointCloud;
24+
static ros::Publisher icp_PCL_pub;
25+
26+
pcl::PointCloud<pcl::PointXYZ>::Ptr template_cuboid(new pcl::PointCloud<pcl::PointXYZ>);
27+
pcl::PointCloud<pcl::PointXYZ>::Ptr input_cuboid(new pcl::PointCloud<pcl::PointXYZ>);
28+
29+
int performICP()
30+
{
31+
pcl::IterativeClosestPoint <pcl::PointXYZ, pcl::PointXYZ> icp;
32+
icp.setInputSource(input_cuboid);
33+
icp.setInputTarget(template_cuboid);
34+
pcl::PointCloud <pcl::PointXYZ> Final;
35+
icp.align(Final);
36+
std::cout << "has converged:" << icp.hasConverged() << " score: " <<
37+
icp.getFitnessScore() << std::endl;
38+
std::cout << icp.getFinalTransformation() << std::endl;
39+
40+
//icp_PCL_pub.publish(icp.getFinalTransformation());
41+
42+
return (0);
43+
}
44+
45+
void rawPCL_cb(const sensor_msgs::PointCloud2::ConstPtr& msg)
46+
{
47+
pcl::PCLPointCloud2 pcl_pc2;
48+
pcl_conversions::toPCL(*msg,pcl_pc2);
49+
pcl::fromPCLPointCloud2(pcl_pc2,*input_cuboid);
50+
performICP();
51+
}
52+
53+
int main(int argc, char **argv)
54+
{
55+
ros::init(argc,argv,"iterative_closest_point");
56+
ros::NodeHandle nh;
57+
//icp_PCL_pub = nh.advertise<geometry_msgs::>("iterative_closest_point", 1000);
58+
ros::Subscriber raw_PCL_sub = nh.subscribe<sensor_msgs::PointCloud2>("/ground_plane_segmentation/points", 1000, rawPCL_cb);
59+
60+
if (pcl::io::loadPCDFile<pcl::PointXYZ> ("$/{workspaceFolder}/src/perception/cuboid_detection/templates/template_cuboid_L200_W100_H75.pcd", *template_cuboid) == -1) //* load the file
61+
{
62+
PCL_ERROR ("Couldn't read file test_pcd.pcd \n");
63+
return (-1);
64+
}
65+
66+
ros::spinOnce();
67+
return 0;
68+
}

0 commit comments

Comments
 (0)