42 #include <pcl/ml/feature_handler.h>
43 #include <pcl/ml/multi_channel_2d_comparison_feature.h>
44 #include <pcl/ml/multi_channel_2d_data_set.h>
45 #include <pcl/ml/multiple_data_2d_example_index.h>
46 #include <pcl/ml/point_xy_32f.h>
47 #include <pcl/ml/point_xy_32i.h>
56 template <
class DATA_TYPE, std::
size_t NUM_OF_CHANNELS>
59 pcl::MultiChannel2DDataSet<DATA_TYPE, NUM_OF_CHANNELS>,
60 pcl::MultipleData2DExampleIndex> {
65 const int feature_window_height)
66 : feature_window_width_(feature_window_width)
67 , feature_window_height_(feature_window_height)
81 feature_window_width_ = width;
82 feature_window_height_ = height;
92 const std::size_t num_of_features,
95 features.resize(num_of_features);
96 for (std::size_t feature_index = 0; feature_index < num_of_features;
99 feature_window_width_ / 2,
100 -feature_window_height_ / 2,
101 feature_window_height_ / 2);
103 feature_window_width_ / 2,
104 -feature_window_height_ / 2,
105 feature_window_height_ / 2);
106 features[feature_index].channel =
static_cast<unsigned char>(
107 NUM_OF_CHANNELS * (
static_cast<float>(rand()) / (RAND_MAX + 1)));
123 std::vector<MultipleData2DExampleIndex>& examples,
124 std::vector<float>& results,
125 std::vector<unsigned char>& flags)
const
127 results.resize(examples.size());
128 flags.resize(examples.size());
129 for (
int example_index = 0; example_index < examples.size(); ++example_index) {
133 feature, data_set, example, results[example_index], flags[example_index]);
151 unsigned char& flag)
const
153 const int center_col_index = example.
x;
154 const int center_row_index = example.
y;
156 const std::size_t p1_col =
157 static_cast<std::size_t
>(feature.
p1.x + center_col_index);
158 const std::size_t p1_row =
159 static_cast<std::size_t
>(feature.
p1.y + center_row_index);
161 const std::size_t p2_col =
162 static_cast<std::size_t
>(feature.
p2.x + center_col_index);
163 const std::size_t p2_row =
164 static_cast<std::size_t
>(feature.
p2.y + center_row_index);
166 const unsigned char channel = feature.
channel;
169 static_cast<float>(data_set(example.
data_set_id, p1_col, p1_row)[channel]);
171 static_cast<float>(data_set(example.
data_set_id, p2_col, p2_row)[channel]);
173 result = value1 - value2;
174 flag = (std::isfinite(value1) && std::isfinite(value2)) ? 0 : 1;
184 std::ostream& stream)
const
186 stream <<
"ERROR: RegressionVarianceStatsEstimator does not implement "
187 "generateCodeForBranchIndex(...)";
198 int feature_window_width_;
200 int feature_window_height_;
205 template <
class DATA_TYPE,
206 std::size_t NUM_OF_CHANNELS,
207 std::size_t SCALE_CHANNEL,
211 pcl::MultiChannel2DDataSet<DATA_TYPE, NUM_OF_CHANNELS>,
212 pcl::MultipleData2DExampleIndex> {
217 const int feature_window_height)
218 : feature_window_width_(feature_window_width)
219 , feature_window_height_(feature_window_height)
233 feature_window_width_ = width;
234 feature_window_height_ = height;
244 const std::size_t num_of_features,
247 features.resize(num_of_features);
248 for (std::size_t feature_index = 0; feature_index < num_of_features;
251 feature_window_width_ / 2,
252 -feature_window_height_ / 2,
253 feature_window_height_ / 2);
255 feature_window_width_ / 2,
256 -feature_window_height_ / 2,
257 feature_window_height_ / 2);
258 features[feature_index].channel =
static_cast<unsigned char>(
259 NUM_OF_CHANNELS * (
static_cast<float>(rand()) / (RAND_MAX + 1)));
275 std::vector<MultipleData2DExampleIndex>& examples,
276 std::vector<float>& results,
277 std::vector<unsigned char>& flags)
const
279 results.resize(examples.size());
280 flags.resize(examples.size());
281 for (
int example_index = 0; example_index < examples.size(); ++example_index) {
285 feature, data_set, example, results[example_index], flags[example_index]);
303 unsigned char& flag)
const
305 const int center_col_index = example.
x;
306 const int center_row_index = example.
y;
310 scale = 1.0f /
static_cast<float>(data_set(example.
data_set_id,
312 center_row_index)[SCALE_CHANNEL]);
314 scale =
static_cast<float>(data_set(
315 example.
data_set_id, center_col_index, center_row_index)[SCALE_CHANNEL]);
317 const std::size_t p1_col =
318 static_cast<std::size_t
>(scale * feature.
p1.x + center_col_index);
319 const std::size_t p1_row =
320 static_cast<std::size_t
>(scale * feature.
p1.y + center_row_index);
322 const std::size_t p2_col =
323 static_cast<std::size_t
>(scale * feature.
p2.x + center_col_index);
324 const std::size_t p2_row =
325 static_cast<std::size_t
>(scale * feature.
p2.y + center_row_index);
327 const unsigned char channel = feature.
channel;
330 static_cast<float>(data_set(example.
data_set_id, p1_col, p1_row)[channel]);
332 static_cast<float>(data_set(example.
data_set_id, p2_col, p2_row)[channel]);
334 result = value1 - value2;
335 flag = (std::isfinite(value1) && std::isfinite(value2)) ? 0 : 1;
345 std::ostream& stream)
const
347 stream <<
"ERROR: ScaledMultiChannel2DComparisonFeatureHandler does not implement "
348 "generateCodeForBranchIndex(...)"
367 int feature_window_width_;
369 int feature_window_height_;
372 template <
class DATA_TYPE,
373 std::size_t NUM_OF_CHANNELS,
374 std::size_t SCALE_CHANNEL,
377 :
public pcl::FeatureHandlerCodeGenerator<
378 pcl::MultiChannel2DComparisonFeature<pcl::PointXY32f>,
379 pcl::MultiChannel2DDataSet<DATA_TYPE, NUM_OF_CHANNELS>,
380 pcl::MultipleData2DExampleIndex> {
386 generateEvalFunctionCode(std::ostream& stream)
const;
390 std::ostream& stream)
const;
393 template <
class DATA_TYPE,
394 std::size_t NUM_OF_CHANNELS,
395 std::size_t SCALE_CHANNEL,
398 ScaledMultiChannel2DComparisonFeatureHandlerCCodeGenerator<
402 INVERT_SCALE>::generateEvalFunctionCode(std::ostream& stream)
const
404 if (NUM_OF_CHANNELS == 1 && SCALE_CHANNEL == 0 && INVERT_SCALE) {
405 stream <<
"const float scale = 1.0f / static_cast<float> (*data_ptr);"
407 stream <<
"" << std::endl;
408 stream <<
"struct LocalFeatureHandler" << std::endl;
409 stream <<
"{" << std::endl;
410 stream <<
" static inline void eval (" <<
typeid(DATA_TYPE).name()
411 <<
" * a_ptr, const float a_x1, const float a_y1, const float a_x2, const "
412 "float a_y2, const float a_scale, const int a_width, float & a_result, "
413 "unsigned char & a_flags)"
415 stream <<
" {" << std::endl;
416 stream <<
" a_result = *(a_ptr + static_cast<int> (a_scale*a_x1) + "
417 "(static_cast<int> (a_scale*a_y1)*a_width)) - *(a_ptr + static_cast<int> "
418 "(a_scale*a_x2) + (static_cast<int> (a_scale*a_y2)*a_width));"
420 stream <<
" }" << std::endl;
421 stream <<
"};" << std::endl;
424 stream <<
"ERROR: generateEvalFunctionCode not implemented" << std::endl;
428 template <
class DATA_TYPE,
429 std::size_t NUM_OF_CHANNELS,
430 std::size_t SCALE_CHANNEL,
438 std::ostream& stream)
const
440 stream <<
"LocalFeatureHandler::eval (data_ptr, " << feature.
p1.
x <<
", "
441 << feature.
p1.
y <<
", " << feature.
p2.
x <<
", " << feature.
p2.
y <<
", "
442 <<
"scale, width, result, flags);" << std::endl;