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>
89 initialize (
const std::size_t width,
const std::size_t height,
const std::size_t nr_bins)
91 maps_.resize(nr_bins,
nullptr);
96 const std::size_t mapsSize = width*height;
98 for (
auto &map : maps_)
101 map =
reinterpret_cast<unsigned char*
> (
aligned_malloc (mapsSize));
102 std::fill_n(map, mapsSize, 0);
110 for (
auto &map : maps_)
125 inline unsigned char &
126 operator() (
const std::size_t bin_index,
const std::size_t col_index,
const std::size_t row_index)
128 return (maps_[bin_index][row_index*width_ + col_index]);
135 inline unsigned char &
136 operator() (
const std::size_t bin_index,
const std::size_t index)
138 return (maps_[bin_index][index]);
144 inline unsigned char *
145 operator() (
const std::size_t bin_index)
147 return (maps_[bin_index]);
155 inline const unsigned char &
156 operator() (
const std::size_t bin_index,
const std::size_t col_index,
const std::size_t row_index)
const
158 return (maps_[bin_index][row_index*width_ + col_index]);
165 inline const unsigned char &
166 operator() (
const std::size_t bin_index,
const std::size_t index)
const
168 return (maps_[bin_index][index]);
174 inline const unsigned char *
175 operator() (
const std::size_t bin_index)
const
177 return (maps_[bin_index]);
182 std::size_t width_{0};
184 std::size_t height_{0};
186 std::size_t nr_bins_{0};
188 std::vector<unsigned char*> maps_;
225 initialize (
const std::size_t width,
const std::size_t height,
const std::size_t step_size)
227 maps_.resize(step_size*step_size,
nullptr);
230 mem_width_ = width / step_size;
231 mem_height_ = height / step_size;
232 step_size_ = step_size;
234 const std::size_t mapsSize = mem_width_ * mem_height_;
236 for (
auto &map : maps_)
239 map =
reinterpret_cast<unsigned char*
> (
aligned_malloc (2*mapsSize));
240 std::fill_n(map, 2*mapsSize, 0);
248 for (
auto &map : maps_)
264 inline unsigned char *
265 operator() (
const std::size_t col_index,
const std::size_t row_index)
267 return (maps_[row_index*step_size_ + col_index]);
274 inline unsigned char *
275 getOffsetMap (
const std::size_t col_index,
const std::size_t row_index)
277 const std::size_t map_col = col_index % step_size_;
278 const std::size_t map_row = row_index % step_size_;
280 const std::size_t map_mem_col_index = col_index / step_size_;
281 const std::size_t map_mem_row_index = row_index / step_size_;
283 return (maps_[map_row*step_size_ + map_col] + map_mem_row_index*mem_width_ + map_mem_col_index);
288 std::size_t width_{0};
290 std::size_t height_{0};
292 std::size_t mem_width_{0};
294 std::size_t mem_height_{0};
296 std::size_t step_size_{0};
298 std::vector<unsigned char*> maps_;
341 createAndAddTemplate (
const std::vector<QuantizableModality*> & modalities,
342 const std::vector<MaskMap*> & masks,
356 detectTemplates (
const std::vector<QuantizableModality*> & modalities,
357 std::vector<LINEMODDetection> & detections)
const;
368 detectTemplatesSemiScaleInvariant (
const std::vector<QuantizableModality*> & modalities,
369 std::vector<LINEMODDetection> & detections,
370 float min_scale = 0.6944444f,
371 float max_scale = 1.44f,
372 float scale_multiplier = 1.2f)
const;
379 matchTemplates (
const std::vector<QuantizableModality*> & modalities,
380 std::vector<LINEMODDetection> & matches)
const;
388 template_threshold_ = threshold;
397 use_non_max_suppression_ = use_non_max_suppression;
406 average_detections_ = average_detections;
415 return (templates_[template_id]);
422 return (templates_.size ());
429 saveTemplates (
const char * file_name)
const;
435 loadTemplates (
const char * file_name);
442 loadTemplates (std::vector<std::string> & file_names);
448 serialize (std::ostream & stream)
const;
454 deserialize (std::istream & stream);
459 float template_threshold_{0.75f};
461 bool use_non_max_suppression_{
false};
463 bool average_detections_{
false};
465 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.
Template matching using the LINEMOD approach.
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.
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.
void aligned_free(void *ptr)
Stores a set of linearized maps.
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.
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.
void * aligned_malloc(std::size_t size)