Opencv Scipy在图像中绘制边界框
我之前使用Opencv Scipy在图像中绘制边界框,opencv,numpy,scipy,Opencv,Numpy,Scipy,我之前使用cv.rectangle()OpenCV方法在numpy数组中绘制边界框,然后将其保存到文件中。然而,我已经开始用scipy替换OpenCV操作,我无法在scipy中轻松找到与此等效的方法。在scipy中有没有一种方法可以实现这一点?您可以通过使用简单的矩阵操作并用给定的颜色替换所需的行和列来实现,如下所示: from scipy.misc import imsave import numpy as np # Create 500 x 500 Empty canvas of whit
cv.rectangle()
OpenCV方法在numpy数组中绘制边界框,然后将其保存到文件中。然而,我已经开始用scipy
替换OpenCV操作,我无法在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)
输出:
您可以通过使用简单的矩阵操作并用给定的颜色替换所需的行和列来完成此操作,如下所示:
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)
输出:
你可以试试
skimage
我认为skimage没有它的功能。最后我使用了PIL.ImageDraw.Draw.Rectangle函数你可以试试skimage
我认为skimage也没有相应的函数。我最终使用了PIL.ImageDraw.Draw.Rectangle函数