我想遮盖轮廓内的区域。我的一段代码如下:
cnt = np.array(list((y, x) for x in X for y in Y))
mask = np.zeros(np.shape(b_contour_map),np.uint8)
cv2.drawContours(mask,[cnt],0,1)
我基于点坐标的两个向量创建 cnt,打印时它看起来像这样:
[[252 251]
[252 251]
[252 251]
...,
[249 251]
[249 251]
[252 251]]
而b_contour_map是包含结构轮廓点的图像。 当我显示掩码时,我得到了结构的边界框,但我只需要知道结构不规则轮廓内的点(由 cnt 定义)。有办法吗?
最佳答案
事实证明,点的顺序是个问题。我通过实现得到了正确的结果:
cnt = zip(Y, X)
cnt.sort(key=lambda x: (-x[0], x[[1]]))
maskIm = Image.new('L', (b_contour_map.shape[[1]], b_contour_map.shape[0]), 0)
ImageDraw.Draw(maskIm).polygon(cnt, outline=1, fill=1)
mask = np.array(maskIm) <p>
关于python - python中的不规则区域掩码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38646270/