OpenCV学习笔记——判断两张图的相似度
                                                            生活随笔
收集整理的這篇文章主要介紹了
                                OpenCV学习笔记——判断两张图的相似度
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.                        
                                判斷兩張圖的相似度
方法
實驗
1.直方圖對比法
參考如何使用OpenCV3直方圖方法進行人臉相似度對比
 因為我的環境是VS2010+OpenCV2.4.8,所以在原版的基礎上做了一點小修改。
主要實現思路:
 1)從本地讀取兩張圖像
 2)將需要對比的圖像進行HSV格式轉換
 3)構建圖像的直方圖模型,并進行直方圖歸一化
 4)比較兩張圖片的直方圖模型,計算圖片的直方圖相似度
 5)判斷相似度值,如果大于0.85左右我們可以認為兩張圖片比較相似的
2. ORB算法
參考OpenCV圖像相似度ORB算法(圖像特征比對)
#include "stdafx.h" #include <iostream> #include<opencv2/opencv.hpp> #include "opencv2/core/core.hpp" #include "opencv2/features2d/features2d.hpp" #include "opencv2/highgui/highgui.hpp" #include "opencv2/nonfree/nonfree.hpp" #include "opencv2/nonfree/features2d.hpp" #include<opencv2/legacy/legacy.hpp>using namespace std; using namespace cv;int getORB(char * imagePatha,char * imagePathb){double t;t=getTickCount();Mat img_1 = imread(imagePatha);Mat img_2 = imread(imagePathb);if (!img_1.data || !img_2.data) {cout << "error reading images " << endl; return -1;}ORB orb;vector<KeyPoint> keyPoints_1, keyPoints_2;Mat descriptors_1, descriptors_2;orb(img_1, Mat(), keyPoints_1, descriptors_1);orb(img_2, Mat(), keyPoints_2, descriptors_2);BruteForceMatcher<HammingLUT> matcher;vector<DMatch> matches;matcher.match(descriptors_1, descriptors_2, matches);double max_dist = 0; double min_dist = 100;for( int i = 0; i < descriptors_1.rows; i++ ) {double dist = matches[i].distance;if( dist < min_dist ) min_dist = dist;if( dist > max_dist ) max_dist = dist;}printf("-- Max dist : %f \n", max_dist );printf("-- Min dist : %f \n", min_dist );std::vector< DMatch > good_matches;for( int i = 0; i < descriptors_1.rows; i++ ) {if( matches[i].distance < 0.6*max_dist ){good_matches.push_back(matches[i]);}}t=getTickCount()-t;t=t*1000/getTickFrequency();Mat img_matches;drawMatches(img_1, keyPoints_1, img_2, keyPoints_2,good_matches, img_matches,Scalar::all(-1), Scalar::all(-1),vector<char>(),DrawMatchesFlags::NOT_DRAW_SINGLE_POINTS);imshow( "Match", img_matches); printf( "%f ms\n", t );cvWaitKey(0);return 0; }int main() {getORB("r.png","s.png");return 0; }總結
以上是生活随笔為你收集整理的OpenCV学习笔记——判断两张图的相似度的全部內容,希望文章能夠幫你解決所遇到的問題。
 
                            
                        - 上一篇: 完整opencv(emgucv)人脸、检
- 下一篇: Node.js -- Stream 使用
