當你還是個孩子坐車旅行的時候,你玩過數經過的汽車的數目的遊戲嗎?
在這篇文章中,我將教你如何使用Python用c。
以下是執行文中程式碼的環境及相應的版本庫:
Python版本 3。6。9
cvlib: 0。2。2
opencv-python: 4。1。1。26
tensorflow: 1。14。0
matplotlib: 3。1。1
Keras: 2。2。5
下面的程式碼用於匯入所需的python庫、從儲存中讀取影象、對影象執行目標檢測、用邊界框顯示影象以及關於檢測目標的標籤、計算影象中的汽車數量並列印影象:
import cv2
import matplotlib。pyplot as plt
import cvlib as cv
from cvlib。object_detection import draw_bbox
im = cv2。imread(‘cars_4。jpeg’)
bbox, label, conf = cv。detect_common_objects(im)
output_image = draw_bbox(im, bbox, label, conf)
plt。imshow(output_image)
plt。show()
print(‘Number of cars in the image is ’+ str(label。count(‘car’)))
此影象的輸出
:
Number of cars in the image is 29
此影象的輸出
:
Number of cars in the image is 22
此影象的輸出
:
Number of cars in the image is 25
你的汽車計數器程式現在已經準備好了。你可以用它來做一些有趣的實驗,比如計算每天經過你家門前車道的汽車數量。
要了解更多關於cvlib庫的資訊,可以訪問下面的連結。
cvlib[1]
[1]:
https://www。
cvlib。net