当前位置:网站首页>[quick view opencv] familiar with CV matrix operation with image splicing examples (3)
[quick view opencv] familiar with CV matrix operation with image splicing examples (3)
2022-07-02 04:58:00 【Water cut off passenger】
Be familiar with picture splicing examples CV Matrix operation (3)
Use the following code , It can realize the splicing operation of any two pictures
Previous section Be familiar with picture splicing examples CV Matrix operation (2)
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc.hpp>//resize
#include <opencv2/core/types.hpp>//rect
using namespace cv;
using std::endl;
using std::cout;
#define TIED_MODE_UAD 0
#define TIED_MOED_LAR 1
/** @brief Splicing operation , Put two equal sized pictures together seamlessly @arg src1 Source data 1 Matrix @arg src2 Source data 2 Matrix @arg mod Select splicing mode TIED_MODE_UAD:src1 On ,src2 Next TIED_MOED_LAR:src1 Left ,src2 Right @retval dst Splicing result data matrix **/
Mat Mat_Tied(Mat& src1, Mat src2,int mod)
{
cout << " data source 1 The size of the #"<<src1.rows << "&" << src1.cols << endl;
cout << " data source 2 The size of the #"<<src2.rows << "&" << src2.cols << endl;
/* Transform the image data into a matrix of equal size */
/* Align the big one to the small one */
cout << " Size alignment ..." << endl;
if (Mat_IsLarger(src1, src2)) {
resize(src1, src1, Size(src2.cols, src2.rows));
}
else {
resize(src2, src2, Size(src1.cols, src1.rows));
}
cout << " Data source after size alignment 1 The size of the #" << src1.rows << "&" << src1.cols << endl;
cout << " Data source after size alignment 2 The size of the #" << src2.rows << "&" << src2.cols << endl;
int _cols,_rows;
/* cout << src1.rows << "&" << src1.cols << endl; cout << src2.rows << "&" << src2.cols << endl*/;
_cols = (src1.cols > src2.cols) ? src1.cols
: src2.cols;
_rows = (src1.rows > src2.rows) ? src1.rows
: src2.rows;
Mat dstx((_rows*2), (_cols), src1.type());
Mat dstx2((_rows), (_cols*2), src1.type());
//cout << "dst rows&cols" << dstx.rows << "&" << dstx.cols << endl;
if (mod == TIED_MODE_UAD){
cout << " Press mode 1 Splicing ..." << endl;
for (int i = 0;i < dstx.rows;i++) {
for (int j = 0;j < dstx.cols;j++) {
if (i < src1.rows) {
if (j < src1.cols) {
for (int c = 0;c < src1.channels();c++)
dstx.at<Vec3b>(i, j)[c] = src1.at<Vec3b>(i, j)[c];
}
}
else if (i < src2.rows + src1.rows) {
if (j < src2.cols) {
for (int c = 0;c < src2.channels();c++)
dstx.at<Vec3b>(i, j)[c] = src2.at<Vec3b>(i - src1.rows, j)[c];
}
}
}
}
}
else if (mod == TIED_MOED_LAR) {
cout << " Press mode 2 Splicing ..." << endl;
for (int i = 0;i < dstx2.rows;i++) {
for (int j = 0;j < dstx2.cols;j++) {
if (j < src1.cols) {
if (i < src1.rows) {
for (int c = 0;c < src1.channels();c++)
dstx2.at<Vec3b>(i, j)[c] = src1.at<Vec3b>(i, j)[c];
}
}
else if (j < src2.cols + src1.cols) {
if (i < src2.rows) {
for (int c = 0;c < src2.channels();c++)
dstx2.at<Vec3b>(i, j)[c] = src2.at<Vec3b>(i, j - src1.rows)[c];
}
}
}
}
}
else {
cout << " The specified splicing mode does not exist " << endl;
goto deadline;
}
cout << "anyway done" << endl;
deadline:;
return ((mod == TIED_MODE_UAD)?dstx:dstx2);
}
边栏推荐
- Hcip day 17
- Mysql database learning
- C # picture display occupancy problem
- What data does the main account of Zhengda Meiou 4 pay attention to?
- Express logistics quick query method, set the unsigned doc No. to refresh and query automatically
- DJB Hash
- 案例分享|智慧化的西部机场
- [understand one article] FD_ Use of set
- Social media search engine optimization and its importance
- Rhcsa --- work on the third day
猜你喜欢
Introduction to Luogu 3 [circular structure] problem list solution
数学知识——快速幂的理解及例题
LeetCode-对链表进行插入排序
LM09丨费雪逆变换反转网格策略
Promise all()
cs架构下抓包的几种方法
Typescript function details
2022 Alibaba global mathematics competition, question 4, huhushengwei (blind box problem, truck problem) solution ideas
Social media search engine optimization and its importance
How to write a client-side technical solution
随机推荐
Beginner crawler - biqu Pavilion crawler
List of common bugs in software testing
Social media search engine optimization and its importance
[common error] the DDR type of FPGA device is selected incorrectly
Leetcode merge sort linked list
Hcip day 17
Starting from the classification of database, I understand the map database
oracle 存储过程与job任务设置
Line by line explanation of yolox source code of anchor free series network (7) -- obj in head_ loss、Cls_ Loss and reg_ Calculation and reverse transmission of loss I
Typescript function details
DJB Hash
Interview question: do you know the difference between deep copy and shallow copy? What is a reference copy?
What are the rules and trading hours of agricultural futures contracts? How much is the handling fee deposit?
Go GC garbage collection notes (three color mark)
将光盘中的cda保存到电脑中
C case of communication between server and client based on mqttnet
Vmware安装win10报错:operating system not found
数学知识(欧拉函数)
Mysql重点难题(2)汇总
Several methods of capturing packets under CS framework