2、修改代码位置:visualize.py 文件中的大约150行
# Mask
mask = masks[:, :, i]
if show_mask:
masked_image = apply_mask(masked_image, mask, color)
#########保存mask图片############
directory_name = "./pic/c_dedicate/save_mask" # 所要保存文件夹的路径
if not os.path.exists(directory_name):
os.mkdir(directory_name)
cv2.imwrite(directory_name + "/" + str(indexa) + '.png', mask * 255)
indexa = indexa + 1
#########保存mask图片############
# Mask Polygon
# Pad to ensure proper polygons for masks that touch image edges.
padded_mask = np.zeros(
(mask.shape[0] + 2, mask.shape[1] + 2), dtype=np.uint8)
padded_mask[1:-1, 1:-1] = mask
contours = find_contours(padded_mask, 0.5)
for verts in contours:
# Subtract the padding and flip (y, x) to (x, y)
verts = np.fliplr(verts) - 1
p = Polygon(verts, facecolor="none", edgecolor=color)
ax.add_patch(p)
ax.imshow(masked_image.astype(np.uint8))
# cv2.imwrite('./out.bmp', masked_image.astype(np.uint8))
if auto_show:
directory_name2 = "./pic/c_dedicate/save_out"
if not os.path.exists(directory_name2):
os.mkdir(directory_name2)
plt.savefig(directory_name2 + "/" + "1.png")
# plt.show() # 显示标记的图片
return boxes
3、效果:
原图
识别结果
每一个目标的掩膜保存到本地文件
版权声明:本文为qq_24801475原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。