Go to the documentation of this file.00001 #include <ros/ros.h>
00002 #include <pcl_ros/point_cloud.h>
00003 #include <pcl/point_types.h>
00004 #include <boost/foreach.hpp>
00005 #include <pcl/io/pcd_io.h>
00006 #include <iostream>
00007 #include <fstream>
00008 #include <stdio.h>
00009
00010 #include <iostream>
00011 using namespace std;
00012
00013 #include <narf_recognition/object_recognition_helper.h>
00014 #include <boost/thread/thread.hpp>
00015 #include "pcl/console/parse.h"
00016
00017 #include "pcl/visualization/range_image_visualizer.h"
00018 #include "pcl/visualization/pcl_visualizer.h"
00019
00020 #include "Eigen/Geometry"
00021 #include "pcl/point_cloud.h"
00022 #include "pcl/point_types.h"
00023
00024 #include "pcl/io/pcd_io.h"
00025 #include "pcl/range_image/range_image.h"
00026 #include "pcl/features/narf.h"
00027
00028 #include "pcl/common/point_correspondence.h"
00029 #include "pcl/common/poses_from_matches.h"
00030 #include "pcl/features/range_image_border_extractor.h"
00031 #include "pcl/keypoints/narf_keypoint.h"
00032 #include "pcl/range_image/range_image_planar.h"
00033 #include "sensor_msgs/Image.h"
00034 #include "pcl/common/file_io.h"
00035
00036
00037
00038 #include "pcl/common/common_headers.h"
00039 #include <ros/ros.h>
00040 #include <pcl_ros/point_cloud.h>
00041
00042 #include <unistd.h>
00043
00044 using namespace pcl;
00045 using namespace pcl::visualization;
00046
00047
00048
00049 ObjectRecognitionHelper object_recognition_helper;
00050 ObjectRecognitionHelper::Parameters& orh_params = object_recognition_helper.getParameters ();
00051 FalsePositivesFilter& false_positives_filter = object_recognition_helper.getFalsePositivesFilter ();
00052 FalsePositivesFilter::Parameters& fpf_params = false_positives_filter.getParameters ();
00053
00054 int& max_no_of_threads = orh_params.max_no_of_threads;
00055 bool& use_rotation_invariance = orh_params.use_rotation_invariance;
00056 float& angular_resolution = orh_params.angular_resolution;
00057 RangeImage::CoordinateFrame& coordinate_frame = orh_params.coordinate_frame;
00058 float& max_descriptor_distance = orh_params.max_descriptor_distance;
00059 bool& set_unseen_to_max_range = orh_params.set_unseen_to_max_range;
00060 bool single_view_model = orh_params.single_view_model;
00061
00062 float noise_level_factor = 0.1;
00063 float support_size_factor = 0.5f;
00064
00065 bool show_model_views = 0;
00066 bool show_view_simulation_results = 0;
00067 bool show_validation_points = 0;
00068 bool show_found_objects = 1;
00069 bool show_feature_match_positions = 0;
00070 bool show_interest_points = 0;
00071 bool print_timings = true;
00072 sensor_msgs::ImageConstPtr depth_image_msg;
00073 boost::mutex m;
00074 bool got_new_data=false;
00075
00076
00077 bool fileExist(const char *fileName)
00078 { FILE *pFile;
00079 pFile = fopen(fileName, "r");
00080 if(pFile != NULL)
00081 { fclose(pFile);
00082 return true;
00083 }
00084 return false;
00085 }
00086
00087 void callback(const pcl::PointCloud<pcl::PointXYZ>::ConstPtr& msg, ros::Publisher &pub, ros::Publisher &pub2)
00088 {
00089 static bool foundObject = false;
00090
00091
00092
00093
00094 PointCloud<PointXYZ> scene(*msg);
00095
00096 vector<string> point_clouds_in_viewer;
00097 object_recognition_helper.createRangeImageFromPointCloud (*msg);
00098 object_recognition_helper.extractSceneFeatures ();
00099 object_recognition_helper.extractPoseEstimates ();
00100 std::vector<PosesFromMatches::PoseEstimatesVector>& pose_estimates_per_model =
00101 object_recognition_helper.filterFalsePositives ();
00102
00103 object_recognition_helper.printTimings ();
00104 vector<boost::shared_ptr<ObjectModel::PointCloudType> > objects_in_scene;
00105 PosesFromMatches::PoseEstimatesVector& pose_estimates = pose_estimates_per_model[0];
00106 ObjectModelList& object_models = object_recognition_helper.getIntermediateElements ().object_models;
00107
00108 for (unsigned int pose_estimate_idx=0; pose_estimate_idx<pose_estimates.size (); ++pose_estimate_idx)
00109 {
00110 const PosesFromMatches::PoseEstimate& pose_estimate = pose_estimates[pose_estimate_idx];
00111 objects_in_scene.push_back (boost::shared_ptr<ObjectModel::PointCloudType> (new ObjectModel::PointCloudType));
00112 object_models[0]->getTransformedPointCloud (pose_estimate.transformation, *objects_in_scene.back ());
00113
00114 float x, y, z, roll, pitch, yaw;
00115 pcl::getTranslationAndEulerAngles (pose_estimate.transformation, x, y, z, roll, pitch, yaw);
00116 foundObject = true;
00117 cout << "Found object at "<<pose_estimate.transformation(0,0)<<".....\n";
00118 cout << "Found object at "<<x<<", "<<y<<", "<<z<<" with rotation "<<pcl::rad2deg(roll)<<"deg, "<<pcl::rad2deg(pitch)<<"deg, "<<pcl::rad2deg(yaw)<<"deg.\n";
00119
00120 objects_in_scene.back()->header.stamp = msg->header.stamp;
00121 objects_in_scene.back()->header.frame_id = msg->header.frame_id;
00122 if(pub.getNumSubscribers() != 0) pub.publish(objects_in_scene.back());
00123 }
00124 if(pub2.getNumSubscribers() != 0) pub2.publish(*msg);
00125
00126 ROS_INFO("Callback Finished");
00127 usleep(10000);
00128 }
00129
00130
00131 int main(int argc, char** argv)
00132 {
00133 std::string object_name;
00134
00135 ros::init(argc, argv, "object_filter");
00136 ros::NodeHandle nh;
00137 ros::NodeHandle pnh("~");
00138
00139 if (pnh.getParam("object_name", object_name))
00140 {
00141
00142
00143 orh_params.view_sampling_first_layer = 0;
00144 orh_params.view_sampling_last_layer = 2;
00145
00146 vector<string> model_filenames;
00147 model_filenames.push_back (object_name);
00148 if (!object_recognition_helper.addObjectModelsFromPcdFiles (model_filenames))
00149 {
00150 ROS_FATAL("Could not add object model: %s", model_filenames.back().c_str());
00151 exit (1);
00152 }
00153 object_recognition_helper.extractModelFeatures ();
00154 ObjectModelList& object_models = object_recognition_helper.getIntermediateElements ().object_models;
00155 float average_model_radius = object_models.getAverageModelRadius ();
00156 float support_size = support_size_factor * average_model_radius;
00157 float noise_level = noise_level_factor * average_model_radius;
00158 cout << "\n-----\n"
00159 << "The average object model radius is "<<average_model_radius<<"m.\n"
00160 << " => using support size "<<support_size<<"m.\n"
00161 << " => using noise level "<<noise_level<<"m.\n"
00162 << "-----\n\n";
00163 orh_params.support_size = support_size;
00164 orh_params.noise_level = noise_level;
00165
00166
00167 ros::Publisher pub = nh.advertise<ObjectModel::PointCloudType> ("points2", 1);
00168 ros::Publisher pub2 = nh.advertise<PointCloud<PointXYZ> > ("office_scene", 1);
00169
00170 ros::Subscriber hearCamera;
00171 hearCamera = nh.subscribe<pcl::PointCloud<pcl::PointXYZ> >("cloud_in", 1, boost::bind(callback, _1, pub, pub2));
00172
00173 ros::spin();
00174
00175 }
00176 else ROS_ERROR("There is no model existing");
00177 }
00178
00179