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