44 #include <pcl/recognition/quantizable_modality.h>
45 #include <pcl/recognition/region_xy.h>
46 #include <pcl/recognition/sparse_quantized_multi_mod_template.h>
92 initialize (
const std::size_t width,
const std::size_t height,
const std::size_t nr_bins)
94 maps_.resize(nr_bins,
nullptr);
99 const std::size_t mapsSize = width*height;
101 for (
auto &map : maps_)
104 map =
reinterpret_cast<unsigned char*
> (
aligned_malloc (mapsSize));
105 std::fill_n(map, mapsSize, 0);
113 for (
auto &map : maps_)
128 inline unsigned char &
129 operator() (
const std::size_t bin_index,
const std::size_t col_index,
const std::size_t row_index)
131 return (maps_[bin_index][row_index*width_ + col_index]);
138 inline unsigned char &
139 operator() (
const std::size_t bin_index,
const std::size_t index)
141 return (maps_[bin_index][index]);
147 inline unsigned char *
148 operator() (
const std::size_t bin_index)
150 return (maps_[bin_index]);
158 inline const unsigned char &
159 operator() (
const std::size_t bin_index,
const std::size_t col_index,
const std::size_t row_index)
const
161 return (maps_[bin_index][row_index*width_ + col_index]);
168 inline const unsigned char &
169 operator() (
const std::size_t bin_index,
const std::size_t index)
const
171 return (maps_[bin_index][index]);
177 inline const unsigned char *
178 operator() (
const std::size_t bin_index)
const
180 return (maps_[bin_index]);
189 std::size_t nr_bins_;
191 std::vector<unsigned char*> maps_;
201 LinearizedMaps () : width_ (0), height_ (0), mem_width_ (0), mem_height_ (0), step_size_ (0)
230 initialize (
const std::size_t width,
const std::size_t height,
const std::size_t step_size)
232 maps_.resize(step_size*step_size,
nullptr);
235 mem_width_ = width / step_size;
236 mem_height_ = height / step_size;
237 step_size_ = step_size;
239 const std::size_t mapsSize = mem_width_ * mem_height_;
241 for (
auto &map : maps_)
244 map =
reinterpret_cast<unsigned char*
> (
aligned_malloc (2*mapsSize));
245 std::fill_n(map, 2*mapsSize, 0);
253 for (
auto &map : maps_)
269 inline unsigned char *
270 operator() (
const std::size_t col_index,
const std::size_t row_index)
272 return (maps_[row_index*step_size_ + col_index]);
279 inline unsigned char *
280 getOffsetMap (
const std::size_t col_index,
const std::size_t row_index)
282 const std::size_t map_col = col_index % step_size_;
283 const std::size_t map_row = row_index % step_size_;
285 const std::size_t map_mem_col_index = col_index / step_size_;
286 const std::size_t map_mem_row_index = row_index / step_size_;
288 return (maps_[map_row*step_size_ + map_col] + map_mem_row_index*mem_width_ + map_mem_col_index);
297 std::size_t mem_width_;
299 std::size_t mem_height_;
301 std::size_t step_size_;
303 std::vector<unsigned char*> maps_;
347 const std::vector<MaskMap*> & masks,
362 std::vector<LINEMODDetection> & detections)
const;
374 std::vector<LINEMODDetection> & detections,
375 float min_scale = 0.6944444f,
376 float max_scale = 1.44f,
377 float scale_multiplier = 1.2f)
const;
385 std::vector<LINEMODDetection> & matches)
const;
393 template_threshold_ = threshold;
402 use_non_max_suppression_ = use_non_max_suppression;
411 average_detections_ = average_detections;
420 return (templates_[template_id]);
427 return (templates_.size ());
464 float template_threshold_;
466 bool use_non_max_suppression_;
468 bool average_detections_;
470 std::vector<SparseQuantizedMultiModTemplate> templates_;
Stores a set of energy maps.
std::size_t getNumOfBins() const
Returns the number of bins used for quantization (which is equal to the number of energy maps).
virtual ~EnergyMaps()=default
Destructor.
void releaseAll()
Releases the internal data.
void initialize(const std::size_t width, const std::size_t height, const std::size_t nr_bins)
Initializes the set of energy maps.
std::size_t getWidth() const
Returns the width of the energy maps.
std::size_t getHeight() const
Returns the height of the energy maps.
Template matching using the LINEMOD approach.
void deserialize(std::istream &stream)
Deserializes templates from the specified stream.
void saveTemplates(const char *file_name) const
Saves the stored templates to the specified file.
void detectTemplatesSemiScaleInvariant(const std::vector< QuantizableModality * > &modalities, std::vector< LINEMODDetection > &detections, float min_scale=0.6944444f, float max_scale=1.44f, float scale_multiplier=1.2f) const
Detects the stored templates in a semi scale invariant manner by applying the detection to multiple s...
const SparseQuantizedMultiModTemplate & getTemplate(int template_id) const
Returns the template with the specified ID.
void matchTemplates(const std::vector< QuantizableModality * > &modalities, std::vector< LINEMODDetection > &matches) const
Matches the stored templates to the supplied modality data.
std::size_t getNumOfTemplates() const
Returns the number of stored/trained templates.
void setDetectionThreshold(float threshold)
Sets the detection threshold.
void setDetectionAveraging(bool average_detections)
Enables/disables averaging of close detections.
virtual ~LINEMOD()
Destructor.
void serialize(std::ostream &stream) const
Serializes the stored templates to the specified stream.
void detectTemplates(const std::vector< QuantizableModality * > &modalities, std::vector< LINEMODDetection > &detections) const
Detects the stored templates in the supplied modality data.
void loadTemplates(std::vector< std::string > &file_names)
Loads templates from the specified files.
void setNonMaxSuppression(bool use_non_max_suppression)
Enables/disables non-maximum suppression.
int addTemplate(const SparseQuantizedMultiModTemplate &linemod_template)
Adds the specified template to the matching queue.
int createAndAddTemplate(const std::vector< QuantizableModality * > &modalities, const std::vector< MaskMap * > &masks, const RegionXY ®ion)
Creates a template from the specified data and adds it to the matching queue.
void loadTemplates(const char *file_name)
Loads templates from the specified file.
Stores a set of linearized maps.
std::size_t getHeight() const
Returns the height of the linearized map.
void initialize(const std::size_t width, const std::size_t height, const std::size_t step_size)
Initializes the linearized map.
LinearizedMaps()
Constructor.
virtual ~LinearizedMaps()=default
Destructor.
unsigned char * getOffsetMap(const std::size_t col_index, const std::size_t row_index)
Returns a linearized map starting at the specified position.
void releaseAll()
Releases the internal memory.
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 getMapMemorySize() const
Returns the size of the memory map.
void aligned_free(void *ptr)
void * aligned_malloc(std::size_t size)
Defines all the PCL and non-PCL macros used.
Represents a detection of a template using the LINEMOD approach.
LINEMODDetection()
Constructor.
int template_id
ID of the detected template.
int y
y-position of the detection.
float scale
scale at which the template was detected.
float score
score of the detection.
int x
x-position of the detection.
Defines a region in XY-space.
A multi-modality template constructed from a set of quantized multi-modality features.