当前位置:网站首页>Opencv fills the rectangle with a transparent color
Opencv fills the rectangle with a transparent color
2022-04-23 02:54:00 【1900_】
Fill an irregular figure in an image
Fixed color fill
use cv2.fillPoly function
img = cv2.imread('./001.png')
area = np.array([[1000, 200], [1500, 200], [1500, 400], [1000, 400]])
cv2.fillPoly(img,[area], color=(255, 255, 255))
The effect is as shown in the picture , There can be multiple area Coordinate group , Set the color yourself

Transparent color fill
There is no function dedicated to filling transparent colors
But we can use image fusion cv2.addWeighted
( Note that this method can only fill the rectangle with transparent color , Irregular shapes cannot )
import cv2
import numpy as np
img = cv2.imread('./001.png')
# Create a three channel image The image size can be set by yourself np.zeros(H,W,C)
create_green = np.zeros((100,100,3),dtype=np.uint8)
# Set the color values of the three channels of the image
# img[ y: y+h , x : x+w ] Split the image
# numpy yes BGR So the first 0 The first channel is B Blue 1 yes G green 2 yes R Red
create_green[:,:,0] = 0
create_green[:,:,1] = 255 # Here I create a pure green image
create_green[:,:,2] = 0
# Image fusion The two images must be the same size to merge 0.7 and 0.3 Is the parameter
# The formula for adding images is R=a*x1+b*x2+c x1 x2 Represents two images a b Two parameters c Is a bias item.
# The fusion degree parameter can be adjusted To control “ transparency ”
img_add = cv2.addWeighted(img[100:200,100:200], 0.7 ,create_green, 0.3, 0)
# The fused image is then put back to the original
img[100:200,100:200] = img_add
# Show it after modifying the size
h_h = img.shape[0]
w_w = img.shape[1]
resize = cv2.resize(img,( int(w_w / 2) ,int(h_h / 2) ) ,interpolation = cv2.INTER_CUBIC)
cv2.imshow("test",resize)
cv2.waitKey(0)
The effect is as follows :

版权声明
本文为[1900_]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204220658376329.html
边栏推荐
- The express project changes the jade template to art template
- Six very 6 computer driver managers: what software is good for driver upgrade? Recommended by the best computer driver management software abroad
- VirtualBox virtual machine (Oracle VM)
- Chapter VI project information management system summary
- Actual combat of industrial defect detection project (IV) -- ceramic defect detection based on hrnet
- 基于ele封装下拉菜单等组件
- Modification du contenu de la recherche dans la boîte déroulante par PHP + MySQL
- TypeScript(1)
- JS using the parameters of art template
- Day 4 of learning rhcsa
猜你喜欢

grain rain

Six very 6 computer driver managers: what software is good for driver upgrade? Recommended by the best computer driver management software abroad

【Hcip】OSPF常用的6种LSA详解

Implementation of distributed scenario business operation log (based on redis lightweight)

Error installing Mongo service 'mongodb server' on win10 failed to start

Those years can not do math problems, using pyhon only takes 1 minute?

Fashion MNIST dataset classification training

Windows MySQL 8 zip installation

国产轻量级看板式Scrum敏捷项目管理工具

Shell script learning notes - regular expressions
随机推荐
Day 4 of learning rhcsa
Six very 6 computer driver managers: what software is good for driver upgrade? Recommended by the best computer driver management software abroad
L2-006 樹的遍曆(中後序確定二叉樹&層序遍曆)
基于ele封装下拉菜单等组件
ROP Emporium x86_64 7~8题
L2-006 树的遍历(中后序确定二叉树&层序遍历)
grain rain
Domestic lightweight Kanban scrum agile project management tool
Traversal of l2-006 tree (middle and later order determination binary tree & sequence traversal)
php+mysql对下拉框搜索的内容修改
Shell script learning notes - regular expressions
win查看端口占用 命令行
Flink stream processing engine system learning (I)
[wechat applet] set the bottom menu (tabbar) for the applet
MySQL复杂查询使用临时表/with as(类似表变量)
Efficient music format conversion tool Music Converter Pro
Mosaic Routing: implement / home / news
Planning code ROS migration POMDP prediction planning (I)
Fashion MNIST dataset classification training
Face longitude: