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;