当前位置:网站首页>《opencv学习笔记》-- 感兴趣区域(ROI)、图像混合
《opencv学习笔记》-- 感兴趣区域(ROI)、图像混合
2022-06-24 10:00:00 【cc_rong】
目录
感兴趣区域(ROI)
在图像中选择一个区域。
定义ROI区域的方法有两种形式:
方法一:
使用Rect,指定左上角坐标以及矩形的长宽
Mat roi = image(Rect(100, 100, 250, 250));image是已经载入的图像。
方法二:
指定感兴趣区域的行和列的范围
Mat roi = image(Range(20, 150), Range(30, 300));Range:指从其实索引到终止索引的连续序列
显示效果:
代码:
#include <iostream> #include "opencv2/opencv.hpp" using namespace cv; int main() { cv::Mat image = imread("E:\\roi_test.png"); cv::imshow("源图", image); cv::Mat roi = image(Range(30, 280), Range(60, 300)); cv::imshow("roi", roi); cv::waitKey(0); return 0; }
图像混合
先指定ROI,在用addweighted对指定的ROI区域的图像进行混合的操作。
线性混合操作是一种典型的二元的像素操作,理论公式为:
g(x) = (1 - a)F1(x) + aF2(x)
a代表alpha的值(0.0~1.0),对两幅图像(F1(x)和F2(x))或两段视频(F1(x)和F2(x))产生时间上的画面叠化效果,前面页面切换至后面页面的一种叠加效果。
实现方式:addWeighted函数:计算两个数组(图像阵列)的加权和
void addWeighted(InputArray src1, double alpha, InputArray src2, double beta, double gamma, OutputArray dst, int dtype = -1);参数1,InputArray类型的src1,表示需要加权的第一个数组;
参数2,double类型的alpha,表示src1的权重;
参数3,InputArray类型的src2,表示第二个数组,它需要和src1拥有相同的尺寸和通道数;
参数4,double类型的beta,表示src2的权重值;
参数5,double类型的gamma,一个加到权重总和上的标量值。
参数6,OutputArray类型的 dst,输出的数组,它和输入的两个数组拥有相同的尺寸和通道 数;
参数7,int类型的dtype,输出阵列的可选深度,有默认值-1。当两个输入数组具有相同的深 度时,这个参数设置为-1(默认值),即等同于src1.depth()。
两个数组 (src1和src2 ) 的加权和: 对 addWeighted 参数中 beta 位为 1 - alpha
gamma 位为0
dst = src1[ i ] * alpha + src2[ i ] * beta + gamma;
i:多维数组元素的索引值,再多通道数组的情况下,每一个通道需要独立处理。当输入数组的深度为CV_32S时,此函数不适用。
显示效果:
代码:
Mat srcImg1; Mat srcImg2; Mat srcImg3; srcImg1 = imread("E:\\img\\logo3.png"); srcImg2 = imread("E:\\img\\logo4.png"); imshow("源图srcImg1", srcImg1); imshow("源图srcImg2", srcImg2); addWeighted(srcImg1, 0.5, srcImg2, 0.5, 0.0, srcImg3); imshow("混合的srcImg3", srcImg3);也可以指定roi之后,再将图片中的某个区域进行混合。
边栏推荐
- 突然想到老家的木屋
- 历史上的今天:图灵诞生日;互联网奠基人出生;Reddit 上线
- Plant growth H5 animation JS special effect
- Turn 2D photos into 3D models to see NVIDIA's new AI "magic"!
- Maui的学习之路 -- 开篇
- A method of generating non repeated numbers in nodejs
- 程序员大部分时间不是写代码,而是。。。
- Rising bubble canvas breaking animation JS special effect
- Libuv的安装及运行使用
- P5.js paper crane animation background JS special effect
猜你喜欢

脚本之美│VBS 入门交互实战

"One good programmer is worth five ordinary programmers!"

齐次坐标的理解

Cool interactive animation JS special effects implemented by p5.js

MYSQL_ Elaborate on database data types

初识string+简单用法(一)

A group of skeletons flying canvas animation JS special effect

Visual presentation of pictures effectively enhances the attraction of large screen

SQL Server about like operator (including the problem of field data automatically filling in spaces)

Canvas pipe animation JS special effect
随机推荐
System design: load balancing
How to improve the quality of Baidu keyword?
Centripetalnet: more reasonable corner matching, improved cornernet | CVPR 2020 in many aspects
Visual presentation of pictures effectively enhances the attraction of large screen
Cook a delicious cli
初识string+简单用法(一)
Libuv的安装及运行使用
Today's sleep quality record 76 points
Today in history: Turing's birth day; The birth of the founder of the Internet; Reddit goes online
腾讯开源项目「应龙」成Apache顶级项目:前身长期服务微信支付,能hold住百万亿级数据流处理...
MYSQL_精讲数据库数据类型
8 types of API automated testing that technicians must know
Many of my friends asked me what books and online classes I recommended. This time, I contributed all the materials that I had been hiding for a long time (Part 1)
[net action!] Cos data escort helps SMEs avoid content security risks!
Opencv optical flow prediction and remap remapping function usage
It's so difficult for me. Have you met these interview questions?
Cool interactive animation JS special effects implemented by p5.js
如何只导出word文档中的标题?(即将正文内容都删除,只保留标题)B站牛逼
Fashionable pop-up mode login registration window
Moving Tencent to the cloud cured their technical anxiety



