当前位置:网站首页>[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);
}
边栏推荐
- Realize the function of data uploading
- Cache consistency solution - how to ensure the consistency between the cache and the data in the database when changing data
- idea自动导包和自动删包设置
- 2022 Alibaba global mathematics competition, question 4, huhushengwei (blind box problem, truck problem) solution ideas
- Cubemx DMA notes
- Summary of database problems
- Future trend of automated testing ----- self healing technology
- Typescript function details
- Lay the foundation for children's programming to become a basic discipline
- What are the rules and trading hours of agricultural futures contracts? How much is the handling fee deposit?
猜你喜欢
Learn BeanShell before you dare to say you know JMeter
Markdown edit syntax
Getting started with pytest ----- confitest Application of PY
農業生態領域智能機器人的應用
Practical problem solving ability of steam Education
Promise all()
CubeMx DMA笔记
Tawang food industry insight | current situation, consumption data and trend analysis of domestic infant complementary food market
数学问题(数论)试除法做质数的判断、分解质因数,筛质数
Lm09 Fisher inverse transform inversion mesh strategy
随机推荐
Application of intelligent robot in agricultural ecology
Its appearance makes competitors tremble. Interpretation of Sony vision-s 02 products
TypeScript函数详解
Acelems Expressway microgrid energy efficiency management platform and intelligent lighting solution intelligent lighting tunnel
Summary of database problems
2022-003arts: recursive routine of binary tree
【ClickHouse】How to create index for Map Type Column or one key of it?
[Yu Yue education] autumn 2021 reference materials of Tongji University
06 decorator mode
C - derived classes and constructors
Mysql表insert中文变?号的问题解决办法
Analyze the space occupied by the table according to segments, clusters and pages
Video multiple effects production, fade in effect and border background are added at the same time
Vmware安装win10报错:operating system not found
Realize the function of data uploading
Mathematical knowledge (Euler function)
6.30年终小结,学生时代结束
What are the rules and trading hours of agricultural futures contracts? How much is the handling fee deposit?
Practical problem solving ability of steam Education
Hcip day 17