我只想保存我使用mask_rcnn的图像的一部分例如,我想从test.jpg中仅提取bag类,并使用python imagecrop获得仅包含bag的图像,但是代码太复杂了,无法知道。
# Load a random image from the images folder
file_names = next(os.walk(IMAGE_DIR))[2]
image = skimage.io.imread(os.path.join(IMAGE_DIR, "test2.jpg"))
# Run detection
results = model.detect([image], verbose=1)
# Visualize results
r = results[0]
visualize.display_instances(image, r['rois'], r['masks'], r['class_ids'],
class_names, r['scores'])
仅打印一个文件包并将其保存在名为test.jpg的文件中。通过使用pythoncrop
您可以通过编辑visualize.py保存图像并插入 代码后的plt.savefig('your_desired_path_to_image.jpg',bbox_inches='tight', pad_inches=-0.5,orientation= 'landscape')
ax.imshow(masked_image.astype(np.uint8))
在此处找到链接https://github.com/matterport/Mask_RCNN/issues/134