代碼:
img = cv2.imread(img_path)
# 注意這裏的座標點需要是int
start_point = (round(xmin), round(ymin))
end_point = (round(xmax), round(ymax))
cv2.rectangle(img, start_point, end_point, (0, 255, 0), 2)
font = cv2.FONT_HERSHEY_SIMPLEX
cv2.putText(img, f'{category_name} {confidence:.2f}', start_point, font, 1, (0, 0, 255), 3)
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
plt.imshow(img)
plt.show()
需要注意的是:
- rectangle裏面的座標參數必須爲整形的,要不然會出
TypeError: an integer is required (got type tuple)
,錯誤