這是本書的第三章,本文主要關注其中的特征點比對及去除失配點的方法。
主要功能:對統一物體拍了兩張照片,隻是第二張圖檔有選擇和尺度的變化。現在要分别對兩幅圖像提取特征點,然後将這些特征點比對,使其盡量互相對應
下面,本文通過采用surf特征,分别使用Brute-force matcher和Flann-based matcher對特征點進行互相比對:
第一段代碼摘自opencv官網的教程:
Brute-forcedescriptor matcher. For each descriptor in the first set, this matcher findsthe closest descriptor in the second set by trying each one. This descriptormatcher supports masking
permissible matches of descriptor sets.
上面是那個bfmatcher的介紹,各位自己體會。我上面代碼把surf的門檻值故意設定的很大,否則圖檔全是線,沒法看。上面代碼的運作結果:

如圖,有很多比對失誤。書中對比對失誤有兩種定義:
False-positivematches:特征點健全,隻是對應關系錯誤;
False-negativematches:特征點消失,導緻對應關系錯誤;
我們隻關心第一種情況,解決方案有兩種,一種是将BFMatcher構造函數的第二個參數設定為true,作為cross-match filter。
他的思想是:to match train descriptors with the query set and viceversa.Only common matches for these two matches are returned. Such techniquesusually produce best results with minimal number of outliers when there areenough matches
效果圖:
可以看到比對錯誤的線段比第一副圖少了。
第二種Flann-based matcher:uses the fastapproximate nearest neighbor search algorithm to find correspondences (it usesfast third-party library for approximate nearest neighbors library for this).
用法:
下面介紹第二種去除比對錯誤點方法,KNN-matching:We performKNN-matching first with K=2. Two nearest descriptors are returned for eachmatch.The match is returned only if the distance ratio between the first andsecond matches is
big enough (the ratio threshold is usually near two).
這裡,我把surf門檻值設為1500了,效果圖:
最後,老外書中又提到了使用單應性矩陣變換來進一步細化結果:
這段代碼直接承接上一段代碼即可。效果圖:
這次文章寫得太沒勁了,主要老外書上這章本身就沒意思,随書代碼每次都一大堆,第三章還要用到opengl,不玩了!
以後一段日子,專心圖像基本特征提取的實作和android基礎功能的實作。opencv先放一邊了