0
我之前使用的是cv.rectangle()
OpenCV方法在numpy數組中繪製邊界框,然後將其保存到文件中。不過,我已經開始用scipy
取代OpenCV操作,並且我無法輕鬆地在scipy
中找到此方法。有沒有一種方法可以在scipy
中實現?Scipy在圖像中繪製邊界框
我之前使用的是cv.rectangle()
OpenCV方法在numpy數組中繪製邊界框,然後將其保存到文件中。不過,我已經開始用scipy
取代OpenCV操作,並且我無法輕鬆地在scipy
中找到此方法。有沒有一種方法可以在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)
輸出:
你可以試試' skimage' –
我不認爲skimage也有它的功能。我結束了使用PIL.ImageDraw.Draw.Rectangle函數 – pratsJ