41 #include <pcl/ml/feature_handler.h>
42 #include <pcl/ml/multi_channel_2d_comparison_feature.h>
43 #include <pcl/ml/multi_channel_2d_data_set.h>
44 #include <pcl/ml/multiple_data_2d_example_index.h>
45 #include <pcl/ml/point_xy_32f.h>
46 #include <pcl/ml/point_xy_32i.h>
55 template <
class DATA_TYPE, std::
size_t NUM_OF_CHANNELS>
58 pcl::MultiChannel2DDataSet<DATA_TYPE, NUM_OF_CHANNELS>,
59 pcl::MultipleData2DExampleIndex> {
64 const int feature_window_height)
65 : feature_window_width_(feature_window_width)
66 , feature_window_height_(feature_window_height)
77 feature_window_width_ = width;
78 feature_window_height_ = height;
88 const std::size_t num_of_features,
91 features.resize(num_of_features);
92 for (std::size_t feature_index = 0; feature_index < num_of_features;
95 feature_window_width_ / 2,
96 -feature_window_height_ / 2,
97 feature_window_height_ / 2);
99 feature_window_width_ / 2,
100 -feature_window_height_ / 2,
101 feature_window_height_ / 2);
102 features[feature_index].channel =
static_cast<unsigned char>(
103 NUM_OF_CHANNELS * (
static_cast<float>(rand()) / (RAND_MAX + 1)));
119 std::vector<MultipleData2DExampleIndex>& examples,
120 std::vector<float>& results,
121 std::vector<unsigned char>& flags)
const
123 results.resize(examples.size());
124 flags.resize(examples.size());
125 for (
int example_index = 0; example_index < examples.size(); ++example_index) {
129 feature, data_set, example, results[example_index], flags[example_index]);
147 unsigned char& flag)
const
149 const int center_col_index = example.
x;
150 const int center_row_index = example.
y;
152 const std::size_t p1_col =
153 static_cast<std::size_t
>(feature.
p1.x + center_col_index);
154 const std::size_t p1_row =
155 static_cast<std::size_t
>(feature.
p1.y + center_row_index);
157 const std::size_t p2_col =
158 static_cast<std::size_t
>(feature.
p2.x + center_col_index);
159 const std::size_t p2_row =
160 static_cast<std::size_t
>(feature.
p2.y + center_row_index);
162 const unsigned char channel = feature.
channel;
165 static_cast<float>(data_set(example.
data_set_id, p1_col, p1_row)[channel]);
167 static_cast<float>(data_set(example.
data_set_id, p2_col, p2_row)[channel]);
169 result = value1 - value2;
170 flag = (std::isfinite(value1) && std::isfinite(value2)) ? 0 : 1;
180 std::ostream& stream)
const
182 stream <<
"ERROR: RegressionVarianceStatsEstimator does not implement "
183 "generateCodeForBranchIndex(...)";
194 int feature_window_width_;
196 int feature_window_height_;
201 template <
class DATA_TYPE,
202 std::size_t NUM_OF_CHANNELS,
203 std::size_t SCALE_CHANNEL,
207 pcl::MultiChannel2DDataSet<DATA_TYPE, NUM_OF_CHANNELS>,
208 pcl::MultipleData2DExampleIndex> {
213 const int feature_window_height)
214 : feature_window_width_(feature_window_width)
215 , feature_window_height_(feature_window_height)
226 feature_window_width_ = width;
227 feature_window_height_ = height;
237 const std::size_t num_of_features,
240 features.resize(num_of_features);
241 for (std::size_t feature_index = 0; feature_index < num_of_features;
244 feature_window_width_ / 2,
245 -feature_window_height_ / 2,
246 feature_window_height_ / 2);
248 feature_window_width_ / 2,
249 -feature_window_height_ / 2,
250 feature_window_height_ / 2);
251 features[feature_index].channel =
static_cast<unsigned char>(
252 NUM_OF_CHANNELS * (
static_cast<float>(rand()) / (RAND_MAX + 1)));
268 std::vector<MultipleData2DExampleIndex>& examples,
269 std::vector<float>& results,
270 std::vector<unsigned char>& flags)
const
272 results.resize(examples.size());
273 flags.resize(examples.size());
274 for (
int example_index = 0; example_index < examples.size(); ++example_index) {
278 feature, data_set, example, results[example_index], flags[example_index]);
296 unsigned char& flag)
const
298 const int center_col_index = example.
x;
299 const int center_row_index = example.
y;
303 scale = 1.0f /
static_cast<float>(data_set(example.
data_set_id,
305 center_row_index)[SCALE_CHANNEL]);
307 scale =
static_cast<float>(data_set(
308 example.
data_set_id, center_col_index, center_row_index)[SCALE_CHANNEL]);
310 const std::size_t p1_col =
311 static_cast<std::size_t
>(scale * feature.
p1.x + center_col_index);
312 const std::size_t p1_row =
313 static_cast<std::size_t
>(scale * feature.
p1.y + center_row_index);
315 const std::size_t p2_col =
316 static_cast<std::size_t
>(scale * feature.
p2.x + center_col_index);
317 const std::size_t p2_row =
318 static_cast<std::size_t
>(scale * feature.
p2.y + center_row_index);
320 const unsigned char channel = feature.
channel;
323 static_cast<float>(data_set(example.
data_set_id, p1_col, p1_row)[channel]);
325 static_cast<float>(data_set(example.
data_set_id, p2_col, p2_row)[channel]);
327 result = value1 - value2;
328 flag = (std::isfinite(value1) && std::isfinite(value2)) ? 0 : 1;
338 std::ostream& stream)
const
340 stream <<
"ERROR: ScaledMultiChannel2DComparisonFeatureHandler does not implement "
341 "generateCodeForBranchIndex(...)"
360 int feature_window_width_;
362 int feature_window_height_;
365 template <
class DATA_TYPE,
366 std::size_t NUM_OF_CHANNELS,
367 std::size_t SCALE_CHANNEL,
370 :
public pcl::FeatureHandlerCodeGenerator<
371 pcl::MultiChannel2DComparisonFeature<pcl::PointXY32f>,
372 pcl::MultiChannel2DDataSet<DATA_TYPE, NUM_OF_CHANNELS>,
373 pcl::MultipleData2DExampleIndex> {
378 generateEvalFunctionCode(std::ostream& stream)
const;
382 std::ostream& stream)
const;
385 template <
class DATA_TYPE,
386 std::size_t NUM_OF_CHANNELS,
387 std::size_t SCALE_CHANNEL,
390 ScaledMultiChannel2DComparisonFeatureHandlerCCodeGenerator<
394 INVERT_SCALE>::generateEvalFunctionCode(std::ostream& stream)
const
396 if (NUM_OF_CHANNELS == 1 && SCALE_CHANNEL == 0 && INVERT_SCALE) {
397 stream <<
"const float scale = 1.0f / static_cast<float> (*data_ptr);"
399 stream <<
"" << std::endl;
400 stream <<
"struct LocalFeatureHandler" << std::endl;
401 stream <<
"{" << std::endl;
402 stream <<
" static inline void eval (" <<
typeid(DATA_TYPE).name()
403 <<
" * a_ptr, const float a_x1, const float a_y1, const float a_x2, const "
404 "float a_y2, const float a_scale, const int a_width, float & a_result, "
405 "unsigned char & a_flags)"
407 stream <<
" {" << std::endl;
408 stream <<
" a_result = *(a_ptr + static_cast<int> (a_scale*a_x1) + "
409 "(static_cast<int> (a_scale*a_y1)*a_width)) - *(a_ptr + static_cast<int> "
410 "(a_scale*a_x2) + (static_cast<int> (a_scale*a_y2)*a_width));"
412 stream <<
" }" << std::endl;
413 stream <<
"};" << std::endl;
416 stream <<
"ERROR: generateEvalFunctionCode not implemented" << std::endl;
420 template <
class DATA_TYPE,
421 std::size_t NUM_OF_CHANNELS,
422 std::size_t SCALE_CHANNEL,
430 std::ostream& stream)
const
432 stream <<
"LocalFeatureHandler::eval (data_ptr, " << feature.
p1.x <<
", "
433 << feature.
p1.y <<
", " << feature.
p2.x <<
", " << feature.
p2.y <<
", "
434 <<
"scale, width, result, flags);" << std::endl;
Utility class interface which is used for creating and evaluating features.
Feature utility class that handles the creation and evaluation of RGBD comparison features.
void evaluateFeature(const MultiChannel2DComparisonFeature< PointXY32i > &feature, MultiChannel2DDataSet< DATA_TYPE, NUM_OF_CHANNELS > &data_set, std::vector< MultipleData2DExampleIndex > &examples, std::vector< float > &results, std::vector< unsigned char > &flags) const
Evaluates a feature for a set of examples on the specified data set.
void setFeatureWindowSize(int width, int height)
Sets the feature window size.
void createRandomFeatures(const std::size_t num_of_features, std::vector< MultiChannel2DComparisonFeature< PointXY32i >> &features)
Creates random features.
void evaluateFeature(const MultiChannel2DComparisonFeature< PointXY32i > &feature, MultiChannel2DDataSet< DATA_TYPE, NUM_OF_CHANNELS > &data_set, const MultipleData2DExampleIndex &example, float &result, unsigned char &flag) const
Evaluates a feature for one examples on the specified data set.
MultiChannel2DComparisonFeatureHandler(const int feature_window_width, const int feature_window_height)
Constructor.
void generateCodeForEvaluation(const MultiChannel2DComparisonFeature< PointXY32i > &feature, std::ostream &stream) const
Generates code for feature evaluation.
Feature for comparing two sample points in 2D multi-channel data.
unsigned char channel
Specifies which channel is used for comparison.
PointT p2
Second sample point.
PointT p1
First sample point.
Holds a set of two-dimensional multi-channel data.
static PointXY32f randomPoint(const int min_x, const int max_x, const int min_y, const int max_y)
Creates a random point within the specified window.
static PointXY32i randomPoint(const int min_x, const int max_x, const int min_y, const int max_y)
Creates a random point within the specified window.
ScaledMultiChannel2DComparisonFeatureHandlerCCodeGenerator()
Feature utility class that handles the creation and evaluation of RGBD comparison features.
void evaluateFeature(const MultiChannel2DComparisonFeature< PointXY32f > &feature, MultiChannel2DDataSet< DATA_TYPE, NUM_OF_CHANNELS > &data_set, std::vector< MultipleData2DExampleIndex > &examples, std::vector< float > &results, std::vector< unsigned char > &flags) const
Evaluates a feature for a set of examples on the specified data set.
void evaluateFeature(const MultiChannel2DComparisonFeature< PointXY32f > &feature, MultiChannel2DDataSet< DATA_TYPE, NUM_OF_CHANNELS > &data_set, const MultipleData2DExampleIndex &example, float &result, unsigned char &flag) const
Evaluates a feature for one examples on the specified data set.
void generateCodeForEvaluation(const MultiChannel2DComparisonFeature< PointXY32f > &feature, std::ostream &stream) const
Generates code for feature evaluation.
void createRandomFeatures(const std::size_t num_of_features, std::vector< MultiChannel2DComparisonFeature< PointXY32f >> &features)
Creates random features.
void setFeatureWindowSize(int width, int height)
Sets the feature window size.
ScaledMultiChannel2DComparisonFeatureHandler(const int feature_window_width, const int feature_window_height)
Constructor.
Define standard C methods and C++ classes that are common to all methods.
Example index for a set of 2D data blocks.
int data_set_id
The data set index.