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)
80 feature_window_width_ = width;
81 feature_window_height_ = height;
91 const std::size_t num_of_features,
94 features.resize(num_of_features);
95 for (std::size_t feature_index = 0; feature_index < num_of_features;
98 feature_window_width_ / 2,
99 -feature_window_height_ / 2,
100 feature_window_height_ / 2);
102 feature_window_width_ / 2,
103 -feature_window_height_ / 2,
104 feature_window_height_ / 2);
105 features[feature_index].channel =
static_cast<unsigned char>(
106 NUM_OF_CHANNELS * (
static_cast<float>(rand()) / (RAND_MAX + 1)));
122 std::vector<MultipleData2DExampleIndex>& examples,
123 std::vector<float>& results,
124 std::vector<unsigned char>& flags)
const 126 results.resize(examples.size());
127 flags.resize(examples.size());
128 for (
int example_index = 0; example_index < examples.size(); ++example_index) {
132 feature, data_set, example, results[example_index], flags[example_index]);
150 unsigned char& flag)
const 152 const int center_col_index = example.
x;
153 const int center_row_index = example.
y;
155 const std::size_t p1_col =
156 static_cast<std::size_t
>(feature.
p1.x + center_col_index);
157 const std::size_t p1_row =
158 static_cast<std::size_t
>(feature.
p1.y + center_row_index);
160 const std::size_t p2_col =
161 static_cast<std::size_t
>(feature.
p2.x + center_col_index);
162 const std::size_t p2_row =
163 static_cast<std::size_t
>(feature.
p2.y + center_row_index);
165 const unsigned char channel = feature.
channel;
168 static_cast<float>(data_set(example.
data_set_id, p1_col, p1_row)[channel]);
170 static_cast<float>(data_set(example.
data_set_id, p2_col, p2_row)[channel]);
172 result = value1 - value2;
173 flag = (std::isfinite(value1) && std::isfinite(value2)) ? 0 : 1;
183 std::ostream& stream)
const 185 stream <<
"ERROR: RegressionVarianceStatsEstimator does not implement " 186 "generateCodeForBranchIndex(...)";
197 int feature_window_width_;
199 int feature_window_height_;
204 template <
class DATA_TYPE,
205 std::size_t NUM_OF_CHANNELS,
206 std::size_t SCALE_CHANNEL,
210 pcl::MultiChannel2DDataSet<DATA_TYPE, NUM_OF_CHANNELS>,
211 pcl::MultipleData2DExampleIndex> {
216 const int feature_window_height)
217 : feature_window_width_(feature_window_width)
218 , feature_window_height_(feature_window_height)
232 feature_window_width_ = width;
233 feature_window_height_ = height;
243 const std::size_t num_of_features,
246 features.resize(num_of_features);
247 for (std::size_t feature_index = 0; feature_index < num_of_features;
250 feature_window_width_ / 2,
251 -feature_window_height_ / 2,
252 feature_window_height_ / 2);
254 feature_window_width_ / 2,
255 -feature_window_height_ / 2,
256 feature_window_height_ / 2);
257 features[feature_index].channel =
static_cast<unsigned char>(
258 NUM_OF_CHANNELS * (
static_cast<float>(rand()) / (RAND_MAX + 1)));
274 std::vector<MultipleData2DExampleIndex>& examples,
275 std::vector<float>& results,
276 std::vector<unsigned char>& flags)
const 278 results.resize(examples.size());
279 flags.resize(examples.size());
280 for (
int example_index = 0; example_index < examples.size(); ++example_index) {
284 feature, data_set, example, results[example_index], flags[example_index]);
302 unsigned char& flag)
const 304 const int center_col_index = example.
x;
305 const int center_row_index = example.
y;
309 scale = 1.0f /
static_cast<float>(data_set(example.
data_set_id,
311 center_row_index)[SCALE_CHANNEL]);
313 scale =
static_cast<float>(data_set(
314 example.
data_set_id, center_col_index, center_row_index)[SCALE_CHANNEL]);
316 const std::size_t p1_col =
317 static_cast<std::size_t
>(scale * feature.
p1.x + center_col_index);
318 const std::size_t p1_row =
319 static_cast<std::size_t
>(scale * feature.
p1.y + center_row_index);
321 const std::size_t p2_col =
322 static_cast<std::size_t
>(scale * feature.
p2.x + center_col_index);
323 const std::size_t p2_row =
324 static_cast<std::size_t
>(scale * feature.
p2.y + center_row_index);
326 const unsigned char channel = feature.
channel;
329 static_cast<float>(data_set(example.
data_set_id, p1_col, p1_row)[channel]);
331 static_cast<float>(data_set(example.
data_set_id, p2_col, p2_row)[channel]);
333 result = value1 - value2;
334 flag = (std::isfinite(value1) && std::isfinite(value2)) ? 0 : 1;
344 std::ostream& stream)
const 346 stream <<
"ERROR: ScaledMultiChannel2DComparisonFeatureHandler does not implement " 347 "generateCodeForBranchIndex(...)" 366 int feature_window_width_;
368 int feature_window_height_;
371 template <
class DATA_TYPE,
372 std::size_t NUM_OF_CHANNELS,
373 std::size_t SCALE_CHANNEL,
376 :
public pcl::FeatureHandlerCodeGenerator<
377 pcl::MultiChannel2DComparisonFeature<pcl::PointXY32f>,
378 pcl::MultiChannel2DDataSet<DATA_TYPE, NUM_OF_CHANNELS>,
379 pcl::MultipleData2DExampleIndex> {
385 generateEvalFunctionCode(std::ostream& stream)
const;
389 std::ostream& stream)
const;
392 template <
class DATA_TYPE,
393 std::size_t NUM_OF_CHANNELS,
394 std::size_t SCALE_CHANNEL,
397 ScaledMultiChannel2DComparisonFeatureHandlerCCodeGenerator<
401 INVERT_SCALE>::generateEvalFunctionCode(std::ostream& stream)
const 403 if (NUM_OF_CHANNELS == 1 && SCALE_CHANNEL == 0 && INVERT_SCALE) {
404 stream <<
"const float scale = 1.0f / static_cast<float> (*data_ptr);" 406 stream <<
"" << std::endl;
407 stream <<
"struct LocalFeatureHandler" << std::endl;
408 stream <<
"{" << std::endl;
409 stream <<
" static inline void eval (" <<
typeid(DATA_TYPE).name()
410 <<
" * a_ptr, const float a_x1, const float a_y1, const float a_x2, const " 411 "float a_y2, const float a_scale, const int a_width, float & a_result, " 412 "unsigned char & a_flags)" 414 stream <<
" {" << std::endl;
415 stream <<
" a_result = *(a_ptr + static_cast<int> (a_scale*a_x1) + " 416 "(static_cast<int> (a_scale*a_y1)*a_width)) - *(a_ptr + static_cast<int> " 417 "(a_scale*a_x2) + (static_cast<int> (a_scale*a_y2)*a_width));" 419 stream <<
" }" << std::endl;
420 stream <<
"};" << std::endl;
423 stream <<
"ERROR: generateEvalFunctionCode not implemented" << std::endl;
427 template <
class DATA_TYPE,
428 std::size_t NUM_OF_CHANNELS,
429 std::size_t SCALE_CHANNEL,
437 std::ostream& stream)
const 439 stream <<
"LocalFeatureHandler::eval (data_ptr, " << feature.
p1.
x <<
", " 440 << feature.
p1.
y <<
", " << feature.
p2.
x <<
", " << feature.
p2.
y <<
", " 441 <<
"scale, width, result, flags);" << std::endl;
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.
ScaledMultiChannel2DComparisonFeatureHandler(const int feature_window_width, const int feature_window_height)
Constructor.
virtual ~MultiChannel2DComparisonFeatureHandler()
Destructor.
Feature utility class that handles the creation and evaluation of RGBD comparison features...
int data_set_id
The data set index.
virtual ~ScaledMultiChannel2DComparisonFeatureHandlerCCodeGenerator()
void generateCodeForEvaluation(const MultiChannel2DComparisonFeature< PointXY32i > &feature, std::ostream &stream) const
Generates code for feature evaluation.
virtual ~ScaledMultiChannel2DComparisonFeatureHandler()
Destructor.
Example index for a set of 2D data blocks.
void createRandomFeatures(const std::size_t num_of_features, std::vector< MultiChannel2DComparisonFeature< PointXY32f >> &features)
Creates random features.
Feature for comparing two sample points in 2D multi-channel data.
float x
The x-coordinate of the point.
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.
Define standard C methods and C++ classes that are common to all methods.
void createRandomFeatures(const std::size_t num_of_features, std::vector< MultiChannel2DComparisonFeature< PointXY32i >> &features)
Creates random features.
MultiChannel2DComparisonFeatureHandler(const int feature_window_width, const int feature_window_height)
Constructor.
ScaledMultiChannel2DComparisonFeatureHandlerCCodeGenerator()
Holds a set of two-dimensional multi-channel data.
unsigned char channel
Specifies which channel is used for comparison.
float y
The y-coordinate of the point.
void setFeatureWindowSize(int width, int height)
Sets the feature window size.
Feature utility class that handles the creation and evaluation of RGBD comparison features...
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.
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.
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.
void setFeatureWindowSize(int width, int height)
Sets the feature window size.
PointT p2
Second sample point.
void generateCodeForEvaluation(const MultiChannel2DComparisonFeature< PointXY32f > &feature, std::ostream &stream) const
Generates code for feature evaluation.
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.
Utility class interface which is used for creating and evaluating features.
PointT p1
First sample point.