当前位置:网站首页>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]
边栏推荐
猜你喜欢

Understanding of distributed transactions

In unity3d, billboard effect can be realized towards another target

MySQL 主从,6 分钟带你掌握

Guns framework multi data source configuration without modifying the configuration file

SQLite cross compile dynamic library

Simulateur nightGod ADB View log

Getting started with houdininengine HDA and UE4

Directx11 advanced tutorial tiled based deffered shading

Annotation configuration of filter

First note
随机推荐
Pytorch implementation of regression model
Unity custom translucent surface material shader
sqlite交叉编译动态库
BRDF of directx11 advanced tutorial PBR (2)
Poisson disk sampling for procedural placement
. Net core and Net framework comparison
n次贝塞尔曲线
The application could not be installed: INSTALL_ FAILED_ TEST_ ONLY
[untitled]
哈工大信息内容安全实验
三年磨一剑:蚂蚁金服的研发效能洞察实践
Login authentication filter
IBL of directx11 advanced tutorial PBR (3)
Leetcode-1535. Find the winner of the array game
摄像头拍摄运动物体,产生运动模糊/拖影的原因分析
E-book analysis
Project management and overall planning
[PowerShell] command line output and adding system environment variables
Sqlite Cross - compile Dynamic Library
UE4 4.27 modify the mobile forward pipeline to support cluster multi light source culling