当前位置:网站首页>cv2.fillPoly coco annotator segment坐标转化为mask图像
cv2.fillPoly coco annotator segment坐标转化为mask图像
2022-06-12 06:03:00 【换个名字就很好】
以下实现分割的单通道mask图像的生成。
一、关于arr
1, arr是一个多边形的x y坐标的array,
[144.7, 134.2] 是这个多边形的一个点的x y坐标。
arr2是另一个多边形的 x y 坐标的array。
2, 数据类型要设置成np.int32, 不然会报错。
3,传入fillPolly做参数前要加中括号,不然会报错。
二、关于fillPoly
fillPoly 的color 参数,如果是生成单通道,填个数即可,
(255,0,0)不会报错,但是容易跟3通道的混淆。
cv2的color 是brg的顺序。
三、关于通道
一定要统一,
就是生成的图像是单通道,
读入的时候也是单通道读入。
如果生成的是3通道,
读入是单通道读入,
读入的数会不对。
import numpy as np
import cv2
import os
arr = np.array([[144.7, 134.2], [185.5, 132.3], [183.9, 149.6], [142.1, 150.0], [141.7, 143.0], [144.7, 137.3]], dtype=np.int32)
arr2 = np.array([[140.9, 183.4], [186.6, 181.1], [186.6, 188.8], [188.9, 198.4], [196.6, 220.3], [197.0, 236.4], [192.0, 246.0], [190.8, 255.2], [154.0, 257.9], [147.0, 216.8], [140.9, 198.0], [141.3, 183.8]], dtype=np.int32)
h, w = 288, 384
pth = r"F:\vscode_files\project\segment_side"
mask = np.zeros((h, w), dtype=np.int32)
cv2.fillPoly(mask, [arr], color=255)
cv2.fillPoly(mask, [arr2], color=255)
# 以上两行也可以用这一句代替 cv2.fillPoly(mask, [arr, arr2], color=255)
cv2.imwrite(os.path.join(pth, "2400.png"), mask)

单通道读入代码:
mask_img = cv2.imread(r"F:\vscode_files\project\segment_side\2400.png", cv2.IMREAD_GRAYSCALE)
print(mask_img.shape) # (288, 384)
print(mask_img)
list_ = []
for i in range(h):
for j in range(w):
if mask_img[i][j] not in list_:
list_.append(mask_img[i][j])
print(list_)
output:
(288, 384)
[[0 0 0 ... 0 0 0]
[0 0 0 ... 0 0 0]
[0 0 0 ... 0 0 0]
...
[0 0 0 ... 0 0 0]
[0 0 0 ... 0 0 0]
[0 0 0 ... 0 0 0]]
[0, 255]
边栏推荐
- Filter的注解配置
- Database Experiment 3: data query
- json-c常用API
- China embolic coil market trend report, technical innovation and market forecast
- Multiple ways 99.9% to solve the problem of garbled code after copying text from PDF
- Stack and queue classic interview questions
- 为什么联合索引是最左匹配原则?
- Leetcode-139. Word splitting
- Idea common configuration
- Unity VSCode不能跳转到定义
猜你喜欢

Three years of sharpening a sword: insight into the R & D efficiency of ant financial services

What is the lszrz protocol used at ordinary times? Talk about xmodem/ymodem/zmodem

The application could not be installed: INSTALL_FAILED_TEST_ONLY

EBook list page

TCP and UDP introduction

Project technical structure

E-book analysis

Makefile文件编写快速掌握

从传统网络IO 到 IO多路复用

Data integration framework seatunnel learning notes
随机推荐
China embolic coil market trend report, technical innovation and market forecast
RTMP streaming +rtmp playback low delay solution in unity environment
Un mois de DDD hépatique.
nrf52832--官方例程ble_app_uart添加led特性,实现电脑uart和手机app控制开发板led开和关
Error the main class com xxx. yyy. Application
Solution to the problem of the 80th fortnight competition of leetcode
肝了一個月的 DDD,一文帶你掌握
BRDF of directx11 advanced tutorial PBR (2)
Database Experiment 3: data query
C WMI query remote Win32_ Operatingsystem class
肝了一个月的 DDD,一文带你掌握
jpg格式与xml格式文件分离到不同的文件夹
Chapter 7 - pointer learning
Redis transaction
IO to IO multiplexing from traditional network
Leetcode sword finger offer II 119 Longest continuous sequence
Findasync and include LINQ statements - findasync and include LINQ statements
The application could not be installed: INSTALL_FAILED_TEST_ONLY
Leetcode-1705. Maximum number of apples to eat
Leetcode-1706. Where does the club fall