我之前使用cv.rectangle()
OpenCV方法在numpy数组中绘制边界框,然后将其保存到文件中。但是,我已经开始用OpenCV替换scipy
操作,而且在scipy
中也找不到相应的方法。有没有办法在scipy
中实现这一点?
发布于 2017-01-29 06:53:00
您可以使用简单的矩阵操作操作并将所需的行和列替换为给定的颜色,如下所示:
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)
输出:
https://stackoverflow.com/questions/41918262
复制相似问题