图像中的Scipy绘制边界框

J

我之前使用cv.rectangle()OpenCV方法在numpy数组中绘制边界框,然后将其保存到文件中。但是,我已经开始用OpenCV操作替换,scipy并且我无法scipy轻松地找到与此等效的方法有没有办法可以做到这一点scipy

成功

您可以通过使用简单的矩阵操作操作并用给定的颜色替换所需的行和列来实现此目的,例如:

from scipy.misc import imsave
import numpy as np

# Create 500 x 500 Empty canvas of white color
arr = np.ones((500, 500, 3), dtype=np.uint8) * 255
color = np.array([0, 255, 0], dtype=np.uint8)
bounding_box = (100, 100, 200, 200)

arr[bounding_box[1], bounding_box[0]:bounding_box[0] + bounding_box[2]] = color
arr[bounding_box[1]:bounding_box[1] + bounding_box[3], bounding_box[0]] = color

arr[bounding_box[1] + bounding_box[3], bounding_box[0]:bounding_box[0] + bounding_box[2]] = color
arr[bounding_box[1]:bounding_box[1] + bounding_box[3], bounding_box[0] + bounding_box[2]] = color

imsave("./debug.png", arr)

输出:

在此处输入图片说明

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章