雷火电竞-中国电竞赛事及体育赛事平台

歡迎來到入門教程網(wǎng)!

C語言

當(dāng)前位置:主頁 > 軟件編程 > C語言 >

OpenCV實(shí)現(xiàn)多圖像拼接成一張大圖

來源:本站原創(chuàng)|時(shí)間:2020-01-10|欄目:C語言|點(diǎn)擊:

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

開始嘗試merge函數(shù),具體如下:

定義四個(gè)矩陣A,B,C,D。得到矩陣combine。

#include<iostream>
#include <core/core.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>
using namespace std;
using namespace cv;
int main()
{
 cv::Mat a = (cv::Mat_<int>(2,2)<<1,2,3,4);
 cv::Mat b = (cv::Mat_<int>(2,2)<<5,6,7,8);
 cv::Mat c = (cv::Mat_<int>(2,2)<<9,10,11,12);
 cv::Mat d = (cv::Mat_<int>(2,2)<<13,14,15,16);
 std::vector<cv::Mat> v1;
 v1.push_back(a);
 v1.push_back(b);
 v1.push_back(c);
 v1.push_back(d);
 cv::Mat combine;
 cv::merge(v1, combine);
 cout << "combine=" <<combine<< endl;
 cout<<"Size of combine:"<<combine.size()<<endl;
 
 system("pause");
 return 0;
}

結(jié)果如下:

顯然,不是我們需要的結(jié)果。

嘗試hconcat和vconcat函數(shù),這兩個(gè)函數(shù)opencv本身并沒有。

詳細(xì)介紹參見hconcat和vconcat。

具體實(shí)現(xiàn)如下:

#include <iostream>
#include <core/core.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>
using namespace std;
using namespace cv;
int main()
{
 cv::Mat a = (cv::Mat_<int>(2,2)<<1,2,3,4);
 cv::Mat b = (cv::Mat_<int>(2,2)<<5,6,7,8);
 cv::Mat c = (cv::Mat_<int>(2,2)<<9,10,11,12);
 cv::Mat d = (cv::Mat_<int>(2,2)<<13,14,15,16);
 Mat combine,combine1,combine2;
 hconcat(a,b,combine1);
 hconcat(c,d,combine2);
 vconcat(combine1,combine2,combine);
 //namedWindow("Combine",CV_WINDOW_AUTOSIZE);
 //imshow("Combine",combine);
 cout<<"Combine=:"<<combine<<endl;
 system("pause");
 return 0;
}

結(jié)果:

圖像拼接實(shí)現(xiàn)

#include <iostream>
#include <core/core.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>
using namespace std;
using namespace cv;
int main()
{
 //cv::Mat a = (cv::Mat_<int>(2,2)<<1,2,3,4);
 //cv::Mat b = (cv::Mat_<int>(2,2)<<5,6,7,8);
 //cv::Mat c = (cv::Mat_<int>(2,2)<<9,10,11,12);
 //cv::Mat d = (cv::Mat_<int>(2,2)<<13,14,15,16);
 Mat combine,combine1,combine2;
 Mat a=imread("1.jpg");
 Mat b=imread("2.jpg");
 Mat c=imread("3.jpg");
 Mat d=imread("4.jpg");
 hconcat(a,b,combine1);
 hconcat(c,d,combine2);
 vconcat(combine1,combine2,combine);
 namedWindow("Combine",CV_WINDOW_AUTOSIZE);
 imshow("Combine",combine);
 waitKey(0);
 //cout<<"Combine=:"<<combine<<endl;
 system("pause");
 return 0;
}

圖像結(jié)果顯示如下:

以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持我們。

上一篇:如何寫出優(yōu)美的C語言代碼

欄    目:C語言

下一篇:C++小知識(shí):盡可能使用枚舉類

本文標(biāo)題:OpenCV實(shí)現(xiàn)多圖像拼接成一張大圖

本文地址:http://m.jygsgssxh.com/a1/Cyuyan/517.html

網(wǎng)頁制作CMS教程網(wǎng)絡(luò)編程軟件編程腳本語言數(shù)據(jù)庫服務(wù)器

如果侵犯了您的權(quán)利,請(qǐng)與我們聯(lián)系,我們將在24小時(shí)內(nèi)進(jìn)行處理、任何非本站因素導(dǎo)致的法律后果,本站均不負(fù)任何責(zé)任。

聯(lián)系QQ:835971066 | 郵箱:835971066#qq.com(#換成@)

Copyright © 2002-2020 腳本教程網(wǎng) 版權(quán)所有