18 #ifndef PIC_COMPUTER_VISION_ITERATIVE_CLOSEST_POINT_2D_HPP 19 #define PIC_COMPUTER_VISION_ITERATIVE_CLOSEST_POINT_2D_HPP 25 #include "../base.hpp" 27 #include "../util/math.hpp" 29 #include "../features_matching/brief_descriptor.hpp" 31 #include "../util/eigen_util.hpp" 33 #ifndef PIC_DISABLE_EIGEN 34 #ifndef PIC_EIGEN_NOT_BUNDLED 35 #include "../externals/Eigen/Dense" 36 #include "../externals/Eigen/SVD" 37 #include "../externals/Eigen/Geometry" 39 #include <Eigen/Dense> 41 #include <Eigen/Geometry> 46 #ifndef PIC_DISABLE_EIGEN 56 for(
unsigned int i = 1; i < p.size(); i++) {
72 float *x =
new float[n];
73 float *y =
new float[n];
75 for(
unsigned int i = 0; i < n; i++) {
89 printf(
"%f %f\n", med[0], med[1]);
119 float cos_a = cosf(angle);
120 float sin_a = sinf(angle);
130 printf(
"R:\n %f %f\n %f %f\n",
R(0,0),
R(0,1),
R(1,0),
R(1,1));
132 printf(
"T: %f %f\n",
t[0],
t[1]);
134 printf(
"S: %f\n\n",
scale);
137 void apply(std::vector< Eigen::Vector2f > &points) {
139 for(
unsigned int i = 0; i < points.size(); i++) {
140 Eigen::Vector2f tmp = points[i];
141 points[i] = ((
R * tmp) +
t) *
scale;
145 void apply(std::vector< Eigen::Vector2f > &points,
146 std::vector< Eigen::Vector2f > &out) {
148 for(
unsigned int i = 0; i < points.size(); i++) {
149 Eigen::Vector2f tmp = ((
R * points[i]) +
t) *
scale;
158 void applyC(std::vector< Eigen::Vector2f > &points) {
165 for(
unsigned int i = 0; i < points.size(); i++) {
166 Eigen::Vector2f tmp = points[i] - c;
167 points[i] = (
R * tmp) *
scale + shift;
171 void applyC(std::vector< Eigen::Vector2f > &points,
172 std::vector< Eigen::Vector2f > &out) {
179 for(
unsigned int i = 0; i < points.size(); i++) {
180 Eigen::Vector2f tmp = points[i] - c;
181 Eigen::Vector2f tmp2 = (
R * tmp) *
scale + shift;
197 std::vector< Eigen::Vector2f > &p1,
198 std::vector< unsigned int *> &p0_descs,
199 std::vector< unsigned int *> &p1_descs,
205 if(p0.size() < 2 || p1.size() < 2) {
211 ind =
new int[p1.size()];
224 printf(
"Size: %d\n", size_descs);
227 for(
int i = 0; i < p1.size(); i++) {
230 float d_min = FLT_MAX;
232 for(
int j = 0; j < p0.size(); j++) {
233 auto delta_ij = p_i - p0[j];
234 float d_tmp = delta_ij.norm();
237 d_tmp += float(size_descs * 32) - float(value);
259 for(
unsigned int i = 0; i < p1.size(); i++) {
262 auto t0 = p0[j] - c0;
263 auto t1 = p1[i] - c1;
265 Eigen::RowVector2f t1r = t1;
266 Eigen::Matrix2f tmp = t0 * t1r;
276 Eigen::JacobiSVD< Eigen::Matrix2f > svd(H, Eigen::ComputeFullV | Eigen::ComputeFullU);
277 Eigen::Matrix2f U = svd.matrixU();
278 Eigen::Matrix2f V = svd.matrixV();
280 Eigen::Matrix2f U_t = U.transpose();
281 Eigen::Matrix2f R = V * U_t;
283 if(R.determinant() < 0.0f) {
284 for(
unsigned int i = 0; i < V.rows(); i++) {
292 ret.
t = c0 - (ret.
R * c1);
308 std::vector< Eigen::Vector2f > &p1)
311 for(
unsigned int i = 0; i < p0.size(); i++) {
314 float tmp_err = FLT_MAX;
315 for(
unsigned int j = 0; j < p1.size(); j++) {
316 auto delta_ij = p_i - p1[j];
317 float dist = delta_ij.norm();
327 return err / float(p0.size());
340 std::vector<Eigen::Vector2f> &points,
341 std::vector< unsigned int *> &points_pattern_descs,
342 std::vector< unsigned int *> &points_descs,
344 int maxIterations = 1000)
348 t_init.
apply(points_pattern);
351 float prev_err = 1e32f;
353 while(iter < maxIterations) {
356 points_descs, points_pattern_descs,
364 t.
apply(points_pattern);
379 printf(
"Error: %f %f\n", err, prev_err);
389 #endif // PIC_COMPUTER_VISION_ITERATIVE_CLOSEST_POINT_2D_HPP
PIC_INLINE float getErrorPointsList(std::vector< Eigen::Vector2f > &p0, std::vector< Eigen::Vector2f > &p1)
getErrorPointsList
Definition: iterative_closest_point_2D.hpp:307
PIC_INLINE ICP2DTransform estimateRotatioMatrixAndTranslation(std::vector< Eigen::Vector2f > &p0, std::vector< Eigen::Vector2f > &p1, std::vector< unsigned int *> &p0_descs, std::vector< unsigned int *> &p1_descs, int size_descs, int *ind=NULL)
estimateRotatioMatrixAndTranslation
Definition: iterative_closest_point_2D.hpp:196
#define PIC_INLINE
Definition: base.hpp:33
static uint match(uint *fv0, uint *fv1, uint nfv)
match matches two descriptors. Note: Higher scores means better matching.
Definition: brief_descriptor.hpp:255
PIC_INLINE Eigen::Vector2f getMedianVector2f(std::vector< Eigen::Vector2f > &p)
getMedianVector2f
Definition: iterative_closest_point_2D.hpp:69
PIC_INLINE Eigen::Vector2f getMeanVector2f(std::vector< Eigen::Vector2f > &p)
getMean
Definition: iterative_closest_point_2D.hpp:53
Definition: bilateral_separation.hpp:25
PIC_INLINE void iterativeClosestPoints2D(std::vector< Eigen::Vector2f > &points_pattern, std::vector< Eigen::Vector2f > &points, std::vector< unsigned int *> &points_pattern_descs, std::vector< unsigned int *> &points_descs, int size_descs, int maxIterations=1000)
iterativeClosestPoints2D
Definition: iterative_closest_point_2D.hpp:339