Point Cloud Library (PCL)  1.11.1-dev
brisk_2d.hpp
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Point Cloud Library (PCL) - www.pointclouds.org
5  * Copyright (C) 2011, The Autonomous Systems Lab (ASL), ETH Zurich,
6  * Stefan Leutenegger, Simon Lynen and Margarita Chli.
7  * Copyright (c) 2012-, Open Perception, Inc.
8  *
9  * All rights reserved.
10  *
11  * Redistribution and use in source and binary forms, with or without
12  * modification, are permitted provided that the following conditions
13  * are met:
14  *
15  * * Redistributions of source code must retain the above copyright
16  * notice, this list of conditions and the following disclaimer.
17  * * Redistributions in binary form must reproduce the above
18  * copyright notice, this list of conditions and the following
19  * disclaimer in the documentation and/or other materials provided
20  * with the distribution.
21  * * Neither the name of the copyright holder(s) nor the names of its
22  * contributors may be used to endorse or promote products derived
23  * from this software without specific prior written permission.
24  *
25  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
28  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
29  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
30  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
31  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
32  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
33  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
35  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36  * POSSIBILITY OF SUCH DAMAGE.
37  *
38  */
39 
40 #ifndef PCL_KEYPOINTS_BRISK_KEYPOINT_2D_IMPL_H_
41 #define PCL_KEYPOINTS_BRISK_KEYPOINT_2D_IMPL_H_
42 
43 #include <pcl/common/io.h>
44 
45 
46 namespace pcl
47 {
48 
49 template <typename PointInT, typename PointOutT, typename IntensityT> bool
51 {
53  {
54  PCL_ERROR ("[pcl::%s::initCompute] init failed.!\n", name_.c_str ());
55  return (false);
56  }
57 
58  if (!input_->isOrganized ())
59  {
60  PCL_ERROR ("[pcl::%s::initCompute] %s doesn't support non organized clouds!\n", name_.c_str ());
61  return (false);
62  }
63 
64  return (true);
65 }
66 
67 
68 template <typename PointInT, typename PointOutT, typename IntensityT> void
70 {
71  // image size
72  const int width = int (input_->width);
73  const int height = int (input_->height);
74 
75  // destination for intensity data; will be forwarded to BRISK
76  std::vector<unsigned char> image_data (width*height);
77 
78  for (std::size_t i = 0; i < image_data.size (); ++i)
79  image_data[i] = static_cast<unsigned char> (intensity_ ((*input_)[i]));
80 
81  pcl::keypoints::brisk::ScaleSpace brisk_scale_space (octaves_);
82  brisk_scale_space.constructPyramid (image_data, width, height);
84  brisk_scale_space.getKeypoints (threshold_, output_temp.points);
85  pcl::copyPointCloud (output_temp, output);
86 
87  // we do not change the denseness
88  output.width = output.size ();
89  output.height = 1;
90  output.is_dense = false; // set to false to be sure
91 
92  // 2nd pass to remove the invalid set of 3D keypoints
93  if (remove_invalid_3D_keypoints_)
94  {
95  PointCloudOut output_clean;
96  for (std::size_t i = 0; i < output.size (); ++i)
97  {
98  PointOutT pt;
99  // Interpolate its position in 3D, as the "u" and "v" are subpixel accurate
100  bilinearInterpolation (input_, output[i].x, output[i].y, pt);
101 
102  // Check if the point is finite
103  if (pcl::isFinite (pt))
104  output_clean.push_back (output[i]);
105  }
106  output = output_clean;
107  output.is_dense = true; // set to true as there's no keypoint at an invalid XYZ
108  }
109 }
110 
111 } // namespace pcl
112 
113 #endif
114 
pcl
Definition: convolution.h:46
pcl::PointCloud::points
std::vector< PointT, Eigen::aligned_allocator< PointT > > points
The point data.
Definition: point_cloud.h:389
pcl::isFinite
bool isFinite(const PointT &pt)
Tests if the 3D components of a point are all finite param[in] pt point to be tested return true if f...
Definition: point_tests.h:55
pcl::PointCloud
PointCloud represents the base class in PCL for storing collections of 3D points.
Definition: distances.h:55
pcl::copyPointCloud
void copyPointCloud(const pcl::PointCloud< PointInT > &cloud_in, pcl::PointCloud< PointOutT > &cloud_out)
Copy all the fields from a given point cloud into a new point cloud.
Definition: io.hpp:144
pcl::BriskKeypoint2D::detectKeypoints
void detectKeypoints(PointCloudOut &output) override
Detects the keypoints.
Definition: brisk_2d.hpp:69
pcl::BriskKeypoint2D::PointCloudOut
typename Keypoint< PointInT, PointOutT >::PointCloudOut PointCloudOut
Definition: brisk_2d.h:80
pcl::keypoints::brisk::ScaleSpace::constructPyramid
void constructPyramid(const std::vector< unsigned char > &image, int width, int height)
Construct the image pyramids.
pcl::keypoints::brisk::ScaleSpace
BRISK Scale Space helper.
Definition: brisk_2d.h:393
pcl::BriskKeypoint2D::initCompute
bool initCompute() override
Initializes everything and checks whether input data is fine.
Definition: brisk_2d.hpp:50
pcl::keypoints::brisk::ScaleSpace::getKeypoints
void getKeypoints(const int threshold, std::vector< pcl::PointWithScale, Eigen::aligned_allocator< pcl::PointWithScale > > &keypoints)
Get the keypoints for the associated image and threshold.
pcl::Keypoint
Keypoint represents the base class for key points.
Definition: keypoint.h:49