38 #ifndef PCL_RECOGNITION_LINEMOD 39 #define PCL_RECOGNITION_LINEMOD 44 #include <pcl/pcl_macros.h> 45 #include <pcl/recognition/quantizable_modality.h> 46 #include <pcl/recognition/region_xy.h> 47 #include <pcl/recognition/sparse_quantized_multi_mod_template.h> 59 EnergyMaps () : width_ (0), height_ (0), nr_bins_ (0), maps_ ()
95 initialize (
const size_t width,
const size_t height,
const size_t nr_bins)
97 maps_.resize(nr_bins, NULL);
102 const size_t mapsSize = width*height;
104 for (
size_t map_index = 0; map_index < maps_.size (); ++map_index)
107 maps_[map_index] = reinterpret_cast<unsigned char*> (aligned_malloc (mapsSize));
108 memset (maps_[map_index], 0, mapsSize);
116 for (
size_t map_index = 0; map_index < maps_.size (); ++map_index)
118 if (maps_[map_index] != NULL) aligned_free (maps_[map_index]);
131 inline unsigned char &
132 operator() (
const size_t bin_index,
const size_t col_index,
const size_t row_index)
134 return (maps_[bin_index][row_index*width_ + col_index]);
141 inline unsigned char &
142 operator() (
const size_t bin_index,
const size_t index)
144 return (maps_[bin_index][index]);
150 inline unsigned char *
151 operator() (
const size_t bin_index)
153 return (maps_[bin_index]);
161 inline const unsigned char &
162 operator() (
const size_t bin_index,
const size_t col_index,
const size_t row_index)
const 164 return (maps_[bin_index][row_index*width_ + col_index]);
171 inline const unsigned char &
172 operator() (
const size_t bin_index,
const size_t index)
const 174 return (maps_[bin_index][index]);
180 inline const unsigned char *
181 operator() (
const size_t bin_index)
const 183 return (maps_[bin_index]);
194 std::vector<unsigned char*> maps_;
204 LinearizedMaps () : width_ (0), height_ (0), mem_width_ (0), mem_height_ (0), step_size_ (0), maps_ ()
235 initialize (
const size_t width,
const size_t height,
const size_t step_size)
237 maps_.resize(step_size*step_size, NULL);
240 mem_width_ = width / step_size;
241 mem_height_ = height / step_size;
242 step_size_ = step_size;
244 const size_t mapsSize = mem_width_ * mem_height_;
246 for (
size_t map_index = 0; map_index < maps_.size (); ++map_index)
249 maps_[map_index] = reinterpret_cast<unsigned char*> (aligned_malloc (2*mapsSize));
250 memset (maps_[map_index], 0, 2*mapsSize);
258 for (
size_t map_index = 0; map_index < maps_.size (); ++map_index)
260 if (maps_[map_index] != NULL) aligned_free (maps_[map_index]);
274 inline unsigned char *
275 operator() (
const size_t col_index,
const size_t row_index)
277 return (maps_[row_index*step_size_ + col_index]);
284 inline unsigned char *
287 const size_t map_col = col_index % step_size_;
288 const size_t map_row = row_index % step_size_;
290 const size_t map_mem_col_index = col_index / step_size_;
291 const size_t map_mem_row_index = row_index / step_size_;
293 return (maps_[map_row*step_size_ + map_col] + map_mem_row_index*mem_width_ + map_mem_col_index);
308 std::vector<unsigned char*> maps_;
350 createAndAddTemplate (
const std::vector<QuantizableModality*> & modalities,
351 const std::vector<MaskMap*> & masks,
365 detectTemplates (
const std::vector<QuantizableModality*> & modalities,
366 std::vector<LINEMODDetection> & detections)
const;
377 detectTemplatesSemiScaleInvariant (
const std::vector<QuantizableModality*> & modalities,
378 std::vector<LINEMODDetection> & detections,
379 float min_scale = 0.6944444f,
380 float max_scale = 1.44f,
381 float scale_multiplier = 1.2f)
const;
388 matchTemplates (
const std::vector<QuantizableModality*> & modalities,
389 std::vector<LINEMODDetection> & matches)
const;
397 template_threshold_ = threshold;
406 use_non_max_suppression_ = use_non_max_suppression;
415 average_detections_ = average_detections;
424 return (templates_[template_id]);
431 return (templates_.size ());
438 saveTemplates (
const char * file_name)
const;
444 loadTemplates (
const char * file_name);
451 loadTemplates (std::vector<std::string> & file_names);
457 serialize (std::ostream & stream)
const;
463 deserialize (std::istream & stream);
468 float template_threshold_;
470 bool use_non_max_suppression_;
472 bool average_detections_;
474 std::vector<SparseQuantizedMultiModTemplate> templates_;
virtual ~EnergyMaps()
Destructor.
Template matching using the LINEMOD approach.
float score
score of the detection.
const SparseQuantizedMultiModTemplate & getTemplate(int template_id) const
Returns the template with the specified ID.
LINEMODDetection()
Constructor.
size_t getWidth() const
Returns the width of the energy maps.
int template_id
ID of the detected template.
void initialize(const size_t width, const size_t height, const size_t nr_bins)
Initializes the set of energy maps.
void setNonMaxSuppression(bool use_non_max_suppression)
Enables/disables non-maximum suppression.
Represents a detection of a template using the LINEMOD approach.
Defines a region in XY-space.
void initialize(const size_t width, const size_t height, const size_t step_size)
Initializes the linearized map.
void setDetectionThreshold(float threshold)
Sets the detection threshold.
int y
y-position of the detection.
A multi-modality template constructed from a set of quantized multi-modality features.
size_t getNumOfBins() const
Returns the number of bins used for quantization (which is equal to the number of energy maps).
float scale
scale at which the template was detected.
Stores a set of linearized maps.
size_t getStepSize() const
Returns the step-size used to construct the linearized map.
virtual ~LinearizedMaps()
Destructor.
Stores a set of energy maps.
void releaseAll()
Releases the internal data.
size_t getNumOfTemplates() const
Returns the number of stored/trained templates.
size_t getHeight() const
Returns the height of the linearized map.
size_t getWidth() const
Returns the width of the linearized map.
size_t getMapMemorySize() const
Returns the size of the memory map.
LinearizedMaps()
Constructor.
int x
x-position of the detection.
unsigned char * getOffsetMap(const size_t col_index, const size_t row_index)
Returns a linearized map starting at the specified position.
void setDetectionAveraging(bool average_detections)
Enables/disables averaging of close detections.
void releaseAll()
Releases the internal memory.
size_t getHeight() const
Returns the height of the energy maps.