我有一個 haar 級聯專案,它逐幀計算視頻中的汽車,我開始想知道是否可以將 1 幀分成 4 個部分并計算每個部分的汽車。例如,我有這個框架。

如您所見,此框架有 4 個螢屏/部分,我希望 haar 級聯計算每個部分的汽車,但我創建的演算法僅計算 2 個部分(螢屏上方和下方)
for (x,y,w,h) in cars:
cv2.rectangle(img,(x,y),(x w,y h),(0,0,255),2)
# divide screen for 4 screen and count the car
if x < img.shape[1]/2:
car_count1 = 1
elif x < img.shape[1]/2*3:
car_count2 = 1
elif x < img.shape[1]/2*5:
car_count3 = 1
else:
car_count4 = 1

“螢屏 1”是上面的螢屏,有 8 個矩形,“螢屏 2”是下面的螢屏,有 13 個矩形。我知道問題來自elif x < img.shape[1]/2*5:and else:,但我不知道condition這個問題的正確性。
謝謝
uj5u.com熱心網友回復:
首先,您可能想使用矩形的中心點來計算正確的框架
centerx = x w/2
centery = y h/2
您的影像區域是 x < 0.5width 和 y < 0.5height 用于左上角,x > 0.5width 和 y < 0.5height 用于右上角等等。
if centerx < img.shape[1]/2 and centery < img.shape[0]/2:
count1 = 1
if centerx >= img.shape[1]/2 and centery < img.shape[0]/2:
count2 = 1
if centerx < img.shape[1]/2 and centery >= img.shape[0]/2:
count3 = 1
if centerx >= img.shape[1]/2 and centery >= img.shape[0]/2:
count4 = 1
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/488144.html
