43 #include <pcl/pcl_macros.h>
44 #include <pcl/recognition/quantizable_modality.h>
45 #include <pcl/recognition/region_xy.h>
46 #include <pcl/recognition/sparse_quantized_multi_mod_template.h>
94 initialize (
const std::size_t width,
const std::size_t height,
const std::size_t nr_bins)
96 maps_.resize(nr_bins,
nullptr);
101 const std::size_t mapsSize = width*height;
103 for (
auto &map : maps_)
106 map =
reinterpret_cast<unsigned char*
> (aligned_malloc (mapsSize));
107 memset (map, 0, mapsSize);
115 for (
auto &map : maps_)
117 if (map !=
nullptr) aligned_free (map);
130 inline unsigned char &
131 operator() (
const std::size_t bin_index,
const std::size_t col_index,
const std::size_t row_index)
133 return (maps_[bin_index][row_index*width_ + col_index]);
140 inline unsigned char &
141 operator() (
const std::size_t bin_index,
const std::size_t index)
143 return (maps_[bin_index][index]);
149 inline unsigned char *
150 operator() (
const std::size_t bin_index)
152 return (maps_[bin_index]);
160 inline const unsigned char &
161 operator() (
const std::size_t bin_index,
const std::size_t col_index,
const std::size_t row_index)
const
163 return (maps_[bin_index][row_index*width_ + col_index]);
170 inline const unsigned char &
171 operator() (
const std::size_t bin_index,
const std::size_t index)
const
173 return (maps_[bin_index][index]);
179 inline const unsigned char *
180 operator() (
const std::size_t bin_index)
const
182 return (maps_[bin_index]);
191 std::size_t nr_bins_;
193 std::vector<unsigned char*> maps_;
203 LinearizedMaps () : width_ (0), height_ (0), mem_width_ (0), mem_height_ (0), step_size_ (0)
234 initialize (
const std::size_t width,
const std::size_t height,
const std::size_t step_size)
236 maps_.resize(step_size*step_size,
nullptr);
239 mem_width_ = width / step_size;
240 mem_height_ = height / step_size;
241 step_size_ = step_size;
243 const std::size_t mapsSize = mem_width_ * mem_height_;
245 for (
auto &map : maps_)
248 map =
reinterpret_cast<unsigned char*
> (aligned_malloc (2*mapsSize));
249 memset (map, 0, 2*mapsSize);
257 for (
auto &map : maps_)
259 if (map !=
nullptr) aligned_free (map);
273 inline unsigned char *
274 operator() (
const std::size_t col_index,
const std::size_t row_index)
276 return (maps_[row_index*step_size_ + col_index]);
283 inline unsigned char *
284 getOffsetMap (
const std::size_t col_index,
const std::size_t row_index)
286 const std::size_t map_col = col_index % step_size_;
287 const std::size_t map_row = row_index % step_size_;
289 const std::size_t map_mem_col_index = col_index / step_size_;
290 const std::size_t map_mem_row_index = row_index / step_size_;
292 return (maps_[map_row*step_size_ + map_col] + map_mem_row_index*mem_width_ + map_mem_col_index);
301 std::size_t mem_width_;
303 std::size_t mem_height_;
305 std::size_t step_size_;
307 std::vector<unsigned char*> maps_;
349 createAndAddTemplate (
const std::vector<QuantizableModality*> & modalities,
350 const std::vector<MaskMap*> & masks,
364 detectTemplates (
const std::vector<QuantizableModality*> & modalities,
365 std::vector<LINEMODDetection> & detections)
const;
376 detectTemplatesSemiScaleInvariant (
const std::vector<QuantizableModality*> & modalities,
377 std::vector<LINEMODDetection> & detections,
378 float min_scale = 0.6944444f,
379 float max_scale = 1.44f,
380 float scale_multiplier = 1.2f)
const;
387 matchTemplates (
const std::vector<QuantizableModality*> & modalities,
388 std::vector<LINEMODDetection> & matches)
const;
396 template_threshold_ = threshold;
405 use_non_max_suppression_ = use_non_max_suppression;
414 average_detections_ = average_detections;
423 return (templates_[template_id]);
430 return (templates_.size ());
437 saveTemplates (
const char * file_name)
const;
443 loadTemplates (
const char * file_name);
450 loadTemplates (std::vector<std::string> & file_names);
456 serialize (std::ostream & stream)
const;
462 deserialize (std::istream & stream);
467 float template_threshold_;
469 bool use_non_max_suppression_;
471 bool average_detections_;
473 std::vector<SparseQuantizedMultiModTemplate> templates_;
void initialize(const std::size_t width, const std::size_t height, const std::size_t nr_bins)
Initializes the set of energy maps.
virtual ~EnergyMaps()
Destructor.
Template matching using the LINEMOD approach.
float score
score of the detection.
LINEMODDetection()
Constructor.
int template_id
ID of the detected template.
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 setDetectionThreshold(float threshold)
Sets the detection threshold.
unsigned char * getOffsetMap(const std::size_t col_index, const std::size_t row_index)
Returns a linearized map starting at the specified position.
int y
y-position of the detection.
A multi-modality template constructed from a set of quantized multi-modality features.
std::size_t getHeight() const
Returns the height of the energy maps.
std::size_t getMapMemorySize() const
Returns the size of the memory map.
const SparseQuantizedMultiModTemplate & getTemplate(int template_id) const
Returns the template with the specified ID.
std::size_t getStepSize() const
Returns the step-size used to construct the linearized map.
std::size_t getWidth() const
Returns the width of the linearized map.
std::size_t getWidth() const
Returns the width of the energy maps.
float scale
scale at which the template was detected.
Stores a set of linearized maps.
virtual ~LinearizedMaps()
Destructor.
Stores a set of energy maps.
void releaseAll()
Releases the internal data.
std::size_t getHeight() const
Returns the height of the linearized map.
std::size_t getNumOfBins() const
Returns the number of bins used for quantization (which is equal to the number of energy maps)...
std::size_t getNumOfTemplates() const
Returns the number of stored/trained templates.
LinearizedMaps()
Constructor.
int x
x-position of the detection.
void setDetectionAveraging(bool average_detections)
Enables/disables averaging of close detections.
void initialize(const std::size_t width, const std::size_t height, const std::size_t step_size)
Initializes the linearized map.
void releaseAll()
Releases the internal memory.