38 #ifndef PCL_ML_MULTI_CHANNEL_2D_COMPARISON_FEATURE_HANDLER_H_ 39 #define PCL_ML_MULTI_CHANNEL_2D_COMPARISON_FEATURE_HANDLER_H_ 43 #include <pcl/ml/feature_handler.h> 44 #include <pcl/ml/multi_channel_2d_data_set.h> 45 #include <pcl/ml/multi_channel_2d_comparison_feature.h> 46 #include <pcl/ml/multiple_data_2d_example_index.h> 47 #include <pcl/ml/point_xy_32i.h> 48 #include <pcl/ml/point_xy_32f.h> 57 template <
class DATA_TYPE,
size_t NUM_OF_CHANNELS>
59 :
public pcl::FeatureHandler<pcl::MultiChannel2DComparisonFeature<pcl::PointXY32i>, pcl::MultiChannel2DDataSet<DATA_TYPE, NUM_OF_CHANNELS>, pcl::MultipleData2DExampleIndex>
66 const int feature_window_width,
67 const int feature_window_height)
68 : feature_window_width_ (feature_window_width), feature_window_height_ (feature_window_height)
82 feature_window_width_ = width;
83 feature_window_height_ = height;
92 const size_t num_of_features,
95 features.resize (num_of_features);
96 for (
size_t feature_index = 0; feature_index < num_of_features; ++feature_index)
98 features[feature_index].p1 =
PointXY32i::randomPoint(-feature_window_width_/2, feature_window_width_/2, -feature_window_height_/2, feature_window_height_/2);
99 features[feature_index].p2 =
PointXY32i::randomPoint(-feature_window_width_/2, feature_window_width_/2, -feature_window_height_/2, feature_window_height_/2);
100 features[feature_index].channel =
static_cast<unsigned char>(NUM_OF_CHANNELS*(
static_cast<float>(rand()) / (RAND_MAX+1)));
115 std::vector<MultipleData2DExampleIndex> & examples,
116 std::vector<float> & results,
117 std::vector<unsigned char> & flags)
const 119 results.resize (examples.size ());
120 flags.resize (examples.size ());
121 for (
int example_index = 0; example_index < examples.size (); ++example_index)
125 evaluateFeature (feature, data_set, example, results[example_index], flags[example_index]);
142 unsigned char & flag)
const 144 const int center_col_index = example.
x;
145 const int center_row_index = example.
y;
147 const size_t p1_col =
static_cast<size_t> (feature.
p1.x + center_col_index);
148 const size_t p1_row =
static_cast<size_t> (feature.
p1.y + center_row_index);
150 const size_t p2_col =
static_cast<size_t> (feature.
p2.x + center_col_index);
151 const size_t p2_row =
static_cast<size_t> (feature.
p2.y + center_row_index);
153 const unsigned char channel = feature.
channel;
155 const float value1 =
static_cast<float> (data_set (example.
data_set_id, p1_col, p1_row)[channel]);
156 const float value2 =
static_cast<float> (data_set (example.
data_set_id, p2_col, p2_row)[channel]);
158 result = value1 - value2;
159 flag = (pcl_isfinite (value1) && pcl_isfinite (value2)) ? 0 : 1;
169 std::ostream & stream)
const 171 stream <<
"ERROR: RegressionVarianceStatsEstimator does not implement generateCodeForBranchIndex(...)";
178 int feature_window_width_;
180 int feature_window_height_;
186 template <
class DATA_TYPE,
size_t NUM_OF_CHANNELS,
size_t SCALE_CHANNEL,
bool INVERT_SCALE>
188 :
public pcl::FeatureHandler<pcl::MultiChannel2DComparisonFeature<pcl::PointXY32f>, pcl::MultiChannel2DDataSet<DATA_TYPE, NUM_OF_CHANNELS>, pcl::MultipleData2DExampleIndex>
195 const int feature_window_width,
196 const int feature_window_height)
197 : feature_window_width_ (feature_window_width), feature_window_height_ (feature_window_height)
211 feature_window_width_ = width;
212 feature_window_height_ = height;
221 const size_t num_of_features,
224 features.resize (num_of_features);
225 for (
size_t feature_index = 0; feature_index < num_of_features; ++feature_index)
227 features[feature_index].p1 =
PointXY32f::randomPoint(-feature_window_width_/2, feature_window_width_/2, -feature_window_height_/2, feature_window_height_/2);
228 features[feature_index].p2 =
PointXY32f::randomPoint(-feature_window_width_/2, feature_window_width_/2, -feature_window_height_/2, feature_window_height_/2);
229 features[feature_index].channel =
static_cast<unsigned char>(NUM_OF_CHANNELS*(
static_cast<float>(rand()) / (RAND_MAX+1)));
244 std::vector<MultipleData2DExampleIndex> & examples,
245 std::vector<float> & results,
246 std::vector<unsigned char> & flags)
const 248 results.resize (examples.size ());
249 flags.resize (examples.size ());
250 for (
int example_index = 0; example_index < examples.size (); ++example_index)
254 evaluateFeature (feature, data_set, example, results[example_index], flags[example_index]);
271 unsigned char & flag)
const 273 const int center_col_index = example.
x;
274 const int center_row_index = example.
y;
278 scale = 1.0f /
static_cast<float> (data_set (example.
data_set_id, center_col_index, center_row_index)[SCALE_CHANNEL]);
280 scale =
static_cast<float> (data_set (example.
data_set_id, center_col_index, center_row_index)[SCALE_CHANNEL]);
285 const size_t p1_col =
static_cast<size_t> (scale * feature.
p1.x + center_col_index);
286 const size_t p1_row =
static_cast<size_t> (scale * feature.
p1.y + center_row_index);
288 const size_t p2_col =
static_cast<size_t> (scale * feature.
p2.x + center_col_index);
289 const size_t p2_row =
static_cast<size_t> (scale * feature.
p2.y + center_row_index);
291 const unsigned char channel = feature.
channel;
293 const float value1 =
static_cast<float> (data_set (example.
data_set_id, p1_col, p1_row)[channel]);
294 const float value2 =
static_cast<float> (data_set (example.
data_set_id, p2_col, p2_row)[channel]);
296 result = value1 - value2;
297 flag = (pcl_isfinite (value1) && pcl_isfinite (value2)) ? 0 : 1;
307 std::ostream & stream)
const 309 stream <<
"ERROR: ScaledMultiChannel2DComparisonFeatureHandler does not implement generateCodeForBranchIndex(...)" << std::endl;
322 int feature_window_width_;
324 int feature_window_height_;
329 template <
class DATA_TYPE,
size_t NUM_OF_CHANNELS,
size_t SCALE_CHANNEL,
bool INVERT_SCALE>
331 :
public pcl::FeatureHandlerCodeGenerator<pcl::MultiChannel2DComparisonFeature<pcl::PointXY32f>, pcl::MultiChannel2DDataSet<DATA_TYPE, NUM_OF_CHANNELS>, pcl::MultipleData2DExampleIndex>
338 generateEvalFunctionCode (
339 std::ostream & stream)
const;
344 std::ostream & stream)
const;
347 template <
class DATA_TYPE,
size_t NUM_OF_CHANNELS,
size_t SCALE_CHANNEL,
bool INVERT_SCALE>
350 std::ostream & stream)
const 352 if (NUM_OF_CHANNELS == 1 && SCALE_CHANNEL == 0 && INVERT_SCALE)
354 stream <<
"const float scale = 1.0f / static_cast<float> (*data_ptr);" << std::endl;
355 stream <<
"" << std::endl;
356 stream <<
"struct LocalFeatureHandler" << std::endl;
357 stream <<
"{" << std::endl;
358 stream <<
" static inline void eval (" <<
typeid (DATA_TYPE).name () <<
" * a_ptr, const float a_x1, const float a_y1, const float a_x2, const float a_y2, const float a_scale, const int a_width, float & a_result, unsigned char & a_flags)" << std::endl;
359 stream <<
" {" << std::endl;
360 stream <<
" a_result = *(a_ptr + static_cast<int> (a_scale*a_x1) + (static_cast<int> (a_scale*a_y1)*a_width)) - *(a_ptr + static_cast<int> (a_scale*a_x2) + (static_cast<int> (a_scale*a_y2)*a_width));" << std::endl;
361 stream <<
" }" << std::endl;
362 stream <<
"};" << std::endl;
366 stream <<
"ERROR: generateEvalFunctionCode not implemented" << std::endl;
370 template <
class DATA_TYPE,
size_t NUM_OF_CHANNELS,
size_t SCALE_CHANNEL,
bool INVERT_SCALE>
374 std::ostream & stream)
const 376 stream <<
"LocalFeatureHandler::eval (data_ptr, " 377 << feature.
p1.
x <<
", " 378 << feature.
p1.
y <<
", " 379 << feature.
p2.
x <<
", " 380 << feature.
p2.
y <<
", " 381 <<
"scale, width, result, flags);" << std::endl;
ScaledMultiChannel2DComparisonFeatureHandler< float, 2, 1, true > ScaledIntensityDepth2DComparisonFeatureHandler
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.
ScaledMultiChannel2DComparisonFeatureHandlerCCodeGenerator< float, 1, 0, true > ScaledDepth2DComparisonFeatureHandlerCCodeGenerator
ScaledMultiChannel2DComparisonFeatureHandler< float, 1, 0, true > ScaledDepth2DComparisonFeatureHandler
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.
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.
MultiChannel2DComparisonFeatureHandler(const int feature_window_width, const int feature_window_height)
Constructor.
ScaledMultiChannel2DComparisonFeatureHandlerCCodeGenerator()
Holds a set of two-dimensional multi-channel data.
MultiChannel2DComparisonFeatureHandler< float, 3 > RGB2DComparisonFeatureHandler
MultiChannel2DComparisonFeatureHandler< float, 1 > Depth2DComparisonFeatureHandler
unsigned char channel
Specifies which channel is used for comparison.
MultiChannel2DComparisonFeatureHandler< float, 4 > RGBD2DComparisonFeatureHandler
void generateEvalFunctionCode(std::ostream &stream) const
void createRandomFeatures(const size_t num_of_features, std::vector< MultiChannel2DComparisonFeature< PointXY32f > > &features)
Creates random features.
float y
The y-coordinate of the point.
void createRandomFeatures(const size_t num_of_features, std::vector< MultiChannel2DComparisonFeature< PointXY32i > > &features)
Creates random features.
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.
MultiChannel2DComparisonFeatureHandler< float, 2 > IntensityDepth2DComparisonFeatureHandler
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.
void generateEvalCode(const MultiChannel2DComparisonFeature< PointXY32f > &feature, std::ostream &stream) const
ScaledMultiChannel2DComparisonFeatureHandler< float, 4, 3, true > ScaledRGBD2DComparisonFeatureHandler
Utility class interface which is used for creating and evaluating features.
PointT p1
First sample point.