Go to the documentation of this file.00001
00002
00003 #include <iostream>
00004
00005 #include <boost/thread/thread.hpp>
00006 #include <pcl/range_image/range_image.h>
00007 #include <pcl/io/pcd_io.h>
00008 #include <pcl/visualization/range_image_visualizer.h>
00009 #include <pcl/visualization/pcl_visualizer.h>
00010 #include <pcl/features/range_image_border_extractor.h>
00011 #include <pcl/keypoints/narf_keypoint.h>
00012 #include <pcl/console/parse.h>
00013
00014 typedef pcl::PointXYZ PointType;
00015
00016
00017
00018
00019 float angular_resolution = 0.5f;
00020 float support_size = 0.2f;
00021 pcl::RangeImage::CoordinateFrame coordinate_frame = pcl::RangeImage::CAMERA_FRAME;
00022 bool setUnseenToMaxRange = false;
00023
00024
00025
00026
00027 void
00028 printUsage (const char* progName)
00029 {
00030 std::cout << "\n\nUsage: "<<progName<<" [options] <scene.pcd>\n\n"
00031 << "Options:\n"
00032 << "-------------------------------------------\n"
00033 << "-r <float> angular resolution in degrees (default "<<angular_resolution<<")\n"
00034 << "-c <int> coordinate frame (default "<< (int)coordinate_frame<<")\n"
00035 << "-m Treat all unseen points as maximum range readings\n"
00036 << "-s <float> support size for the interest points (diameter of the used sphere - "
00037 << "default "<<support_size<<")\n"
00038 << "-h this help\n"
00039 << "\n\n";
00040 }
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056 int
00057 main (int argc, char** argv)
00058 {
00059
00060
00061
00062 if (pcl::console::find_argument (argc, argv, "-h") >= 0)
00063 {
00064 printUsage (argv[0]);
00065 return 0;
00066 }
00067 if (pcl::console::find_argument (argc, argv, "-m") >= 0)
00068 {
00069 setUnseenToMaxRange = true;
00070 cout << "Setting unseen values in range image to maximum range readings.\n";
00071 }
00072 int tmp_coordinate_frame;
00073 if (pcl::console::parse (argc, argv, "-c", tmp_coordinate_frame) >= 0)
00074 {
00075 coordinate_frame = pcl::RangeImage::CoordinateFrame (tmp_coordinate_frame);
00076 cout << "Using coordinate frame "<< (int)coordinate_frame<<".\n";
00077 }
00078 if (pcl::console::parse (argc, argv, "-s", support_size) >= 0)
00079 cout << "Setting support size to "<<support_size<<".\n";
00080 if (pcl::console::parse (argc, argv, "-r", angular_resolution) >= 0)
00081 cout << "Setting angular resolution to "<<angular_resolution<<"deg.\n";
00082 angular_resolution = pcl::deg2rad (angular_resolution);
00083
00084
00085
00086
00087 pcl::PointCloud<PointType>::Ptr point_cloud_ptr (new pcl::PointCloud<PointType>);
00088 pcl::PointCloud<PointType>& point_cloud = *point_cloud_ptr;
00089 pcl::PointCloud<pcl::PointWithViewpoint> far_ranges;
00090 Eigen::Affine3f scene_sensor_pose (Eigen::Affine3f::Identity ());
00091 std::vector<int> pcd_filename_indices = pcl::console::parse_file_extension_argument (argc, argv, "pcd");
00092 if (!pcd_filename_indices.empty ())
00093 {
00094 std::string filename = argv[pcd_filename_indices[0]];
00095 if (pcl::io::loadPCDFile (filename, point_cloud) == -1)
00096 {
00097 cerr << "Was not able to open file \""<<filename<<"\".\n";
00098 printUsage (argv[0]);
00099 return 0;
00100 }
00101 scene_sensor_pose = Eigen::Affine3f (Eigen::Translation3f (point_cloud.sensor_origin_[0],
00102 point_cloud.sensor_origin_[1],
00103 point_cloud.sensor_origin_[2])) *
00104 Eigen::Affine3f (point_cloud.sensor_orientation_);
00105 std::string far_ranges_filename = pcl::getFilenameWithoutExtension (filename)+"_far_ranges.pcd";
00106 if (pcl::io::loadPCDFile (far_ranges_filename.c_str (), far_ranges) == -1)
00107 std::cout << "Far ranges file \""<<far_ranges_filename<<"\" does not exists.\n";
00108 }
00109 else
00110 {
00111 setUnseenToMaxRange = true;
00112 cout << "\nNo *.pcd file given => Genarating example point cloud.\n\n";
00113 for (float x=-0.5f; x<=0.5f; x+=0.01f)
00114 {
00115 for (float y=-0.5f; y<=0.5f; y+=0.01f)
00116 {
00117 PointType point; point.x = x; point.y = y; point.z = 2.0f - y;
00118 point_cloud.points.push_back (point);
00119 }
00120 }
00121 point_cloud.width = (int) point_cloud.points.size (); point_cloud.height = 1;
00122 }
00123
00124
00125
00126
00127 float noise_level = 0.0;
00128 float min_range = 0.0f;
00129 int border_size = 1;
00130 boost::shared_ptr<pcl::RangeImage> range_image_ptr (new pcl::RangeImage);
00131 pcl::RangeImage& range_image = *range_image_ptr;
00132 range_image.createFromPointCloud (point_cloud, angular_resolution, pcl::deg2rad (360.0f), pcl::deg2rad (180.0f),
00133 scene_sensor_pose, coordinate_frame, noise_level, min_range, border_size);
00134 range_image.integrateFarRanges (far_ranges);
00135 if (setUnseenToMaxRange)
00136 range_image.setUnseenToMaxRange ();
00137
00138
00139
00140
00141 pcl::visualization::PCLVisualizer viewer ("3D Viewer");
00142 viewer.setBackgroundColor (1, 1, 1);
00143 pcl::visualization::PointCloudColorHandlerCustom<pcl::PointWithRange> range_image_color_handler (range_image_ptr, 0, 0, 0);
00144 viewer.addPointCloud (range_image_ptr, range_image_color_handler, "range image");
00145 viewer.setPointCloudRenderingProperties (pcl::visualization::PCL_VISUALIZER_POINT_SIZE, 1, "range image");
00146
00147
00148
00149 viewer.initCameraParameters ();
00150
00151
00152
00153
00154
00155 pcl::visualization::RangeImageVisualizer range_image_widget ("Range image");
00156 range_image_widget.showRangeImage (range_image);
00157
00158
00159
00160
00161 pcl::RangeImageBorderExtractor range_image_border_extractor;
00162 pcl::NarfKeypoint narf_keypoint_detector (&range_image_border_extractor);
00163 narf_keypoint_detector.setRangeImage (&range_image);
00164 narf_keypoint_detector.getParameters ().support_size = support_size;
00165
00166
00167
00168 pcl::PointCloud<int> keypoint_indices;
00169 narf_keypoint_detector.compute (keypoint_indices);
00170 std::cout << "Found "<<keypoint_indices.points.size ()<<" key points.\n";
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182 pcl::PointCloud<pcl::PointXYZ>::Ptr keypoints_ptr (new pcl::PointCloud<pcl::PointXYZ>);
00183 pcl::PointCloud<pcl::PointXYZ>& keypoints = *keypoints_ptr;
00184 keypoints.points.resize (keypoint_indices.points.size ());
00185 for (size_t i=0; i<keypoint_indices.points.size (); ++i)
00186 keypoints.points[i].getVector3fMap () = range_image.points[keypoint_indices.points[i]].getVector3fMap ();
00187
00188 pcl::visualization::PointCloudColorHandlerCustom<pcl::PointXYZ> keypoints_color_handler (keypoints_ptr, 0, 255, 0);
00189 viewer.addPointCloud<pcl::PointXYZ> (keypoints_ptr, keypoints_color_handler, "keypoints");
00190 viewer.setPointCloudRenderingProperties (pcl::visualization::PCL_VISUALIZER_POINT_SIZE, 7, "keypoints");
00191
00192
00193
00194
00195 while (!viewer.wasStopped ())
00196 {
00197 range_image_widget.spinOnce ();
00198 viewer.spinOnce ();
00199 pcl_sleep(0.01);
00200 }
00201 }