Scipy在图像中绘制边界框

时间:2017-01-29 06:27:38

标签: opencv numpy scipy

我之前使用cv.rectangle() OpenCV方法绘制numpy数组中的边界框,然后将其保存到文件中。但是我已经开始用scipy替换OpenCV操作了,我无法轻易地在scipy中找到相应的方法。有没有办法可以在scipy

中实现

1 个答案:

答案 0 :(得分:2)

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

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)

输出

enter image description here

相关问题