#include
#include
#include
#include
#include
#include
using namespace std;
using namespace cv;
int main() {
//Read images
Mat graf_1, graf_3;
graf_1 = imread("../data/vggAffineDataset/graf/img1.ppm");
graf_3 = imread("../data/vggAffineDataset/graf/img3.ppm");
if (graf_1.empty() || graf_3.empty()){
cerr<<"No images"< kp1, kp3;
sift.detect(graf_1,kp1);
sift.detect(graf_3,kp3);
//surf.detect(graf_1,kp1);
//surf.detect(graf_3,kp3);
cout<<"The number of keypoints of graf_1 is "< matches;
matcher.match(desc_1,desc_3,matches);
double max_dist = 0;
double min_dist = 10000;
for (int i = 0; i < matches.size(); ++i) {
if (matches[i].distance < min_dist)
min_dist = matches[i].distance;
if (matches[i].distance > max_dist)
max_dist = matches[i].distance;
}
vector goodMatches;
for (int j = 0; j < matches.size(); ++j) {
if (matches[j].distance < 4*min_dist)
goodMatches.push_back(matches[j]);
}
cout<<"Matches is "<(k,0) = pt1.x;
p1.at(k,1) = pt1.y;
pt3 = kp3[goodMatches[k].trainIdx].pt;
p3.at(k,0) = pt3.x;
p3.at(k,1) = pt3.y;
}
vector m_RANSACStatus;
findFundamentalMat(p1,p3,m_RANSACStatus,FM_RANSAC);
int inlinerCount = 0;
for (int l = 0; l < ptCount; ++l) {
if (m_RANSACStatus[l] != 0)
inlinerCount++;
}
cout<<"inlinerCount is "< inlierMatches;
for (int i=0; i
實驗效果圖:
(kp_graf_1)
(kp_graf_3)
(不經過任何處理的圖像匹配)
(使用距離小於最小距離四倍時的匹配效果)
(使用RANSAC算法提純後的圖像匹配效果)