opencv2基于SURF特征提取實(shí)現(xiàn)兩張圖像拼接融合的示例分析-創(chuàng)新互聯(lián)

小編給大家分享一下opencv2基于SURF特征提取實(shí)現(xiàn)兩張圖像拼接融合的示例分析,相信大部分人都還不怎么了解,因此分享這篇文章給大家參考一下,希望大家閱讀完這篇文章后大有收獲,下面讓我們一起去了解一下吧!

創(chuàng)新互聯(lián)公司自2013年創(chuàng)立以來,是專業(yè)互聯(lián)網(wǎng)技術(shù)服務(wù)公司,擁有項(xiàng)目成都網(wǎng)站設(shè)計(jì)、做網(wǎng)站、成都外貿(mào)網(wǎng)站建設(shè)公司網(wǎng)站策劃,項(xiàng)目實(shí)施與項(xiàng)目整合能力。我們以讓每一個夢想脫穎而出為使命,1280元松山做網(wǎng)站,已為上家服務(wù),為松山各地企業(yè)和個人服務(wù),聯(lián)系電話:18982081108

本文實(shí)例為大家分享了opencv2實(shí)現(xiàn)兩張圖像拼接融合的具體代碼,供大家參考,具體內(nèi)容如下

要用到兩個文件,estimate.cpp和matcher.h(在有關(guān)魯棒匹配這篇博文中有)

estimate.cpp的頭文件也需要添加一些東西才行,以下是對的,已經(jīng)成功運(yùn)行。

加了using namespace std;之后,cv::可以去掉了。

estimate.cpp:

#include <iostream>
#include <vector>
#include <opencv2/core/core.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/features2d/features2d.hpp>
#include <opencv2/calib3d/calib3d.hpp>
#include<opencv2/nonfree/nonfree.hpp>
#include<opencv2\legacy\legacy.hpp> 
#include "matcher.h"
using namespace std;
using namespace cv;
int main()
{
// Read input images讀入圖像
cv::Mat image1= cv::imread("parliament1.bmp",0);
cv::Mat image2= cv::imread("parliament2.bmp",0);
if (!image1.data || !image2.data)
return 0; 


  // Display the images顯示圖像
cv::namedWindow("Image 1");
cv::imshow("Image 1",image1);
cv::namedWindow("Image 2");
cv::imshow("Image 2",image2);


// Prepare the matcher準(zhǔn)備匹配
RobustMatcher rmatcher;
rmatcher.setConfidenceLevel(0.98);
rmatcher.setMinDistanceToEpipolar(1.0);
rmatcher.setRatio(0.65f);
cv::Ptr<cv::FeatureDetector> pfd= new cv::SurfFeatureDetector(10); 
rmatcher.setFeatureDetector(pfd);


// Match the two images
std::vector<cv::DMatch> matches;
std::vector<cv::KeyPoint> keypoints1, keypoints2;
cv::Mat fundemental= rmatcher.match(image1,image2,matches, keypoints1, keypoints2);


// draw the matches畫匹配結(jié)果
cv::Mat imageMatches;
cv::drawMatches(image1,keypoints1, // 1st image and its keypoints第一張圖像及其關(guān)鍵點(diǎn)
      image2,keypoints2, // 2nd image and its keypoints第二張圖像及其關(guān)鍵點(diǎn)
matches, // the matches匹配結(jié)果
imageMatches, // the image produced產(chǎn)生的圖像
cv::Scalar(255,255,255)); // color of the lines線的顏色
cv::namedWindow("Matches");
cv::imshow("Matches",imageMatches);

// Convert keypoints into Point2f將關(guān)鍵點(diǎn)轉(zhuǎn)換為Point2f
std::vector<cv::Point2f> points1, points2;
for (std::vector<cv::DMatch>::const_iterator it= matches.begin();
it!= matches.end(); ++it) {H


// Get the position of left keypoints得到左圖關(guān)鍵點(diǎn)位置
float x= keypoints1[it->queryIdx].pt.x;
float y= keypoints1[it->queryIdx].pt.y;
points1.push_back(cv::Point2f(x,y));
// Get the position of right keypoints得到右圖關(guān)鍵點(diǎn)位置
x= keypoints2[it->trainIdx].pt.x;
y= keypoints2[it->trainIdx].pt.y;
points2.push_back(cv::Point2f(x,y));
}


std::cout << points1.size() << " " << points2.size() << std::endl; 


// Find the homography between image 1 and image 2找到圖像1和圖像2之間的單應(yīng)性矩陣
std::vector<uchar> inliers(points1.size(),0);
cv::Mat homography= cv::findHomography(
cv::Mat(points1),cv::Mat(points2), // corresponding points對應(yīng)點(diǎn)
inliers, // outputed inliers matches 輸出內(nèi)點(diǎn)匹配
CV_RANSAC, // RANSAC method   RANSAC 方法
1.);  // max distance to reprojection point到對應(yīng)點(diǎn)的大距離


// Draw the inlier points畫內(nèi)點(diǎn)
std::vector<cv::Point2f>::const_iterator itPts= points1.begin();
std::vector<uchar>::const_iterator itIn= inliers.begin();
while (itPts!=points1.end()) {


// draw a circle at each inlier location在每一個內(nèi)點(diǎn)畫一個圈
if (*itIn) 
 cv::circle(image1,*itPts,3,cv::Scalar(255,255,255),2);

++itPts;
++itIn;
}


itPts= points2.begin();
itIn= inliers.begin();
while (itPts!=points2.end()) {


// draw a circle at each inlier location在每一個內(nèi)點(diǎn)畫一個圈
if (*itIn) 
cv::circle(image2,*itPts,3,cv::Scalar(255,255,255),2);

++itPts;
++itIn;
}


  // Display the images with points顯示畫點(diǎn)的圖像
cv::namedWindow("Image 1 Homography Points");
cv::imshow("Image 1 Homography Points",image1);
cv::namedWindow("Image 2 Homography Points");
cv::imshow("Image 2 Homography Points",image2);


// Warp image 1 to image 2變形圖像1到圖像2
cv::Mat result;
cv::warpPerspective(image1, // input image輸入的圖像
result, // output image輸出的圖像
homography, // homography單應(yīng)性矩陣
cv::Size(2*image1.cols,image1.rows)); // size of output image輸出圖像的大小


// Copy image 1 on the first half of full image復(fù)制圖像1的上一部分
cv::Mat half(result,cv::Rect(0,0,image2.cols,image2.rows));
image2.copyTo(half);


  // Display the warp image顯示變形后圖像
cv::namedWindow("After warping");
cv::imshow("After warping",result);


cv::waitKey();
return 0;
}

以上是“opencv2基于SURF特征提取實(shí)現(xiàn)兩張圖像拼接融合的示例分析”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對大家有所幫助,如果還想學(xué)習(xí)更多知識,歡迎關(guān)注創(chuàng)新互聯(lián)網(wǎng)站建設(shè)公司行業(yè)資訊頻道!

另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)建站www.muchs.cn,海內(nèi)外云服務(wù)器15元起步,三天無理由+7*72小時(shí)售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務(wù)可用性高、性價(jià)比高”等特點(diǎn)與優(yōu)勢,專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場景需求。

網(wǎng)頁題目:opencv2基于SURF特征提取實(shí)現(xiàn)兩張圖像拼接融合的示例分析-創(chuàng)新互聯(lián)
分享路徑:http://www.muchs.cn/article38/cdeosp.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供App設(shè)計(jì)、做網(wǎng)站、微信小程序、靜態(tài)網(wǎng)站、營銷型網(wǎng)站建設(shè)、網(wǎng)站導(dǎo)航

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

手機(jī)網(wǎng)站建設(shè)