【发布时间】:2021-11-02 02:45:32
【问题描述】:
我想计算一个匀称的多边形和一个掩码(numpy.array)的交集面积:
plt.plot(*building.exterior.xy, color='brown', linewidth=4)
plt.plot(*parcelle.exterior.xy, color='orange', linewidth=4)
plt.imshow(thr, origin='upper', extent=[x_left, x_right, y_bottom, y_top], cmap='Greys')
我希望能够计算下面的绿色区域:
为此,我尝试使用此处描述的方法:How to transform contours obtained from OpenCV to SHP file polygons?
mask_to_polygons(np.flip(thr, 0))
plt.plot(*parcelle.exterior.xy)
plt.plot(*building.exterior.xy)
mask_pol = translate(mask_to_polygons(np.flip(thr, 0)), x_left, y_bottom)
for geo in mask_pol:
plt.plot(*geo.exterior.xy, color = 'green')
确实,MultiPolygon mask_pol 的边界不是 thr 数组的维度:
> mask_pol.bounds
(0.0, 0.0, 511.0, 511.0)
> thr.shape
(256, 256)
所以,我想知道从掩码切换到多项式的选项是否正确。我也可以尝试从匀称多项式切换到掩码。有没有更好的方法来完成这项任务?
【问题讨论】:
标签: python numpy opencv matplotlib shapely