Skip to content

Commit 1cc56c5

Browse files
committed
Added changes done during testing
1 parent c0554d2 commit 1cc56c5

File tree

4 files changed

+472
-508
lines changed

4 files changed

+472
-508
lines changed

cuboid_detection/launch/iterative_closest_point.launch

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,11 @@
6161
</node>
6262

6363
<!-- Run RVIZ -->
64-
<node
64+
<!--node
6565
type="rviz"
6666
name="rviz"
6767
pkg="rviz"
6868
args="-d $(find cuboid_detection)/perception.rviz">
69-
</node>
69+
</node-->
7070

7171
</launch>

object_detection/src/object_pose_detection.cpp

Lines changed: 49 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -12,38 +12,38 @@ add_executable(ground_plane_segmentation src/ground_plane_segmentation.cpp)
1212
target_link_libraries(ground_plane_segmentation ${catkin_LIBRARIES})
1313
*/
1414

15-
#include <ros/ros.h>
1615
#include "object_detection/boost.h"
16+
#include <ros/ros.h>
1717

1818
// TF includes
1919
#include <tf/tf.h>
20-
#include <tf/transform_listener.h>
2120
#include <tf/transform_broadcaster.h>
21+
#include <tf/transform_listener.h>
2222
#include <tf_conversions/tf_eigen.h>
2323

2424
// Pose includes
25-
#include <geometry_msgs/Pose.h>
2625
#include <eigen_conversions/eigen_msg.h>
26+
#include <geometry_msgs/Pose.h>
2727

2828
// PCL specific includes
29-
#include <sensor_msgs/PointCloud2.h>
29+
#include <pcl/ModelCoefficients.h>
3030
#include <pcl/io/pcd_io.h>
3131
#include <pcl/io/ply_io.h>
3232
#include <pcl/point_types.h>
3333
#include <pcl/registration/icp.h>
34-
#include <pcl/ModelCoefficients.h>
3534
#include <pcl/sample_consensus/method_types.h>
3635
#include <pcl/sample_consensus/model_types.h>
37-
#include <pcl/segmentation/sac_segmentation.h>
38-
#include <pcl/segmentation/extract_clusters.h>
3936
#include <pcl/search/kdtree.h>
40-
#include <pcl_ros/point_cloud.h>
37+
#include <pcl/segmentation/extract_clusters.h>
38+
#include <pcl/segmentation/sac_segmentation.h>
39+
#include <pcl_conversions/pcl_conversions.h>
40+
#include <pcl_ros/filters/extract_indices.h>
4141
#include <pcl_ros/filters/passthrough.h>
4242
#include <pcl_ros/filters/voxel_grid.h>
43-
#include <pcl_ros/filters/extract_indices.h>
43+
#include <pcl_ros/point_cloud.h>
4444
#include <pcl_ros/point_cloud.h>
4545
#include <pcl_ros/transforms.h>
46-
#include <pcl_conversions/pcl_conversions.h>
46+
#include <sensor_msgs/PointCloud2.h>
4747

4848
// Local includes
4949
#include "object_detection/ObjectDetection.h"
@@ -71,7 +71,7 @@ string template_cuboid_filename;
7171
sensor_msgs::PointCloud2 bbox_msg;
7272
sensor_msgs::PointCloud2 output_msg;
7373
sensor_msgs::PointCloud2 template_msg;
74-
tf::TransformListener *listener;
74+
tf::TransformListener* listener;
7575
geometry_msgs::Pose pose_msg;
7676
Eigen::Affine3d pose_transform;
7777
double dimensions[3];
@@ -89,13 +89,13 @@ void publish_pose(Eigen::Matrix4d H)
8989
// Set translation
9090
tf::Vector3 origin;
9191
origin.setValue(H(0, 3), H(1, 3), H(2, 3));
92-
92+
9393
// Set rotation
9494
tf::Quaternion quaternion;
9595
tf::Matrix3x3 rotation_matrix;
96-
rotation_matrix.setValue(H(0, 0), H(0, 1), H(0, 2),
97-
H(1, 0), H(1, 1), H(1, 2),
98-
H(2, 0), H(2, 1), H(2, 2));
96+
rotation_matrix.setValue(H(0, 0), H(0, 1), H(0, 2),
97+
H(1, 0), H(1, 1), H(1, 2),
98+
H(2, 0), H(2, 1), H(2, 2));
9999
rotation_matrix.getRotation(quaternion);
100100

101101
// Make tf transform message
@@ -128,25 +128,23 @@ void publish_bounding_box(Eigen::Matrix4d H)
128128

129129
// Create a point cloud from the vertices
130130
pcl::PointCloud<pcl::PointXYZ> box_cloud;
131-
box_cloud.push_back(pcl::PointXYZ(-l/2, -w/2, -h/2));
132-
box_cloud.push_back(pcl::PointXYZ(-l/2, -w/2, h/2));
133-
box_cloud.push_back(pcl::PointXYZ(-l/2, w/2, -h/2));
134-
box_cloud.push_back(pcl::PointXYZ(-l/2, w/2, h/2));
135-
box_cloud.push_back(pcl::PointXYZ(l/2, -w/2, -h/2));
136-
box_cloud.push_back(pcl::PointXYZ(l/2, -w/2, h/2));
137-
box_cloud.push_back(pcl::PointXYZ(l/2, w/2, -h/2));
138-
box_cloud.push_back(pcl::PointXYZ(l/2, w/2, h/2));
131+
box_cloud.push_back(pcl::PointXYZ(-l / 2, -w / 2, -h / 2));
132+
box_cloud.push_back(pcl::PointXYZ(-l / 2, -w / 2, h / 2));
133+
box_cloud.push_back(pcl::PointXYZ(-l / 2, w / 2, -h / 2));
134+
box_cloud.push_back(pcl::PointXYZ(-l / 2, w / 2, h / 2));
135+
box_cloud.push_back(pcl::PointXYZ(l / 2, -w / 2, -h / 2));
136+
box_cloud.push_back(pcl::PointXYZ(l / 2, -w / 2, h / 2));
137+
box_cloud.push_back(pcl::PointXYZ(l / 2, w / 2, -h / 2));
138+
box_cloud.push_back(pcl::PointXYZ(l / 2, w / 2, h / 2));
139139

140140
// Transform point cloud
141141
pcl::PointCloud<pcl::PointXYZ>::Ptr transformed_cloud(new pcl::PointCloud<pcl::PointXYZ>);
142142
pcl::transformPointCloud(box_cloud, *transformed_cloud, H.cast<float>());
143143

144-
if (FIRST)
145-
{
144+
if (FIRST) {
146145
FIRST = false;
147146
cout << "Bounding Box Points:" << endl;
148-
for (int i = 0; i < transformed_cloud->size(); i++)
149-
{
147+
for (int i = 0; i < transformed_cloud->size(); i++) {
150148
cout << "X: " << transformed_cloud->points[i].x << " | "
151149
<< "Y: " << transformed_cloud->points[i].y << " | "
152150
<< "Z: " << transformed_cloud->points[i].z << endl;
@@ -161,8 +159,7 @@ void publish_bounding_box(Eigen::Matrix4d H)
161159

162160
void icp_registration(pcl::PointCloud<pcl::PointXYZ>::Ptr input_pcl, pcl::PointCloud<pcl::PointXYZ>::Ptr template_pcl)
163161
{
164-
while (1)
165-
{
162+
while (1) {
166163
// Point cloud containers
167164
pcl::PointCloud<pcl::PointXYZ>::Ptr output_cloud(new pcl::PointCloud<pcl::PointXYZ>);
168165

@@ -180,11 +177,11 @@ void icp_registration(pcl::PointCloud<pcl::PointXYZ>::Ptr input_pcl, pcl::PointC
180177

181178
cerr << "ICP Score Before: " << icp.getFitnessScore() << endl;
182179

183-
if (icp.hasConverged() && icp.getFitnessScore() < icp_fitness_score)
184-
{
180+
if (icp.hasConverged() && icp.getFitnessScore() < icp_fitness_score) {
185181
// Display ICP results
186182
cerr << "\nICP Score: " << icp.getFitnessScore() << endl;
187-
cerr << "ICP Transform:\n" << icp_transform << endl;
183+
cerr << "ICP Transform:\n"
184+
<< icp_transform << endl;
188185

189186
// Convert to ROS data type
190187
pcl::toROSMsg(*output_cloud, output_msg);
@@ -199,21 +196,21 @@ void pcl_callback(const sensor_msgs::PointCloud2ConstPtr& input)
199196
{
200197
// Save the input point cloud to a global variable
201198
pcl_conversions::toPCL(*input, *input_pcl);
202-
if (DEBUG) cerr << "PointCloud before filtering: " << input_pcl->width << " " << input_pcl->height << " data points." << endl;
199+
if (DEBUG)
200+
cerr << "PointCloud before filtering: " << input_pcl->width << " " << input_pcl->height << " data points." << endl;
203201

204202
// Publish template point cloud
205-
if (ICP_SUCCESS)
206-
{
203+
if (ICP_SUCCESS) {
207204
icp_pub.publish(output_msg);
208205
template_msg.header.frame_id = "camera_depth_optical_frame";
209206
template_pub.publish(template_msg);
210207
publish_bounding_box(icp_transform);
211208
publish_pose(icp_transform);
212-
}
209+
}
213210
}
214211

215-
bool service_callback(object_detection::ObjectDetection::Request &req,
216-
object_detection::ObjectDetection::Response &res)
212+
bool service_callback(object_detection::ObjectDetection::Request& req,
213+
object_detection::ObjectDetection::Response& res)
217214
{
218215
// Filter the points in z-axis
219216
pcl::PCLPointCloud2::Ptr cloud_filtered_ptr_z(new pcl::PCLPointCloud2);
@@ -222,7 +219,8 @@ bool service_callback(object_detection::ObjectDetection::Request &req,
222219
pass_z.setFilterFieldName("z");
223220
pass_z.setFilterLimits(0.0, 0.9);
224221
pass_z.filter(*cloud_filtered_ptr_z);
225-
if (DEBUG) cerr << "PointCloud after filtering: " << cloud_filtered_ptr_z->width << " " << cloud_filtered_ptr_z->height << " data points." << endl;
222+
if (DEBUG)
223+
cerr << "PointCloud after filtering: " << cloud_filtered_ptr_z->width << " " << cloud_filtered_ptr_z->height << " data points." << endl;
226224

227225
// Filter the points in y-axis
228226
pcl::PCLPointCloud2::Ptr cloud_filtered_ptr(new pcl::PCLPointCloud2);
@@ -231,7 +229,8 @@ bool service_callback(object_detection::ObjectDetection::Request &req,
231229
pass.setFilterFieldName("x");
232230
pass.setFilterLimits(-0.2, 0.2);
233231
pass.filter(*cloud_filtered_ptr);
234-
if (DEBUG) cerr << "PointCloud after filtering in x-axis: " << cloud_filtered_ptr->width << " " << cloud_filtered_ptr->height << " data points." << endl;
232+
if (DEBUG)
233+
cerr << "PointCloud after filtering in x-axis: " << cloud_filtered_ptr->width << " " << cloud_filtered_ptr->height << " data points." << endl;
235234

236235
// Downsample the points
237236
pcl::PCLPointCloud2::Ptr voxel_ptr(new pcl::PCLPointCloud2);
@@ -249,7 +248,7 @@ bool service_callback(object_detection::ObjectDetection::Request &req,
249248
pcl::PointCloud<pcl::PointXYZ>::Ptr pcl_voxel_ptr(new pcl::PointCloud<pcl::PointXYZ>);
250249
pcl::fromPCLPointCloud2(*voxel_ptr, *pcl_voxel_ptr);
251250

252-
// Segmentation paramters
251+
// Segmentation paramters
253252
seg.setOptimizeCoefficients(true);
254253
seg.setModelType(pcl::SACMODEL_PLANE);
255254
seg.setMethodType(pcl::SAC_RANSAC);
@@ -267,7 +266,8 @@ bool service_callback(object_detection::ObjectDetection::Request &req,
267266
extract.setIndices(inliers);
268267
extract.setNegative(invert);
269268
extract.filter(*plane_cloud_ptr);
270-
if (DEBUG) cerr << "PointCloud representing the planar component: " << plane_cloud_ptr->width << " " << plane_cloud_ptr->height << " data points." << endl;
269+
if (DEBUG)
270+
cerr << "PointCloud representing the planar component: " << plane_cloud_ptr->width << " " << plane_cloud_ptr->height << " data points." << endl;
271271

272272
// Additional filtering
273273
pcl::PCLPointCloud2::Ptr cloud_filtered_ptr_z2(new pcl::PCLPointCloud2);
@@ -276,7 +276,8 @@ bool service_callback(object_detection::ObjectDetection::Request &req,
276276
pass_z2.setFilterFieldName("z");
277277
pass_z2.setFilterLimits(0.0, 0.7);
278278
pass_z2.filter(*cloud_filtered_ptr_z2);
279-
if (DEBUG) cerr << "PointCloud after filtering: " << cloud_filtered_ptr_z2->width << " " << cloud_filtered_ptr->height << " data points." << endl;
279+
if (DEBUG)
280+
cerr << "PointCloud after filtering: " << cloud_filtered_ptr_z2->width << " " << cloud_filtered_ptr->height << " data points." << endl;
280281

281282
// Create the KdTree object for the search method of the extraction
282283
pcl::search::KdTree<pcl::PointXYZ>::Ptr tree(new pcl::search::KdTree<pcl::PointXYZ>);
@@ -302,8 +303,7 @@ bool service_callback(object_detection::ObjectDetection::Request &req,
302303
int obj_id = 1;
303304

304305
// What is this?
305-
for (vector<pcl::PointIndices>::const_iterator it = object_cluster_indices.begin(); it != object_cluster_indices.end(); ++it)
306-
{
306+
for (vector<pcl::PointIndices>::const_iterator it = object_cluster_indices.begin(); it != object_cluster_indices.end(); ++it) {
307307
// Create a pcl object to hold the extracted cluster
308308
pcl::PCLPointCloud2::Ptr object_cluster(new pcl::PCLPointCloud2);
309309
pcl::ExtractIndices<pcl::PCLPointCloud2> obj_extract;
@@ -316,17 +316,16 @@ bool service_callback(object_detection::ObjectDetection::Request &req,
316316
pcl::PointCloud<pcl::PointXYZ>::Ptr object_cluster_pcl(new pcl::PointCloud<pcl::PointXYZ>);
317317
pcl::fromPCLPointCloud2(*object_cluster, *object_cluster_pcl);
318318
// pcl::io::savePCDFile("/home/heethesh/ROS-Workspaces/dash_ws/src/perception/object_detection/templates/clamp.pcd", *object_cluster_pcl, true);
319-
319+
320320
// Convert to ROS data type
321321
sensor_msgs::PointCloud2 output;
322322
pcl_conversions::fromPCL(*object_cluster, output);
323323
pcl_pub.publish(output);
324324

325325
// Read template point cloud
326-
string template_filename = "/home/heethesh/ROS-Workspaces/dash_ws/src/perception/object_detection/templates/eraser_ascii_tf.pcd";
326+
string template_filename = "/home/karmesh/dash_ws/src/perception/object_detection/templates/eraser_ascii_tf.pcd";
327327
pcl::PointCloud<pcl::PointXYZ>::Ptr template_pcl(new pcl::PointCloud<pcl::PointXYZ>);
328-
if (pcl::io::loadPCDFile<pcl::PointXYZ>(template_filename, *template_pcl) == -1)
329-
{
328+
if (pcl::io::loadPCDFile<pcl::PointXYZ>(template_filename, *template_pcl) == -1) {
330329
PCL_ERROR("Couldn't read the template PCL file");
331330
res.success = false;
332331
return false;
@@ -407,7 +406,7 @@ int main(int argc, char** argv)
407406

408407
// // Convert to ROS data type
409408
// pcl::toROSMsg(*template_cuboid, template_msg);
410-
409+
411410
// // Publish template point cloud
412411
// template_msg.header.frame_id = "cuboid_frame";
413412
// template_pub.publish(template_msg);

openface2_ros/launch/openface2_ros.launch

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<launch>
22

3-
<include file="$(find realsense2_camera)/launch/rs_camera.launch"/>
3+
<!--include file="$(find realsense2_camera)/launch/rs_camera.launch"/-->
44

55
<arg name="image_topic" default="/camera/color/image_raw" />
6-
<arg name="publish_viz" default="true" />
6+
<arg name="publish_viz" default="False" />
77

88
<node pkg="openface2_ros" name="openface2_ros" type="openface2_ros" output="screen">
99
<param name="image_topic" value="$(arg image_topic)" type="str"/>

0 commit comments

Comments
 (0)