我有一些代码可以打印出坐标列表(存储在点中)
f=open('139cm_2000_frame27.json')
data=json.load(f)
shapes=data["shapes"]
for i in shapes:
print(i['label']) # prints the label first
for c in i['points']:
d=np.array(c)
print(d) # an array containing coordinates in the form (x,y)
d、 坐标是n个10边多边形的点.坐标0-9是第一个多边形的坐标,坐标10-19是第二个多边形...
json文件中可以有任意数量的多边形,但每个多边形始终有10个坐标.
我需要找到一种方法,使用这些坐标在128x128数组中"绘制"或"重建"这些多边形.
我试过了
from skimage.draw import polygon
img = np.zeros((128, 128), dtype=np.uint8)
r = np.array([#the x coordinates of d])
c = np.array([#the y coordinates of d])
rr, cc = polygon(r, c)
img[rr, cc] = 1 #unsure about the 1
img
但我不知道如何1)获得10个坐标集,2)将xs读入r,将ys读入c
非常感谢!
输入json的一个示例:
{
"version": "4.6.0",
"flags": {},
"shapes": [
{
"label": "blob",
"points": [
[
61.42857142857143,
20.285714285714285
],
[
59.10047478151446,
18.879430437885873
],
[
58.04359793578868,
16.37330203102605
],
[
58.661631924538575,
13.724584936383643
],
[
60.71850877026435,
11.94499905752918
],
[
63.42857142857143,
11.714285714285715
],
[
65.75666807562841,
13.120569562114127
],
[
66.81354492135418,
15.62669796897395
],
[
66.19551093260428,
18.275415063616357
],
[
64.13863408687851,
20.05500094247082
]
],
"group_id": null,
"shape_type": "polygon",
"flags": {}
},
{
"label": "blob",
"points": [
[
88.71428571428572,
82.42857142857143
],
[
85.63470409582908,
81.33512050565437
......