免费视频淫片aa毛片_日韩高清在线亚洲专区vr_日韩大片免费观看视频播放_亚洲欧美国产精品完整版

打開APP
userphoto
未登錄

開通VIP,暢享免費(fèi)電子書等14項(xiàng)超值服

開通VIP
OpenCV學(xué)習(xí)筆記(九)——2維特征Feature2D
基于特征點(diǎn)的圖像匹配是圖像處理中經(jīng)常會(huì)遇到的問題,手動(dòng)選取特征點(diǎn)太麻煩了。比較經(jīng)典常用的特征點(diǎn)自動(dòng)提取的辦法有Harris特征、SIFT特征、SURF特征。
先介紹利用SURF特征的特征描述辦法,其操作封裝在類SurfFeatureDetector中,利用類內(nèi)的detect函數(shù)可以檢測出SURF特征的關(guān)鍵點(diǎn),保存在vector容器中。第二部利用SurfDescriptorExtractor類進(jìn)行特征向量的相關(guān)計(jì)算。將之前的vector變量變成向量矩陣形式保存在Mat中。最后強(qiáng)行匹配兩幅圖像的特征向量,利用了類BruteForceMatcher中的函數(shù)match。代碼如下:
view plain
/**
* @file SURF_descriptor
* @brief SURF detector + descritpor + BruteForce Matcher + drawing matches with OpenCV functions
* @author A. Huaman
*/
#include <stdio.h>
#include <iostream>
#include "opencv2/core/core.hpp"
#include "opencv2/features2d/features2d.hpp"
#include "opencv2/highgui/highgui.hpp"
using namespace cv;
void readme();
/**
* @function main
* @brief Main function
*/
int main( int argc, char** argv )
{
if( argc != 3 )
{ return -1; }
Mat img_1 = imread( argv[1], CV_LOAD_IMAGE_GRAYSCALE );
Mat img_2 = imread( argv[2], CV_LOAD_IMAGE_GRAYSCALE );
if( !img_1.data || !img_2.data )
{ return -1; }
//-- Step 1: Detect the keypoints using SURF Detector
int minHessian = 400;
SurfFeatureDetector detector( minHessian );
std::vector<KeyPoint> keypoints_1, keypoints_2;
detector.detect( img_1, keypoints_1 );
detector.detect( img_2, keypoints_2 );
//-- Step 2: Calculate descriptors (feature vectors)
SurfDescriptorExtractor extractor;
Mat descriptors_1, descriptors_2;
extractor.compute( img_1, keypoints_1, descriptors_1 );
extractor.compute( img_2, keypoints_2, descriptors_2 );
//-- Step 3: Matching descriptor vectors with a brute force matcher
BruteForceMatcher< L2<float> > matcher;
std::vector< DMatch > matches;
matcher.match( descriptors_1, descriptors_2, matches );
//-- Draw matches
Mat img_matches;
drawMatches( img_1, keypoints_1, img_2, keypoints_2, matches, img_matches );
//-- Show detected matches
imshow("Matches", img_matches );
waitKey(0);
return 0;
}
/**
* @function readme
*/
void readme()
{ std::cout << " Usage: ./SURF_descriptor <img1> <img2>" << std::endl; }
當(dāng)然,進(jìn)行強(qiáng)匹配的效果不夠理想,這里再介紹一種FLANN特征匹配算法。前兩步與上述代碼相同,第三步利用FlannBasedMatcher類進(jìn)行特征匹配,并只保留好的特征匹配點(diǎn),代碼如下:
view plain
//-- Step 3: Matching descriptor vectors using FLANN matcher
FlannBasedMatcher matcher;
std::vector< DMatch > matches;
matcher.match( descriptors_1, descriptors_2, matches );
double max_dist = 0; double min_dist = 100;
//-- Quick calculation of max and min distances between keypoints
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 );
//-- Draw only "good" matches (i.e. whose distance is less than 2*min_dist )
//-- PS.- radiusMatch can also be used here.
std::vector< DMatch > good_matches;
for( int i = 0; i < descriptors_1.rows; i++ )
{ if( matches[i].distance < 2*min_dist )
{ good_matches.push_back( matches[i]); }
}
//-- Draw only "good" matches
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 );
//-- Show detected matches
imshow( "Good Matches", img_matches );
在FLANN特征匹配的基礎(chǔ)上,還可以進(jìn)一步利用Homography映射找出已知物體。具體來說就是利用findHomography函數(shù)利用匹配的關(guān)鍵點(diǎn)找出相應(yīng)的變換,再利用perspectiveTransform函數(shù)映射點(diǎn)群。具體代碼如下:
view plain
//-- Localize the object from img_1 in img_2
std::vector<Point2f> obj;
std::vector<Point2f> scene;
for( int i = 0; i < good_matches.size(); i++ )
{
//-- Get the keypoints from the good matches
obj.push_back( keypoints_1[ good_matches[i].queryIdx ].pt );
scene.push_back( keypoints_2[ good_matches[i].trainIdx ].pt );
}
Mat H = findHomography( obj, scene, CV_RANSAC );
//-- Get the corners from the image_1 ( the object to be "detected" )
Point2f obj_corners[4] = { cvPoint(0,0), cvPoint( img_1.cols, 0 ), cvPoint( img_1.cols, img_1.rows ), cvPoint( 0, img_1.rows ) };
Point scene_corners[4];
//-- Map these corners in the scene ( image_2)
for( int i = 0; i < 4; i++ )
{
double x = obj_corners[i].x;
double y = obj_corners[i].y;
double Z = 1./( H.at<double>(2,0)*x + H.at<double>(2,1)*y + H.at<double>(2,2) );
double X = ( H.at<double>(0,0)*x + H.at<double>(0,1)*y + H.at<double>(0,2) )*Z;
double Y = ( H.at<double>(1,0)*x + H.at<double>(1,1)*y + H.at<double>(1,2) )*Z;
scene_corners[i] = cvPoint( cvRound(X) + img_1.cols, cvRound(Y) );
}
//-- Draw lines between the corners (the mapped object in the scene - image_2 )
line( img_matches, scene_corners[0], scene_corners[1], Scalar(0, 255, 0), 2 );
line( img_matches, scene_corners[1], scene_corners[2], Scalar( 0, 255, 0), 2 );
line( img_matches, scene_corners[2], scene_corners[3], Scalar( 0, 255, 0), 2 );
line( img_matches, scene_corners[3], scene_corners[0], Scalar( 0, 255, 0), 2 );
//-- Show detected matches
imshow( "Good Matches & Object detection", img_matches );
然后再看一下Harris特征檢測,在計(jì)算機(jī)視覺中,通常需要找出兩幀圖像的匹配點(diǎn),如果能找到兩幅圖像如何相關(guān),就能提取出兩幅圖像的信息。我們說的特征的最大特點(diǎn)就是它具有唯一可識(shí)別這一特點(diǎn),圖像特征的類型通常指邊界、角點(diǎn)(興趣點(diǎn))、斑點(diǎn)(興趣區(qū)域)。角點(diǎn)就是圖像的一個(gè)局部特征,應(yīng)用廣泛。harris角點(diǎn)檢測是一種直接基于灰度圖像的角點(diǎn)提取算法,穩(wěn)定性高,尤其對(duì)L型角點(diǎn)檢測精度高,但由于采用了高斯濾波,運(yùn)算速度相對(duì)較慢,角點(diǎn)信息有丟失和位置偏移的現(xiàn)象,而且角點(diǎn)提取有聚簇現(xiàn)象。具體實(shí)現(xiàn)就是使用函數(shù)cornerHarris實(shí)現(xiàn)。
除了利用Harris進(jìn)行角點(diǎn)檢測,還可以利用Shi-Tomasi方法進(jìn)行角點(diǎn)檢測。使用函數(shù)goodFeaturesToTrack對(duì)角點(diǎn)進(jìn)行檢測,效果也不錯(cuò)。也可以自己制作角點(diǎn)檢測的函數(shù),需要用到cornerMinEigenVal函數(shù)和minMaxLoc函數(shù),最后的特征點(diǎn)選取,判斷條件要根據(jù)自己的情況編輯。如果對(duì)特征點(diǎn),角點(diǎn)的精度要求更高,可以用cornerSubPix函數(shù)將角點(diǎn)定位到子像素。
本站僅提供存儲(chǔ)服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點(diǎn)擊舉報(bào)。
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
高翔Slambook第七講代碼解讀(2d-2d位姿估計(jì))
干貨 | 基于特征的圖像配準(zhǔn)用于缺陷檢測
OpenCVSharp特征匹配之Brute Force匹配
ORB Test
BRIEF 特征描述子
opencv檢測提取匹配消除錯(cuò)誤匹配顯示 綜合列子
更多類似文章 >>
生活服務(wù)
分享 收藏 導(dǎo)長圖 關(guān)注 下載文章
綁定賬號(hào)成功
后續(xù)可登錄賬號(hào)暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服