当前位置:网站首页>Opencv learning notes - regions of interest (ROI) and image blending
Opencv learning notes - regions of interest (ROI) and image blending
2022-06-24 12:05:00 【cc_ rong】
Catalog
Region of interest (ROI)
Select an area in the image .
Definition ROI Area There are two forms of methods :
Method 1 :
Use Rect, Specify the coordinates of the upper left corner and the length and width of the rectangle
Mat roi = image(Rect(100, 100, 250, 250));image Is the loaded image .
Method 2 :
Specify the... Of the region of interest Range of rows and columns
Mat roi = image(Range(20, 150), Range(30, 300));Range: From the actual index to the end of the index A continuous sequence
According to the effect :
Code :
#include <iostream> #include "opencv2/opencv.hpp" using namespace cv; int main() { cv::Mat image = imread("E:\\roi_test.png"); cv::imshow(" Source graph ", image); cv::Mat roi = image(Range(30, 280), Range(60, 300)); cv::imshow("roi", roi); cv::waitKey(0); return 0; }
Image blending
First specify ROI, In use addweighted For the specified ROI The image of the region is mixed .
Linear blending is a typical binary pixel operation , The theoretical formula is :
g(x) = (1 - a)F1(x) + aF2(x)
a representative alpha Value (0.0~1.0), For two images (F1(x) and F2(x)) Or two videos (F1(x) and F2(x)) To produce the effect of overlapping pictures in time , A superimposed effect of switching from the front page to the back page .
Realization way :addWeighted function : Calculate two arrays ( Image array ) Weighted sum of
void addWeighted(InputArray src1, double alpha, InputArray src2, double beta, double gamma, OutputArray dst, int dtype = -1);Parameters 1,InputArray Type of src1, Represents the first array to be weighted ;
Parameters 2,double Type of alpha, Express src1 The weight of ;
Parameters 3,InputArray Type of src2, Represents the second array , It needs and src1 Have Same size and number of channels ;
Parameters 4,double Type of beta, Express src2 The weight value of ;
Parameters 5,double Type of gamma, A scalar value added to the sum of the weights .
Parameters 6,OutputArray Type of dst, Output array , It has the same size and channel as the two input arrays Count ;
Parameters 7,int Type of dtype, Optional depth of output array , Have default values -1. When two input arrays have the same depth When the degree of , This parameter is set to -1( The default value is ), That is equivalent to src1.depth().
Two arrays (src1 and src2 ) Weighted sum of : Yes addWeighted Parameters in beta Position as 1 - alpha
gamma Position as 0
dst = src1[ i ] * alpha + src2[ i ] * beta + gamma;
i: Index values of multidimensional array elements , In the case of multi-channel arrays , Each channel needs to be handled independently . When the depth of the input array is CV_32S when , This function does not apply .
According to the effect :
Code :
Mat srcImg1; Mat srcImg2; Mat srcImg3; srcImg1 = imread("E:\\img\\logo3.png"); srcImg2 = imread("E:\\img\\logo4.png"); imshow(" Source graph srcImg1", srcImg1); imshow(" Source graph srcImg2", srcImg2); addWeighted(srcImg1, 0.5, srcImg2, 0.5, 0.0, srcImg3); imshow(" Mixed srcImg3", srcImg3);You can also specify roi after , Then mix a certain area in the picture .
边栏推荐
- LS-DYNA beginner's experience
- Influence of DEX optimization on arouter lookup path
- [go language questions] go from 0 to entry 4: advanced usage of slice, elementary review and introduction to map
- Why choose b+ tree as storage engine index structure
- @Requestbody annotation
- Group counting_ Structure and workflow of CPU
- 巧妙构思-铁死亡调节因子分型预后发6+
- 08. Tencent cloud IOT device side learning - device shadow and attributes
- TP-LINK 1208路由器教程(2)
- 《opencv学习笔记》-- 图像的载入和保存
猜你喜欢

Ten thousand campus developers play AI in a fancy way. It's enough to see this picture!
![[go language questions] go from 0 to entry 4: advanced usage of slice, elementary review and introduction to map](/img/7a/16b481753d7d57f50dc8787eec8a1a.png)
[go language questions] go from 0 to entry 4: advanced usage of slice, elementary review and introduction to map

Libuv的安装及运行使用

GTest从入门到入门

FreeRTOS概述与体验

GLOG从入门到入门

电商红包雨是如何实现的?拿去面试用(典型高并发)

FreeRTOS overview and experience

【Go语言刷题篇】Go从0到入门4:切片的高级用法、初级复习与Map入门学习

Linker --- linker
随机推荐
怎样申购打新债 开户是安全的吗
C语言循环语句介绍(foe、while、do...while)
The latest hot spot: the use of copper death related genes for tumor prognosis typing!
Chenglixin research group of Shenzhen People's hospital proposed a new method of multi group data in the diagnosis and prognosis analysis of hepatocellular carcinoma megps
Is it safe to open an account under the conditions of new bonds
Give you a server. Can you deploy your code online?
Understanding of homogeneous coordinates
11+ article - machine learning builds Protics framework - deeply reveals the impact of tumor infiltrating immune cells in different molecular subtypes on prognosis
Ten thousand campus developers play AI in a fancy way. It's enough to see this picture!
怎么申请打新债 开户是安全的吗
ArrayList#subList这四个坑,一不小心就中招
[Flink source code practice (I)] add a rest API to Flink
How to open a new bond? Is it safe to open an account
Nacos source code - Interface read configuration
软件测试 对前一日函数的基本路径测试
9+! Predicting lymph node status from histology of colorectal cancer by deep learning
Istio best practice: graceful termination
Audio knowledge (III) -- MFCCs code implementation
The idea of "6 points + gene family" without experiment~
How is the e-commerce red envelope realized? For interview (typical high concurrency)



