我有以下格式的串列中的坐標:
[572.71063 453.9848 622.2049 472.86023]
其中四個數字分別對應一個矩形的 X1, Y1, X2, Y2 坐標。(X1,Y1 左上角,X2,Y2 右下角)。
我想將串列項轉換為“勻稱”多邊形。串列項的格式不正確,在這種情況下,Polygon 可以作業。所以我使用了以下功能
brd = Polygon(map(np.squeeze, bb))
這沒用。我認為矩形坐標的問題實際上不是輪廓格式。我認為輪廓應該是接近的。
我可以將串列中的矩形坐標轉換為形狀多邊形的最佳方法是什么?
uj5u.com熱心網友回復:
如果我理解問題,你只需要這個:
rect = [572.71063, 453.9848, 622.2049, 472.86023]
X1, Y1, X2, Y2 = rect
polygon = [(X1, Y1), (X2, Y1), (X2, Y2), (X1, Y2)]
編輯:
最小作業代碼:
from shapely.geometry import Polygon
import matplotlib.pyplot as plt
rect = [572.71063, 453.9848, 622.2049, 472.86023]
X1, Y1, X2, Y2 = rect
polygon = [(X1, Y1), (X2, Y1), (X2, Y2), (X1, Y2)]
p = Polygon(polygon)
x, y = p.exterior.xy
plt.plot(x, y)
plt.show()
結果:

轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/479039.html
上一篇:使用OpenCV在GoogleColab中顯示流影像
下一篇:如何在python中繪制邏輯矩陣
