Point Cloud Library (PCL)  1.9.0-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 template <typename PointInT, typename PointOutT, typename IntensityT> bool
48 {
50  {
51  PCL_ERROR ("[pcl::%s::initCompute] init failed.!\n", name_.c_str ());
52  return (false);
53  }
54 
55  if (!input_->isOrganized ())
56  {
57  PCL_ERROR ("[pcl::%s::initCompute] %s doesn't support non organized clouds!\n", name_.c_str ());
58  return (false);
59  }
60 
61  return (true);
62 }
63 
64 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
65 template <typename PointInT, typename PointOutT, typename IntensityT> void
67 {
68  // image size
69  const int width = int (input_->width);
70  const int height = int (input_->height);
71 
72  // destination for intensity data; will be forwarded to BRISK
73  std::vector<unsigned char> image_data (width*height);
74 
75  for (size_t i = 0; i < image_data.size (); ++i)
76  image_data[i] = static_cast<unsigned char> (intensity_ ((*input_)[i]));
77 
78  pcl::keypoints::brisk::ScaleSpace brisk_scale_space (octaves_);
79  brisk_scale_space.constructPyramid (image_data, width, height);
81  brisk_scale_space.getKeypoints (threshold_, output_temp.points);
82  pcl::copyPointCloud<pcl::PointWithScale, PointOutT> (output_temp, output);
83 
84  // we do not change the denseness
85  output.width = int (output.points.size ());
86  output.height = 1;
87  output.is_dense = false; // set to false to be sure
88 
89  // 2nd pass to remove the invalid set of 3D keypoints
90  if (remove_invalid_3D_keypoints_)
91  {
92  PointCloudOut output_clean;
93  for (size_t i = 0; i < output.size (); ++i)
94  {
95  PointOutT pt;
96  // Interpolate its position in 3D, as the "u" and "v" are subpixel accurate
97  bilinearInterpolation (input_, output[i].x, output[i].y, pt);
98 
99  // Check if the point is finite
100  if (pcl::isFinite (pt))
101  output_clean.push_back (output[i]);
102  }
103  output = output_clean;
104  output.is_dense = true; // set to true as there's no keypoint at an invalid XYZ
105  }
106 }
107 
108 #endif
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:54
size_t size() const
Definition: point_cloud.h:448
BRISK Scale Space helper.
Definition: brisk_2d.h:392
std::vector< PointT, Eigen::aligned_allocator< PointT > > points
The point data.
Definition: point_cloud.h:410
void push_back(const PointT &pt)
Insert a new point in the cloud, at the end of the container.
Definition: point_cloud.h:480
uint32_t height
The point cloud height (if organized as an image-structure).
Definition: point_cloud.h:415
Keypoint represents the base class for key points.
Definition: keypoint.h:49
uint32_t width
The point cloud width (if organized as an image-structure).
Definition: point_cloud.h:413
bool initCompute()
Initializes everything and checks whether input data is fine.
Definition: brisk_2d.hpp:47
void detectKeypoints(PointCloudOut &output)
Detects the keypoints.
Definition: brisk_2d.hpp:66
PointCloud represents the base class in PCL for storing collections of 3D points. ...
void constructPyramid(const std::vector< unsigned char > &image, int width, int height)
Construct the image pyramids.
bool is_dense
True if no points are invalid (e.g., have NaN or Inf values in any of their floating point fields)...
Definition: point_cloud.h:418
void getKeypoints(const int threshold, std::vector< pcl::PointWithScale, Eigen::aligned_allocator< pcl::PointWithScale > > &keypoints)
Get the keypoints for the associated image and threshold.