当前位置:网站首页>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
边栏推荐
- 基于ele封装下拉菜单等组件
- Redis data server / database / cache (2022)
- 第46届ICPC亚洲区域赛(昆明) B Blocks(容斥+子集和DP+期望DP)
- Flink stream processing engine system learning (I)
- L2-006 樹的遍曆(中後序確定二叉樹&層序遍曆)
- Winsock programming interface experiment: implementation of ipconfig
- Log4j knowledge point record
- When using art template inheritance, compileerror: invalid or unexpected token generated
- 解决win7 中powershell挖矿占用CPU100%
- Store consumption SMS notification template
猜你喜欢
Flink learning (XI) watermark
Modification du contenu de la recherche dans la boîte déroulante par PHP + MySQL
Machine learning (Zhou Zhihua) Chapter 14 probability graph model
Linux redis - redis database caching service
leangoo脑图-共享式多人协作思维导图工具分享
Rhcsa day 1 operation
Source code and some understanding of employee management system based on polymorphism
Intelligent agricultural management model
基于Scrum进行创新和管理
LeetCode 1450 - 1453
随机推荐
JZ76 删除链表中重复的结点
Those years can not do math problems, using pyhon only takes 1 minute?
Efficient music format conversion tool Music Converter Pro
The second day of learning rhcsa
Day 4 of learning rhcsa
学习正则表达式选项、断言
Linux Redis——Redis 数据库缓存服务
TypeScript(1)
Log cutting - build a remote log collection server
Rhcsa second day operation
Flink stream processing engine system learning (II)
C language 171 Number of recent palindromes
The interface request takes too long. Jstack observes the lock holding
Essential qualities of advanced programmers
Chapter VI project information management system summary
Devil cold rice 𞓜 078 devil answers the market in Shanghai and Nanjing; Communication and guidance; Winning the country and killing and screening; The purpose of making money; Change other people's op
mysql function函数语法
Domestic lightweight Kanban scrum agile project management tool
Slave should be able to synchronize with the master in tests/integration/replication-psync.tcl
Learn regular expression options, assertions