当前位置:网站首页>[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);
}
边栏推荐
- Mapping settings in elk (8) es
- Analyzing the hands-on building tutorial in children's programming
- Typescript function details
- Basic differences between Oracle and MySQL (entry level)
- List of common bugs in software testing
- Idea automatic package import and automatic package deletion settings
- Learn AI safety monitoring project from zero [attach detailed code]
- geotrust ov多域名ssl證書一年兩千一百元包含幾個域名?
- 初学爬虫-笔趣阁爬虫
- What are the rules and trading hours of agricultural futures contracts? How much is the handling fee deposit?
猜你喜欢

Rhcsa --- work on the third day

正大美欧4的主账户关注什么数据?

Getting started with pytest -- description of fixture parameters

记录一次Unity 2020.3.31f1的bug

Realize the function of data uploading

Cannot activate CONDA virtual environment in vscode

正大留4的主账户信息汇总

Analyzing the hands-on building tutorial in children's programming

Getting started with pytest ----- confitest Application of PY

LM09丨费雪逆变换反转网格策略
随机推荐
Getting started with pytest ----- confitest Application of PY
LM09丨费雪逆变换反转网格策略
C# 基于MQTTNet的服务端与客户端通信案例
【ClickHouse】How to create index for Map Type Column or one key of it?
Record the bug of unity 2020.3.31f1 once
Online incremental migration of DM database
Introduction to Luogu 3 [circular structure] problem list solution
数学知识——快速幂的理解及例题
Starting from the classification of database, I understand the map database
Mouse events in JS
2022-003arts: recursive routine of binary tree
Mysql重点难题(2)汇总
Let正版短信测压开源源码
Idea automatic package import and automatic package deletion settings
LeetCode-归并排序链表
Flag bits in assembly language: CF, PF, AF, ZF, SF, TF, if, DF, of
Mathematical knowledge (Euler function)
DJB Hash
Detailed process of DC-1 range construction and penetration practice (DC range Series)
Cubemx DMA notes