Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 #include <pcl/point_cloud.h>
00039 #include <pcl/point_types.h>
00040 #include <pcl/io/pcd_io.h>
00041 #include <pcl/console/print.h>
00042 #include <pcl/console/parse.h>
00043 #include <pcl/console/time.h>
00044
00045 #include <pcl/recognition/linemod.h>
00046 #include <pcl/recognition/color_gradient_modality.h>
00047 #include <pcl/recognition/surface_normal_modality.h>
00048
00049
00050
00051 using namespace pcl;
00052 using namespace pcl::io;
00053 using namespace pcl::console;
00054
00055 typedef pcl::PointCloud<pcl::PointXYZRGBA> PointCloudXYZRGBA;
00056
00057 void
00058 printHelp (int, char **argv)
00059 {
00060 print_error ("Syntax is: %s input_cloud.pcd input_template.lmt\n", argv[0]);
00061 }
00062
00063 void printElapsedTimeAndNumberOfPoints (double t, int w, int h=1)
00064 {
00065 print_info ("[done, "); print_value ("%g", t); print_info (" ms : ");
00066 print_value ("%d", w*h); print_info (" points]\n");
00067 }
00068
00069 bool
00070 loadCloud (const std::string & filename, PointCloudXYZRGBA & cloud)
00071 {
00072 TicToc tt;
00073 print_highlight ("Loading "); print_value ("%s ", filename.c_str ());
00074
00075 tt.tic ();
00076 if (loadPCDFile (filename, cloud) < 0)
00077 return (false);
00078
00079 printElapsedTimeAndNumberOfPoints (tt.toc (), cloud.width, cloud.height);
00080
00081 print_info ("Available dimensions: "); print_value ("%s\n", pcl::getFieldsList (cloud).c_str ());
00082
00083 return (true);
00084 }
00085
00086 std::vector<pcl::LINEMODDetection>
00087 matchTemplates (const PointCloudXYZRGBA::ConstPtr & input, const pcl::LINEMOD & linemod)
00088 {
00089 pcl::ColorGradientModality<pcl::PointXYZRGBA> color_grad_mod;
00090 color_grad_mod.setInputCloud (input);
00091 color_grad_mod.processInputData ();
00092
00093 pcl::SurfaceNormalModality<pcl::PointXYZRGBA> surface_norm_mod;
00094 surface_norm_mod.setInputCloud (input);
00095 surface_norm_mod.processInputData ();
00096
00097 std::vector<pcl::QuantizableModality*> modalities (2);
00098 modalities[0] = &color_grad_mod;
00099 modalities[1] = &surface_norm_mod;
00100
00101 std::vector<pcl::LINEMODDetection> detections;
00102 linemod.matchTemplates (modalities, detections);
00103
00104 return (detections);
00105 }
00106
00107 void
00108 compute (const PointCloudXYZRGBA::ConstPtr & input, const char * templates_filename)
00109 {
00110 pcl::LINEMOD linemod;
00111
00112
00113 linemod.loadTemplates (templates_filename);
00114
00115
00116 std::vector<pcl::LINEMODDetection> detections = matchTemplates (input, linemod);
00117
00118
00119 for (size_t i = 0; i < detections.size (); ++i)
00120 {
00121 const LINEMODDetection & d = detections[i];
00122 printf ("%zu: %d %d %d %f\n", i, d.x, d.y, d.template_id, d.score);
00123 }
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159 }
00160
00161
00162 int
00163 main (int argc, char** argv)
00164 {
00165 print_info ("Match a LINE-MOD template to an organized point cloud. For more information, use: %s -h\n", argv[0]);
00166
00167 if (argc < 2)
00168 {
00169 printHelp (argc, argv);
00170 return (-1);
00171 }
00172
00173
00174 PointCloudXYZRGBA::Ptr cloud (new PointCloudXYZRGBA);
00175 if (!loadCloud (argv[1], *cloud))
00176 return (-1);
00177
00178
00179 compute (cloud, argv[2]);
00180
00181 }
00182