影象處理之 模型匹配有關知識
2.模板匹配的幾種演算法:
1.平方差匹配method=cv_tm_sqdiff,
2.標準平方差匹配method=cv_tm_sqdiff_normed
(這類方法利用平方差來進行匹配,最好匹配為0.匹配越差,匹配值越大.)
3.相關匹配method=cv_tm_ccorr,
4.標準相關匹配method=cv_tm_ccorr_normed
(這類方法採用模板和影象間的乘法操作,所以較大的數表示匹配程度較高,0標識最壞的匹配效果.)
5.相關係數匹配method=cv_tm_ccoeff。這類方法將模版對其均值的相對值與影象對其均值的相關值進行匹配,1表示完美匹配,-1表示糟糕的匹配,0表示沒有任何相關性(隨機序列).
6.標準相關係數匹配method=cv_tm_ccoeff_normed
備註:除了1,2兩種平方差匹配值越低匹配度越好,其餘幾種值越高越好
程式
#include
"stdafx.h"
//本節講述 影象處理之 模型匹配;
#include
#include
#include
using
namespace std;
using
namespace cv;
void
hist_and_backprojection
(int
,void*)
;mat src, test1, test2, dst, gray_src,temp;
char input_title=
"原圖"
;int match_method = cv_tm_sqdiff;
int max_track =5;
void
match_demo
(int
,void*)
;int
main
(int argc,
char
**ar**)
namedwindow
(input_title, cv_window_autosize)
;imshow
(input_title, src)
;imshow
("目標"
, temp)
;// const char* trackbar_label = "method: \n 0: sqdiff \n 1: sqdiff normed \n 2: tm ccorr \n 3: tm ccorr normed \n 4: tm coeff \n 5: tm coeff normed";
const
char
*trackbar_title =
"match alog type "
;createtrackbar
(trackbar_title, input_title,
&match_method, max_track, match_demo)
;match_demo(0
,0);
waitkey(0
);destroyallwindows()
;return0;
}void
match_demo
(int
,void*)
//幾種不同的匹配方法,結果不同,利用平方差來進行匹配,最好匹配為0.匹配越差,匹配值越大.
else
rectangle
(dst,
rect
(temloc.x, temloc.y,temp.cols,temp.rows)
,scalar(0
,2555,0
),2,
8);rectangle
(result,
rect
(temloc.x, temloc.y, temp.cols, temp.rows)
,scalar(0
,2555,0
),2,
8);imshow
("結果"
,result)
;imshow
("匹配"
, dst)
;}
程式執行結果![](https://pic.w3help.cc/cbe/986dd26693b382dc8035c6af96b80.jpeg)
疑問:temp是姚明,為什麼卻變成了老黑?換張圖試試
問題還是存在,然後擴**擇的區域,即temp尺寸變大
完成:原因;可能是目標特徵不夠明顯,盡量選擇較大尺寸或區域。
Opencv之特徵匹配
import cv2 import numpy as np import matplotlib.pyplot as plt matplotlib inline def cv show name,img cv2.imshow name,img cv2.waitkey 0 cv2.destroyallw...
OpenCV之模板匹配
模板匹配是在一幅影象中尋找與另一幅模板影象最匹配 相似 部分的技術,在opencv中,模板匹配由函式matchtemplate 函式實現。需要注意的是,模板匹配不是基於直方圖的,而是通過在輸入影象上滑 像塊,對實際的影象塊和輸入影象進行匹配的一種方法。如圖,通過乙個人臉影象模板,在整個輸入影象上移動...
OpenCV的RobustMatch匹配演算法
今天在網上看到乙個比較健壯的影象特徵匹配演算法,遂拿出來與大家分享 class robustmatcher set the feature detector void setfeaturedetector cv ptr detect set the descriptor extractor void...