当前位置:网站首页>《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之后,再将图片中的某个区域进行混合。
边栏推荐
- RPM installation percona5.7.34
- Cool interactive animation JS special effects implemented by p5.js
- Nxshell session management supports import and export
- 程序员大部分时间不是写代码,而是。。。
- Cause analysis of frequent crash and restart of easynvr-arm cloud terminal
- Internship experience sharing in ByteDance 𞓜 ten thousand word job guide
- What is a voice assistant? What will the future voice assistant look like?
- Which is a good CAD drawing software? How to select good software
- 如何只导出word文档中的标题?(即将正文内容都删除,只保留标题)B站牛逼
- The record of 1300+ times of listing and the pursuit of ultimate happiness
猜你喜欢

PHP SMS notification + voice broadcast automatic double call

A group of skeletons flying canvas animation JS special effect

齐次坐标的理解

Shape change loader loads jsjs special effect code

Canvas falling ball gravity JS special effect animation

喜歡就去行動

Qt: judge whether the string is in numeric format

使用Process Monitor工具监测进程对注册表和文件的操作

程序员大部分时间不是写代码,而是。。。

Rising bubble canvas breaking animation JS special effect
随机推荐
"Write once, run at all ends", Qualcomm released AI software stack!
Mongodb index operation
初识string+简单用法(一)
Self cleaning Manual of mining Trojan horse
Investing in a good navigation framework from the beginning of the jetpack compose tutorial will help you save a lot of migration work later
Lightweight deployment of firefoxsend temporary file sharing service using Tencent cloud
Today's sleep quality record 76 points
Multi gate mixture of experts and code implementation
[深度学习][pytorch][原创]crnn在高版本pytorch上训练loss为nan解决办法
Any and typevar make the automatic completion of IDE better
Clickhouse deployment and basic usage 1
SQL Server about like operator (including the problem of field data automatically filling in spaces)
Install wpr Exe command
How does easydss use go fastdfs distributed file servers to reduce service pressure?
8 types of API automated testing that technicians must know
历史上的今天:图灵诞生日;互联网奠基人出生;Reddit 上线
Beauty of script │ VBS introduction interactive practice
Virtual CD-ROM function how to use and install virtual CD-ROM
math_ Summation and derivation of proportional series & derivation of sum and difference of equal powers / difference between two nth power numbers/
System design: key features of distributed systems



