快速最近鄰匹配

2021-07-10 07:46:11 字數 2757 閱讀 1818

這是乙個完整的利用suft快速近鄰匹配的程式

#include 

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

using

namespace

std;

using

namespace cv;

double calcoefficient(const mat &src1 , const point2f key1 , const mat &src2 , const point2f key2) ;//用於計算匹配點之間的相關係數

keypoints_1 , keypoints_2 ; //儲存特徵點向量

dector.detect(src1 , keypoints_1) ; //檢測surf特徵

dector.detect(src2 , keypoints_2) ;

//計算描述子

surfdescriptorextractor extractor ;

mat descriptors_1 , descriptors_2 ;

extractor.compute(src1 , keypoints_1 , descriptors_1) ;

extractor.compute(src2 , keypoints_2 , descriptors_2) ;

//flan特徵匹配演算法

flannbasedmatcher matcher ;

vector

matches ;

matcher.match(descriptors_1 , descriptors_2 , matches) ;

cout

<

//計算關鍵點之間最大最小歐式距離

for (int i = 0 ; i < descriptors_1.rows ; i++)

if (dist > max_dist)

}cout

<

/選擇歐式距離小於2倍最小距離的匹配作為優良匹配

vector

good_matches ;

for (int i = 0 ; i < descriptors_1.rows ; i++)

}mat m_matches ;

m_matches.create(src1.rows , 2 * src1.cols , src1.type()) ;

mat imageroi ;

imageroi = m_matches(rect(0 , 0 , src1.cols , src1.rows)) ;

mat imageroi2 ;

imageroi2 = m_matches(rect(src1.cols , 0 , src2.cols , src2.rows)) ;

addweighted(imageroi , 0.0 , src1 , 1.0 , 0 , imageroi) ;

addweighted(imageroi2 , 0.0 , src2 , 1.0 , 0 , imageroi2) ;

cout

<

for (int i = 0 ; i < good_matches.size() ; ++i)

{int index1 = good_matches[i].queryidx ;

int index2 = good_matches[i].trainidx ;

circle(m_matches , keypoints_1[index1].pt , 10 , scalar(0 , 0 , 255) , 5) ;

circle(m_matches , point(src1.cols + keypoints_2[index2].pt.x , keypoints_2[index2].pt.y) , 10 , scalar(0 , 0 , 255) , 5) ;

line(m_matches , keypoints_1[index1].pt , point(keypoints_2[index2].pt.x + src1.cols , keypoints_2[index2].pt.y) , scalar::all(-1) , 10 , 8) ;

double coefficent = calcoefficient(src1 , keypoints_1[index1].pt , src2 , keypoints_2[index2].pt) ;

cout

cout

<

imshow("m_matches" , m_matches) ;

waitkey(0) ;

程式執行結果;

結果是不是很好啊!

icp點雲匹配迭代最近鄰演算法

一 含義 1.icp演算法能夠使兩個不同座標系下的點集匹配到乙個座標系中,這個過程就是配準,配準的操作就是找到從座標系1變換到座標系2的剛性變換。2.icp的本質就是配準,但有不同的配準方案,icp演算法本質是基於最小二乘的最優配準方法。該方法重複進行選擇對應關係對,計算最優剛體變換,直到滿足正確配...

Tensorflow實現最近鄰

import tensorflow as tf import numpy as np 匯入mnist資料 from tensorflow.examples.tutorials.mnist import input data mnist input data.read data sets data m...

最近鄰 相關推薦

最近鄰 import numpy as np from numpy import linalg as la from sklearn.neighbors import nearestneighbors m np.array 你吃飯了嗎 今天的花兒很好看 簡直不能更完美 你喜歡吃辣椒嗎 天氣很完美 這...