[英]saving the bounding box image
我沒有嘗試在圖像上繪制邊框,而是嘗試將其另存為新圖像。
當我獲得[ymin,xmax,ymax,xmin]點時,我正在這樣做。
import cv2
import numpy as np
image = cv2.imread('ballet_106_0.jpg')
image = np.array(image)
boxes = [21, 511, 41, 420 ]
ymin, xmax , ymax ,xmin = boxes
im2 = image[ymin:ymax,xmin:xmax,:]
cv2.imwrite('bboximage.jpg',im2)
但是如果我只得到x
和y
點以及height
和width
。 我不確定如何索引numpy數組。
任何建議都會非常有幫助,謝謝。
您的代碼看起來不錯,盡管以下行:
image = np.array(image)
不是必需的,好像一切都很好cv2.imread
產生np.array
,但是如果cv2.imread
失敗,它將返回None
,這可能是問題的根源,請在cv2.imread
下面添加以下行:
print(type(image))
如果顯示None
,則很可能意味着您的目錄中沒有ballet_106_0.jpg
圖像。
編輯:要將x,y,height,width
轉換為x/y-min/max
值,只需執行
ymin = y
ymax = y+height
xmin = x
xmax = x+width
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.