Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/opencv/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Opencv Scipy在图像中绘制边界框_Opencv_Numpy_Scipy - Fatal编程技术网

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函数