42 #ifndef PCL_2D_KEYPOINT_HPP_
43 #define PCL_2D_KEYPOINT_HPP_
46 #include <pcl/2d/convolution.h>
47 #include <pcl/2d/edge.h>
51 pcl::keypoint::harrisCorner(ImageType& output,
62 conv_2d.gaussianKernel(5, sigma_d, kernel_d);
63 conv_2d.gaussianKernel(5, sigma_i, kernel_i);
66 ImageType smoothed_image;
67 conv_2d.convolve(smoothed_image, kernel_d, input);
71 edge_detection.ComputeDerivativeXCentral(I_x, smoothed_image);
72 edge_detection.ComputeDerivativeYCentral(I_y, smoothed_image);
75 ImageType I_x2, I_y2, I_xI_y;
76 imageElementMultiply(I_x2, I_x, I_x);
77 imageElementMultiply(I_y2, I_y, I_y);
78 imageElementMultiply(I_xI_y, I_x, I_y);
81 ImageType M00, M10, M11;
82 conv_2d.convolve(M00, kernel_i, I_x2);
83 conv_2d.convolve(M10, kernel_i, I_xI_y);
84 conv_2d.convolve(M11, kernel_i, I_y2);
87 const std::size_t height = input.size();
88 const std::size_t width = input[0].size();
89 output.resize(height);
90 for (std::size_t i = 0; i < height; i++) {
91 output[i].resize(width);
92 for (std::size_t j = 0; j < width; j++) {
93 output[i][j] = M00[i][j] * M11[i][j] - (M10[i][j] * M10[i][j]) -
94 alpha * ((M00[i][j] + M11[i][j]) * (M00[i][j] + M11[i][j]));
96 if (output[i][j] < thresh)
105 for (std::size_t i = 1; i < height - 1; i++) {
106 for (std::size_t j = 1; j < width - 1; j++) {
107 if (output[i][j] > output[i - 1][j - 1] && output[i][j] > output[i - 1][j] &&
108 output[i][j] > output[i - 1][j + 1] && output[i][j] > output[i][j - 1] &&
109 output[i][j] > output[i][j + 1] && output[i][j] > output[i + 1][j - 1] &&
110 output[i][j] > output[i + 1][j] && output[i][j] > output[i + 1][j + 1])
120 pcl::keypoint::hessianBlob(ImageType& output,
126 ImageType kernel, cornerness;
127 conv_2d.gaussianKernel(5, sigma, kernel);
130 ImageType smoothed_image;
131 conv_2d.convolve(smoothed_image, kernel, input);
135 edge_detection.ComputeDerivativeXCentral(I_x, smoothed_image);
136 edge_detection.ComputeDerivativeYCentral(I_y, smoothed_image);
139 ImageType I_xx, I_yy, I_xy;
140 edge_detection.ComputeDerivativeXCentral(I_xx, I_x);
141 edge_detection.ComputeDerivativeYCentral(I_xy, I_x);
142 edge_detection.ComputeDerivativeYCentral(I_yy, I_y);
144 const std::size_t height = input.size();
145 const std::size_t width = input[0].size();
146 float min = std::numeric_limits<float>::max();
147 float max = std::numeric_limits<float>::min();
148 cornerness.resize(height);
149 for (std::size_t i = 0; i < height; i++) {
150 cornerness[i].resize(width);
151 for (std::size_t j = 0; j < width; j++) {
153 sigma * sigma * (I_xx[i][j] + I_yy[i][j] - I_xy[i][j] * I_xy[i][j]);
155 if (cornerness[i][j] < min)
156 min = cornerness[i][j];
157 if (cornerness[i][j] > max)
158 max = cornerness[i][j];
163 output.resize(height);
164 output[0].resize(width);
165 output[height - 1].resize(width);
166 for (std::size_t i = 1; i < height - 1; i++) {
167 output[i].resize(width);
168 for (std::size_t j = 1; j < width - 1; j++) {
170 output[i][j] = ((cornerness[i][j] - min) / (max - min));
172 output[i][j] = cornerness[i][j];
180 pcl::keypoint::hessianBlob(ImageType& output,
182 const float start_scale,
183 const float scaling_factor,
184 const int num_scales)
186 const std::size_t height = input.size();
187 const std::size_t width = input[0].size();
188 const int local_search_radius = 1;
189 float scale = start_scale;
190 std::vector<ImageType> cornerness;
191 cornerness.resize(num_scales);
192 for (
int i = 0; i < num_scales; i++) {
193 hessianBlob(cornerness[i], input, scale,
false);
194 scale *= scaling_factor;
196 bool non_max_flag =
false;
197 float scale_max, local_max;
198 for (std::size_t i = 0; i < height; i++) {
199 for (std::size_t j = 0; j < width; j++) {
200 scale_max = std::numeric_limits<float>::min();
203 for (
int k = 0; k < num_scales; k++) {
205 non_max_flag =
false;
206 local_max = cornerness[k][i][j];
207 for (
int n = -local_search_radius; n <= local_search_radius; n++) {
208 if (n + k < 0 || n + k >= num_scales)
210 for (
int l = -local_search_radius; l <= local_search_radius; l++) {
211 if (l + i < 0 || l + i >= height)
213 for (
int m = -local_search_radius; m <= local_search_radius; m++) {
214 if (m + j < 0 || m + j >= width)
216 if (cornerness[n + k][l + i][m + j] > local_max) {
230 if (cornerness[k][i][j] > scale_max) {
231 scale_max = cornerness[k][i][j];
234 output[i][i] = start_scale * pow(scaling_factor, k);
244 pcl::keypoint::imageElementMultiply(ImageType& output,
248 const std::size_t height = input1.size();
249 const std::size_t width = input1[0].size();
250 output.resize(height);
251 for (std::size_t i = 0; i < height; i++) {
252 output[i].resize(width);
253 for (std::size_t j = 0; j < width; j++) {
254 output[i][j] = input1[i][j] * input2[i][j];
259 #endif // PCL_2D_KEYPOINT_HPP_