当前位置:网站首页>[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);
}
边栏推荐
- Rhcsa --- work on the third day
- Oracle stored procedure and job task setting
- Pit encountered in win11 pytorch GPU installation
- Markdown edit syntax
- Interview question: do you know the difference between deep copy and shallow copy? What is a reference copy?
- Thinkphp内核工单系统源码商业开源版 多用户+多客服+短信+邮件通知
- LeetCode-对链表进行插入排序
- Domestic all Chinese automatic test software apifox
- MySQL table insert Chinese change? Solution to the problem of No
- Comp 250 parsing
猜你喜欢

Its appearance makes competitors tremble. Interpretation of Sony vision-s 02 products

Promise all()

Mysql表insert中文变?号的问题解决办法

Tawang food industry insight | current situation, consumption data and trend analysis of domestic infant complementary food market

Go Chan's underlying principles

How do I interview for a successful software testing position? If you want to get a high salary, you must see the offer

Typescript function details

Record the bug of unity 2020.3.31f1 once

DC-1靶场搭建及渗透实战详细过程(DC靶场系列)

Win10 disk management compressed volume cannot be started
随机推荐
Analyze the space occupied by the table according to segments, clusters and pages
解决:代理抛出异常错误
Learn BeanShell before you dare to say you know JMeter
Leetcode basic programming: array
Social media search engine optimization and its importance
Express logistics quick query method, set the unsigned doc No. to refresh and query automatically
Markdown edit syntax
解析少儿编程中的动手搭建教程
Cache consistency solution - how to ensure the consistency between the cache and the data in the database when changing data
Common errors of dmrman offline backup
One step implementation of yolox helmet detection (combined with oak intelligent depth camera)
农业生态领域智能机器人的应用
What data does the main account of Zhengda Meiou 4 pay attention to?
JS interview collection test question 1
面试会问的 Promise.all()
Mysql database learning
Flag bits in assembly language: CF, PF, AF, ZF, SF, TF, if, DF, of
Markdown编辑语法
ThinkPHP kernel work order system source code commercial open source version multi user + multi customer service + SMS + email notification
Go GC garbage collection notes (three color mark)