我有一个文本文件,其中的线条定义了几个多边形:
x1,y1,x2,y2,x3,y3,x4,y4
x1,y1,x2,y2,x3,y3,x4,y4
.
.
.
etc
我想把它们读到一个numpy数组与一个轴具有相同的形状的多边形(即。盒子)和其他人喜欢:
[x_min,y_min],[x_min,y_max],[x_max,y_max],[x_max,y_min]
其中x_min是最小x坐标,x_max是最大值等。
我可以读取并获得max和mins:
boxes_x = np.loadtxt(label_path,usecols=np.arange(0,8,2),dtype=int,delimiter=",")
boxes_y = np.loadtxt(label_path,usecols=np.arange(1,8,2),dtype=int,delimiter=",")
x_max = boxes_x[:].max(axis=1)
y_max = boxes_y[:].max(axis=1)
x_min = boxes_x[:].min(axis=1)
y_min = boxes_y[:].min(axis=1)
但将它们塑造成正确的形状,即[num_boxes,4,2],证明是困难的。
最好的方法是什么?
1条答案
按热度按时间unhi4e5o1#
立即将文件读入
boxes
:假设
boxes
表示4个条目(多边形):分别为 x 和 y 坐标找到
min
和max
:构建所需结构和形状的输出数组:
样品输出: