41 #ifndef PCL_HARRIS_KEYPOINT_2D_IMPL_H_
42 #define PCL_HARRIS_KEYPOINT_2D_IMPL_H_
44 #include <pcl/common/point_tests.h>
51 template <
typename Po
intInT,
typename Po
intOutT,
typename IntensityT>
void
58 template <
typename Po
intInT,
typename Po
intOutT,
typename IntensityT>
void
61 threshold_= threshold;
65 template <
typename Po
intInT,
typename Po
intOutT,
typename IntensityT>
void
72 template <
typename Po
intInT,
typename Po
intOutT,
typename IntensityT>
void
79 template <
typename Po
intInT,
typename Po
intOutT,
typename IntensityT>
void
82 window_width_= window_width;
86 template <
typename Po
intInT,
typename Po
intOutT,
typename IntensityT>
void
89 window_height_= window_height;
93 template <
typename Po
intInT,
typename Po
intOutT,
typename IntensityT>
void
96 skipped_pixels_= skipped_pixels;
100 template <
typename Po
intInT,
typename Po
intOutT,
typename IntensityT>
void
103 min_distance_ = min_distance;
107 template <
typename Po
intInT,
typename Po
intOutT,
typename IntensityT>
void
110 static const int width =
static_cast<int> (input_->width);
111 static const int height =
static_cast<int> (input_->height);
113 int x =
static_cast<int> (index % input_->width);
114 int y =
static_cast<int> (index / input_->width);
117 std::fill_n(coefficients, 3, 0);
119 int endx = std::min (width, x + half_window_width_);
120 int endy = std::min (height, y + half_window_height_);
121 for (
int xx = std::max (0, x - half_window_width_); xx < endx; ++xx)
122 for (
int yy = std::max (0, y - half_window_height_); yy < endy; ++yy)
124 const float& ix = derivatives_rows_ (xx,yy);
125 const float& iy = derivatives_cols_ (xx,yy);
126 coefficients[0]+= ix * ix;
127 coefficients[1]+= ix * iy;
128 coefficients[2]+= iy * iy;
133 template <
typename Po
intInT,
typename Po
intOutT,
typename IntensityT>
bool
138 PCL_ERROR (
"[pcl::%s::initCompute] init failed.!\n", name_.c_str ());
142 if (!input_->isOrganized ())
144 PCL_ERROR (
"[pcl::%s::initCompute] %s doesn't support non organized clouds!\n", name_.c_str ());
148 if (indices_->size () != input_->size ())
150 PCL_ERROR (
"[pcl::%s::initCompute] %s doesn't support setting indices!\n", name_.c_str ());
154 if ((window_height_%2) == 0)
156 PCL_ERROR (
"[pcl::%s::initCompute] Window height must be odd!\n", name_.c_str ());
160 if ((window_width_%2) == 0)
162 PCL_ERROR (
"[pcl::%s::initCompute] Window width must be odd!\n", name_.c_str ());
166 if (window_height_ < 3 || window_width_ < 3)
168 PCL_ERROR (
"[pcl::%s::initCompute] Window size must be >= 3x3!\n", name_.c_str ());
172 half_window_width_ = window_width_ / 2;
173 half_window_height_ = window_height_ / 2;
179 template <
typename Po
intInT,
typename Po
intOutT,
typename IntensityT>
void
182 derivatives_cols_.resize (input_->width, input_->height);
183 derivatives_rows_.resize (input_->width, input_->height);
186 int w =
static_cast<int> (input_->width) - 1;
187 int h =
static_cast<int> (input_->height) - 1;
190 derivatives_cols_(0,0) = (intensity_ ((*input_) (0,1)) - intensity_ ((*input_) (0,0))) * 0.5;
191 derivatives_rows_(0,0) = (intensity_ ((*input_) (1,0)) - intensity_ ((*input_) (0,0))) * 0.5;
193 for(
int i = 1; i < w; ++i)
195 derivatives_cols_(i,0) = (intensity_ ((*input_) (i,1)) - intensity_ ((*input_) (i,0))) * 0.5;
198 derivatives_rows_(w,0) = (intensity_ ((*input_) (w,0)) - intensity_ ((*input_) (w-1,0))) * 0.5;
199 derivatives_cols_(w,0) = (intensity_ ((*input_) (w,1)) - intensity_ ((*input_) (w,0))) * 0.5;
201 for(
int j = 1; j < h; ++j)
204 derivatives_rows_(0,j) = (intensity_ ((*input_) (1,j)) - intensity_ ((*input_) (0,j))) * 0.5;
205 for(
int i = 1; i < w; ++i)
208 derivatives_rows_(i,j) = (intensity_ ((*input_) (i+1,j)) - intensity_ ((*input_) (i-1,j))) * 0.5;
211 derivatives_cols_(i,j) = (intensity_ ((*input_) (i,j+1)) - intensity_ ((*input_) (i,j-1))) * 0.5;
214 derivatives_rows_(w,j) = (intensity_ ((*input_) (w,j)) - intensity_ ((*input_) (w-1,j))) * 0.5;
218 derivatives_cols_(0,h) = (intensity_ ((*input_) (0,h)) - intensity_ ((*input_) (0,h-1))) * 0.5;
219 derivatives_rows_(0,h) = (intensity_ ((*input_) (1,h)) - intensity_ ((*input_) (0,h))) * 0.5;
221 for(
int i = 1; i < w; ++i)
223 derivatives_cols_(i,h) = (intensity_ ((*input_) (i,h)) - intensity_ ((*input_) (i,h-1))) * 0.5;
225 derivatives_rows_(w,h) = (intensity_ ((*input_) (w,h)) - intensity_ ((*input_) (w-1,h))) * 0.5;
226 derivatives_cols_(w,h) = (intensity_ ((*input_) (w,h)) - intensity_ ((*input_) (w,h-1))) * 0.5;
231 responseHarris(*response_);
234 responseNoble(*response_);
237 responseLowe(*response_);
240 responseTomasi(*response_);
247 for (std::size_t i = 0; i < response_->size (); ++i)
248 keypoints_indices_->indices.push_back (i);
252 std::sort (indices_->begin (), indices_->end (), [
this] (
int p1,
int p2) { return greaterIntensityAtIndices (p1, p2); });
253 const float threshold = threshold_ * (*response_)[indices_->front ()].intensity;
255 output.reserve (response_->size());
256 std::vector<bool> occupency_map (response_->size (),
false);
257 int width (response_->width);
258 int height (response_->height);
259 const int occupency_map_size (occupency_map.size ());
261 #if OPENMP_LEGACY_CONST_DATA_SHARING_RULE
262 #pragma omp parallel for \
264 shared(occupency_map, output) \
265 firstprivate(width, height) \
266 num_threads(threads_)
268 #pragma omp parallel for \
270 shared(occupency_map, occupency_map_size, output, threshold) \
271 firstprivate(width, height) \
272 num_threads(threads_)
274 for (
int i = 0; i < occupency_map_size; ++i)
276 int idx = indices_->at (i);
277 const PointOutT& point_out = response_->points [idx];
278 if (occupency_map[idx] || point_out.intensity < threshold || !
isXYZFinite (point_out))
283 output.push_back (point_out);
284 keypoints_indices_->indices.push_back (idx);
287 int u_end = std::min (width, idx % width + min_distance_);
288 int v_end = std::min (height, idx / width + min_distance_);
289 for(
int u = std::max (0, idx % width - min_distance_); u < u_end; ++u)
290 for(
int v = std::max (0, idx / width - min_distance_); v < v_end; ++v)
291 occupency_map[v*input_->width+u] =
true;
298 output.width = output.size();
302 output.is_dense = input_->is_dense;
306 template <
typename Po
intInT,
typename Po
intOutT,
typename IntensityT>
void
309 PCL_ALIGN (16)
float covar [3];
311 output.resize (input_->size ());
312 const int output_size (output.size ());
314 #if OPENMP_LEGACY_CONST_DATA_SHARING_RULE
315 #pragma omp parallel for \
318 firstprivate(covar) \
319 num_threads(threads_)
321 #pragma omp parallel for \
323 shared(output, output_size) \
324 firstprivate(covar) \
325 num_threads(threads_)
327 for (
int index = 0; index < output_size; ++index)
329 PointOutT& out_point = output.points [index];
330 const PointInT &in_point = (*input_).points [index];
331 out_point.intensity = 0;
332 out_point.x = in_point.x;
333 out_point.y = in_point.y;
334 out_point.z = in_point.z;
337 computeSecondMomentMatrix (index, covar);
338 float trace = covar [0] + covar [2];
341 float det = covar[0] * covar[2] - covar[1] * covar[1];
342 out_point.intensity = 0.04f + det - 0.04f * trace * trace;
347 output.height = input_->height;
348 output.width = input_->width;
352 template <
typename Po
intInT,
typename Po
intOutT,
typename IntensityT>
void
355 PCL_ALIGN (16)
float covar [3];
357 output.resize (input_->size ());
358 const int output_size (output.size ());
360 #if OPENMP_LEGACY_CONST_DATA_SHARING_RULE
361 #pragma omp parallel for \
364 firstprivate(covar) \
365 num_threads(threads_)
367 #pragma omp parallel for \
369 shared(output, output_size) \
370 firstprivate(covar) \
371 num_threads(threads_)
373 for (
int index = 0; index < output_size; ++index)
375 PointOutT &out_point = output.points [index];
376 const PointInT &in_point = input_->points [index];
377 out_point.x = in_point.x;
378 out_point.y = in_point.y;
379 out_point.z = in_point.z;
380 out_point.intensity = 0;
383 computeSecondMomentMatrix (index, covar);
384 float trace = covar [0] + covar [2];
387 float det = covar[0] * covar[2] - covar[1] * covar[1];
388 out_point.intensity = det / trace;
393 output.height = input_->height;
394 output.width = input_->width;
398 template <
typename Po
intInT,
typename Po
intOutT,
typename IntensityT>
void
401 PCL_ALIGN (16)
float covar [3];
403 output.resize (input_->size ());
404 const int output_size (output.size ());
406 #if OPENMP_LEGACY_CONST_DATA_SHARING_RULE
407 #pragma omp parallel for \
410 firstprivate(covar) \
411 num_threads(threads_)
413 #pragma omp parallel for \
415 shared(output, output_size) \
416 firstprivate(covar) \
417 num_threads(threads_)
419 for (
int index = 0; index < output_size; ++index)
421 PointOutT &out_point = output.points [index];
422 const PointInT &in_point = input_->points [index];
423 out_point.x = in_point.x;
424 out_point.y = in_point.y;
425 out_point.z = in_point.z;
426 out_point.intensity = 0;
429 computeSecondMomentMatrix (index, covar);
430 float trace = covar [0] + covar [2];
433 float det = covar[0] * covar[2] - covar[1] * covar[1];
434 out_point.intensity = det / (trace * trace);
439 output.height = input_->height;
440 output.width = input_->width;
444 template <
typename Po
intInT,
typename Po
intOutT,
typename IntensityT>
void
447 PCL_ALIGN (16)
float covar [3];
449 output.resize (input_->size ());
450 const int output_size (output.size ());
452 #if OPENMP_LEGACY_CONST_DATA_SHARING_RULE
453 #pragma omp parallel for \
456 firstprivate(covar) \
457 num_threads(threads_)
459 #pragma omp parallel for \
461 shared(output, output_size) \
462 firstprivate(covar) \
463 num_threads(threads_)
465 for (
int index = 0; index < output_size; ++index)
467 PointOutT &out_point = output.points [index];
468 const PointInT &in_point = input_->points [index];
469 out_point.x = in_point.x;
470 out_point.y = in_point.y;
471 out_point.z = in_point.z;
472 out_point.intensity = 0;
475 computeSecondMomentMatrix (index, covar);
477 out_point.intensity = ((covar[0] + covar[2] - std::sqrt((covar[0] - covar[2])*(covar[0] - covar[2]) + 4 * covar[1] * covar[1])) /2.0f);
481 output.height = input_->height;
482 output.width = input_->width;
487 #define PCL_INSTANTIATE_HarrisKeypoint2D(T,U,I) template class PCL_EXPORTS pcl::HarrisKeypoint2D<T,U,I>;
void setNonMaxSupression(bool=false)
whether non maxima suppression should be applied or the response for each point should be returned
void setSkippedPixels(int skipped_pixels)
Set number of pixels to skip.
void responseTomasi(PointCloudOut &output) const
void responseLowe(PointCloudOut &output) const
void setRefine(bool do_refine)
whether the detected key points should be refined or not.
void detectKeypoints(PointCloudOut &output) override
void responseNoble(PointCloudOut &output) const
void setMinimalDistance(int min_distance)
Set minimal distance between candidate keypoints.
void setMethod(ResponseMethod type)
set the method of the response to be calculated.
void computeSecondMomentMatrix(std::size_t pos, float *coefficients) const
calculates the upper triangular part of unnormalized covariance matrix over intensities given by the ...
void setWindowHeight(int window_height)
Set window height.
void responseHarris(PointCloudOut &output) const
gets the corner response for valid input points
typename Keypoint< PointInT, PointOutT >::PointCloudOut PointCloudOut
bool initCompute() override
void setThreshold(float threshold)
set the threshold value for detecting corners.
void setWindowWidth(int window_width)
Set window width.
Keypoint represents the base class for key points.
constexpr bool isXYZFinite(const PointT &) noexcept