当前位置:网站首页>Cv2.fillpoly coco annotator segment coordinate conversion to mask image
Cv2.fillpoly coco annotator segment coordinate conversion to mask image
2022-06-12 06:09:00 【Just change your name】
The following implements a split single channel mask Image generation .
One 、 About arr
1, arr Is a polygonal x y Coordinate array,
[144.7, 134.2] Is a point of this polygon x y coordinate .
arr2 It's from another polygon x y Coordinate array.
2, The data type should be set to np.int32, Otherwise, it will report a mistake .
3, Pass in fillPolly Add brackets before making parameters , Otherwise, it will report a mistake .
Two 、 About fillPoly
fillPoly Of color Parameters , If it is to generate a single channel , Just fill in the number ,
(255,0,0) No mistake. , But easy to follow 3 Channel confusion .
cv2 Of color yes brg The order of .
3、 ... and 、 About channel
We must unify ,
The generated image is a single channel ,
When reading in, it is also a single channel reading .
If it's generated 3 passageway ,
Read in is a single channel read in ,
The number read in will be wrong .
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)
# This sentence can also be used in the above two lines cv2.fillPoly(mask, [arr, arr2], color=255)
cv2.imwrite(os.path.join(pth, "2400.png"), mask)

Single channel read in code :
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]
边栏推荐
猜你喜欢

为什么数据库不使用二叉树、红黑树、B树、Hash表? 而是使用了B+树

Directx11 advanced tutorial tiled based deffered shading

Bert use

姿态估计之2D人体姿态估计 - PifPaf:Composite Fields for Human Pose Estimation

MySQL 主从,6 分钟带你掌握

Project technical structure

Simulateur nightGod ADB View log

Chartextcnn (Ag dataset - news topic classification)

(UE4 4.27) add globalshder to the plug-in

MNIST handwritten data recognition by CNN
随机推荐
RMB classification II
JS变量作用域
MLP sensor
Sqlite Cross - compile Dynamic Library
Leetcode sword finger offer II 033 Modified phrase
nus_data_handler源码解读结构体等数据类型
为什么联合索引是最左匹配原则?
Guns framework multi data source configuration without modifying the configuration file
. Net core and Net framework comparison
Word2Vec
Leetcode-1552. Magnetic force between two balls
A month's worth of DDD will help you master it
夜神模擬器adb查看log
关于 Sensor flicker/banding现象的解释
Leetcode-2048. Next larger numerical balance
Leetcode-1260. 2D mesh migration
Leetcode-1663. Minimum string with given value
Redis队列
zip 和.items()区别
Unity implements smooth interpolation