当前位置:网站首页>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
边栏推荐
- Face longitude:
- Implementation of distributed scenario business operation log (based on redis lightweight)
- Rhcsa day 4 operation
- Winsock programming interface experiment: Ping
- Restart redis
- 国产轻量级看板式Scrum敏捷项目管理工具
- @Usage and difference between mapper and @ repository
- Flink learning (XI) watermark
- mysql function函数语法
- Six very 6 computer driver managers: what software is good for driver upgrade? Recommended by the best computer driver management software abroad
猜你喜欢

Kubernetes study notes

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

ROP Emporium x86_64 7~8题

Flink stream processing engine system learning (II)

Innovation and management based on Scrum

L2-006 树的遍历(中后序确定二叉树&层序遍历)

C language 171 Number of recent palindromes

How big the program development of single chip microcomputer project can be, it represents your level of knocking code

First knowledge of C language ~ branch statements

国产轻量级看板式Scrum敏捷项目管理工具
随机推荐
Rhcsa second day operation
Configuring Apache Web services for servers such as Tianyi cloud
MySQL insert free column
Shell script learning notes -- shell operation on files sed
L2-006 树的遍历(中后序确定二叉树&层序遍历)
Reverse a linked list < difficulty coefficient >
ROP Emporium x86_64 7~8题
C语言 171. 最近回文数
When using art template inheritance, compileerror: invalid or unexpected token generated
Redis data server / database / cache (2022)
grain rain
Android 高阶面试必问:全局业务和项目的架构设计与重构
Les derniers noeuds K de la liste jz22
接口请求时间太长,jstack观察锁持有情况
Airtrack cracking wireless network password (Dictionary running method)
Fashion MNIST dataset classification training
The shell monitors the depth of the IBM MQ queue and scans it three times in 10s. When the depth value exceeds 5 for more than two times, the queue name and depth value are output.
Linux Redis——Redis 数据库缓存服务
Close the computer port
leangoo脑图-共享式多人协作思维导图工具分享