-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathFeatureMatcher2.h
97 lines (82 loc) · 3.71 KB
/
FeatureMatcher2.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#ifndef FLANNMATCHER2
#define FLANNMATCHER2
#include <iostream>
#include <vector>
#include <set>
#include <math.h>
#include "opencv2/objdetect/objdetect.hpp"
#include "opencv2/features2d/features2d.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/calib3d/calib3d.hpp"
#include "opencv2/nonfree/nonfree.hpp"
#include "opencv2/imgproc/imgproc_c.h"
#include "opencv2/legacy/legacy.hpp"
#include "opencv2/legacy/compat.hpp"
#include <pcl/io/pcd_io.h>
#include <pcl/point_types.h>
#include <pcl/ModelCoefficients.h>
#include <pcl/kdtree/kdtree.h>
#include <pcl/kdtree/kdtree_flann.h>
#include <pcl/common/transformation_from_correspondences.h>
#include <pcl/registration/gicp.h>
#include <pcl/registration/icp.h>
using namespace std;
class FlannMatcher2
{
public:
FlannMatcher2();
~FlannMatcher2();
void projectTo3D(vector<cv::KeyPoint>& keypoints,
cv::Mat& depth,
vector<Eigen::Vector3f >& eigenPoint);
void getMatches(cv::Mat& depth1,cv::Mat& depth2,
cv::Mat& rgb1,cv::Mat& rgb2,
std::vector<cv::DMatch>& matches,
vector<cv::KeyPoint>& keypoints1,
vector<cv::KeyPoint>& keypoints2,
vector<Eigen::Vector3f>& eigenPoints1,
vector<Eigen::Vector3f>& eigenPoints2);
template<class InputIterator>
Eigen::Matrix4f getTransformFromMatches(vector<Eigen::Vector3f>& eigenPoints1,
vector<Eigen::Vector3f>& eigenPoints2,
InputIterator itr_begin,
InputIterator itr_end,
bool& valid,
float max_dist_m=-1);
void computeInliersAndError(vector<cv::DMatch>& matches,
Eigen::Matrix4f& transformation,
vector<Eigen::Vector3f>& eigenPoints1,
vector<Eigen::Vector3f>& eigenPoints2,
vector<cv::DMatch>& inliers, //output
double& mean_error,
vector<double>& errors,
double squaredMaxInlierDistInM=0.0009);
bool getRelativeTransformations(vector<Eigen::Vector3f>& eigenPoints1,
vector<Eigen::Vector3f>& eigenPoints2,
vector<cv::DMatch>& initial_matches,
Eigen::Matrix4f& result_transform,
float& rmse,
vector<cv::DMatch>& matches,
unsigned int ransac_iterations=1000);
bool getFinalTransform(cv::Mat& image1,cv::Mat& image2,
cv::Mat& depth1,cv::Mat& depth2,
pcl::PointCloud<pcl::PointXYZRGB>::Ptr& pc1,//Must be downsampled
pcl::PointCloud<pcl::PointXYZRGB>::Ptr& pc2,
vector<cv::DMatch>& bestMatches,
Eigen::Matrix4f& bestTransform);
//draw functions
void drawInliers(cv::Mat& image1,cv::Mat& image2,
vector<cv::KeyPoint>& keypoints1,
vector<cv::KeyPoint>& keypoints2,
vector<cv::DMatch>& matches,
vector<cv::DMatch>& bestMatches);
IplImage* stack_imgs( IplImage* img1, IplImage* img2 );
private:
int min_matches;
float max_dist_for_inliers;
cv::Ptr<cv::FeatureDetector> detector;
cv::Ptr<cv::DescriptorExtractor> extractor;
double fx,fy,cx,cy;
double camera_factor;
};
#endif