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 #ifndef PCL_RECOGNITION_LINEMOD
00039 #define PCL_RECOGNITION_LINEMOD
00040
00041 #include <vector>
00042 #include <cstddef>
00043 #include <string.h>
00044 #include <pcl/pcl_macros.h>
00045 #include <pcl/recognition/quantizable_modality.h>
00046 #include <pcl/recognition/region_xy.h>
00047 #include <pcl/recognition/sparse_quantized_multi_mod_template.h>
00048
00049 namespace pcl
00050 {
00051
00055 class PCL_EXPORTS EnergyMaps
00056 {
00057 public:
00059 EnergyMaps () : width_ (0), height_ (0), nr_bins_ (0), maps_ ()
00060 {
00061 }
00062
00064 virtual ~EnergyMaps ()
00065 {
00066 }
00067
00069 inline size_t
00070 getWidth () const
00071 {
00072 return (width_);
00073 }
00074
00076 inline size_t
00077 getHeight () const
00078 {
00079 return (height_);
00080 }
00081
00083 inline size_t
00084 getNumOfBins () const
00085 {
00086 return (nr_bins_);
00087 }
00088
00094 void
00095 initialize (const size_t width, const size_t height, const size_t nr_bins)
00096 {
00097 maps_.resize(nr_bins, NULL);
00098 width_ = width;
00099 height_ = height;
00100 nr_bins_ = nr_bins;
00101
00102 const size_t mapsSize = width*height;
00103
00104 for (size_t map_index = 0; map_index < maps_.size (); ++map_index)
00105 {
00106
00107 maps_[map_index] = reinterpret_cast<unsigned char*> (aligned_malloc (mapsSize));
00108 memset (maps_[map_index], 0, mapsSize);
00109 }
00110 }
00111
00113 void
00114 releaseAll ()
00115 {
00116 for (size_t map_index = 0; map_index < maps_.size (); ++map_index)
00117
00118 if (maps_[map_index] != NULL) aligned_free (maps_[map_index]);
00119
00120 maps_.clear ();
00121 width_ = 0;
00122 height_ = 0;
00123 nr_bins_ = 0;
00124 }
00125
00131 inline unsigned char &
00132 operator() (const size_t bin_index, const size_t col_index, const size_t row_index)
00133 {
00134 return (maps_[bin_index][row_index*width_ + col_index]);
00135 }
00136
00141 inline unsigned char &
00142 operator() (const size_t bin_index, const size_t index)
00143 {
00144 return (maps_[bin_index][index]);
00145 }
00146
00150 inline unsigned char *
00151 operator() (const size_t bin_index)
00152 {
00153 return (maps_[bin_index]);
00154 }
00155
00161 inline const unsigned char &
00162 operator() (const size_t bin_index, const size_t col_index, const size_t row_index) const
00163 {
00164 return (maps_[bin_index][row_index*width_ + col_index]);
00165 }
00166
00171 inline const unsigned char &
00172 operator() (const size_t bin_index, const size_t index) const
00173 {
00174 return (maps_[bin_index][index]);
00175 }
00176
00180 inline const unsigned char *
00181 operator() (const size_t bin_index) const
00182 {
00183 return (maps_[bin_index]);
00184 }
00185
00186 private:
00188 size_t width_;
00190 size_t height_;
00192 size_t nr_bins_;
00194 std::vector<unsigned char*> maps_;
00195 };
00196
00200 class PCL_EXPORTS LinearizedMaps
00201 {
00202 public:
00204 LinearizedMaps () : width_ (0), height_ (0), mem_width_ (0), mem_height_ (0), step_size_ (0), maps_ ()
00205 {
00206 }
00207
00209 virtual ~LinearizedMaps ()
00210 {
00211 }
00212
00214 inline size_t
00215 getWidth () const { return (width_); }
00216
00218 inline size_t
00219 getHeight () const { return (height_); }
00220
00222 inline size_t
00223 getStepSize () const { return (step_size_); }
00224
00226 inline size_t
00227 getMapMemorySize () const { return (mem_width_ * mem_height_); }
00228
00234 void
00235 initialize (const size_t width, const size_t height, const size_t step_size)
00236 {
00237 maps_.resize(step_size*step_size, NULL);
00238 width_ = width;
00239 height_ = height;
00240 mem_width_ = width / step_size;
00241 mem_height_ = height / step_size;
00242 step_size_ = step_size;
00243
00244 const size_t mapsSize = mem_width_ * mem_height_;
00245
00246 for (size_t map_index = 0; map_index < maps_.size (); ++map_index)
00247 {
00248
00249 maps_[map_index] = reinterpret_cast<unsigned char*> (aligned_malloc (2*mapsSize));
00250 memset (maps_[map_index], 0, 2*mapsSize);
00251 }
00252 }
00253
00255 void
00256 releaseAll ()
00257 {
00258 for (size_t map_index = 0; map_index < maps_.size (); ++map_index)
00259
00260 if (maps_[map_index] != NULL) aligned_free (maps_[map_index]);
00261
00262 maps_.clear ();
00263 width_ = 0;
00264 height_ = 0;
00265 mem_width_ = 0;
00266 mem_height_ = 0;
00267 step_size_ = 0;
00268 }
00269
00274 inline unsigned char *
00275 operator() (const size_t col_index, const size_t row_index)
00276 {
00277 return (maps_[row_index*step_size_ + col_index]);
00278 }
00279
00284 inline unsigned char *
00285 getOffsetMap (const size_t col_index, const size_t row_index)
00286 {
00287 const size_t map_col = col_index % step_size_;
00288 const size_t map_row = row_index % step_size_;
00289
00290 const size_t map_mem_col_index = col_index / step_size_;
00291 const size_t map_mem_row_index = row_index / step_size_;
00292
00293 return (maps_[map_row*step_size_ + map_col] + map_mem_row_index*mem_width_ + map_mem_col_index);
00294 }
00295
00296 private:
00298 size_t width_;
00300 size_t height_;
00302 size_t mem_width_;
00304 size_t mem_height_;
00306 size_t step_size_;
00308 std::vector<unsigned char*> maps_;
00309 };
00310
00314 struct PCL_EXPORTS LINEMODDetection
00315 {
00317 LINEMODDetection () : x (0), y (0), template_id (0), score (0.0f), scale (1.0f) {}
00318
00320 int x;
00322 int y;
00324 int template_id;
00326 float score;
00328 float scale;
00329 };
00330
00335 class PCL_EXPORTS LINEMOD
00336 {
00337 public:
00339 LINEMOD ();
00340
00342 virtual ~LINEMOD ();
00343
00349 int
00350 createAndAddTemplate (const std::vector<QuantizableModality*> & modalities,
00351 const std::vector<MaskMap*> & masks,
00352 const RegionXY & region);
00353
00357 int
00358 addTemplate (const SparseQuantizedMultiModTemplate & linemod_template);
00359
00364 void
00365 detectTemplates (const std::vector<QuantizableModality*> & modalities,
00366 std::vector<LINEMODDetection> & detections) const;
00367
00376 void
00377 detectTemplatesSemiScaleInvariant (const std::vector<QuantizableModality*> & modalities,
00378 std::vector<LINEMODDetection> & detections,
00379 float min_scale = 0.6944444f,
00380 float max_scale = 1.44f,
00381 float scale_multiplier = 1.2f) const;
00382
00387 void
00388 matchTemplates (const std::vector<QuantizableModality*> & modalities,
00389 std::vector<LINEMODDetection> & matches) const;
00390
00394 inline void
00395 setDetectionThreshold (float threshold)
00396 {
00397 template_threshold_ = threshold;
00398 }
00399
00403 inline void
00404 setNonMaxSuppression (bool use_non_max_suppression)
00405 {
00406 use_non_max_suppression_ = use_non_max_suppression;
00407 }
00408
00412 inline void
00413 setDetectionAveraging (bool average_detections)
00414 {
00415 average_detections_ = average_detections;
00416 }
00417
00421 inline const SparseQuantizedMultiModTemplate &
00422 getTemplate (int template_id) const
00423 {
00424 return (templates_[template_id]);
00425 }
00426
00428 inline size_t
00429 getNumOfTemplates () const
00430 {
00431 return (templates_.size ());
00432 }
00433
00437 void
00438 saveTemplates (const char * file_name) const;
00439
00443 void
00444 loadTemplates (const char * file_name);
00445
00449 void
00450 serialize (std::ostream & stream) const;
00451
00455 void
00456 deserialize (std::istream & stream);
00457
00458
00459 private:
00461 float template_threshold_;
00463 bool use_non_max_suppression_;
00465 bool average_detections_;
00467 std::vector<SparseQuantizedMultiModTemplate> templates_;
00468 };
00469
00470 }
00471
00472 #endif