我目前正在为我的本科论文研究车辆检测,分类和计算每个班级实例的数量。但是,我在计数上有问题。我想根据分类结果(例如“汽车总数”和“卡车总数”)计算车辆数量。
我目前正在https://github.com/AlfaCodeFlow/Vehicle_Detection-And-Classification这里使用示例代码。
在此示例中,作者根据车辆的行驶方向(“上”或“下”)对车辆总数进行计数,就像这张图片一样
example
我需要是按照计数并显示卡车总数和汽车总数而不是车辆总数的方式更改此代码向上或向下移动。你能帮我吗?
以下是此任务的代码,我需要在其中进行更改:
cnt_up=0
cnt_down=0
line_up=400
line_down=250
up_limit=230
down_limit=int(4.5*(500/5))
new=True
if cy in range(up_limit,down_limit):
for i in cars:
if abs(x - i.getX()) <= w and abs(y - i.getY()) <= h:
new = False
i.updateCoords(cx, cy)
#Counter that i need to change from upward and downward to classification (Truck & Car)
if i.going_UP(line_down,line_up)==True:
cnt_up+=1
elif i.going_DOWN(line_down,line_up)==True:
cnt_down+=1
break
if i.getState()=='1':
if i.getDir()=='down'and i.getY()>down_limit:
i.setDone()
elif i.getDir()=='up'and i.getY()<up_limit:
i.setDone()
#This is for Classification
for i in cars:
cv2.putText(frame, str(i.getId()), (i.getX(), i.getY()), font, 0.3, (255,255,0), 1, cv2.LINE_AA)
if line_down+20<= i.getY() <= line_up-20:
a = (h + (.74*w)- 100)
if a >= 0:
cv2.putText(frame, "Truck", (i.getX(), i.getY()), font, 1, (0,0,255), 2, cv2.LINE_AA)
else:
cv2.putText(frame, "Car", (i.getX(), i.getY()), font, 1, (0,0,255), 2, cv2.LINE_AA)
#To render in frame
str_up='UP: '+str(cnt_up)
str_down='DOWN: '+str(cnt_down)
frame=cv2.line(frame,(0,line_up),(900,line_up),(0,0,255),3,8)
frame=cv2.line(frame,(0,up_limit),(900,up_limit),(0,0,0),1,8)
frame=cv2.line(frame,(0,down_limit),(900,down_limit),(255,255,0),1,8)
frame=cv2.line(frame, (0, line_down), (900, line_down), (255, 0,0), 3, 8)
cv2.putText(frame, str_up, (10, 40), font, 0.5, (0, 0, 255), 1, cv2.LINE_AA)
cv2.putText(frame, str_down, (10, 90), font, 0.5, (255, 0, 0), 1, cv2.LINE_AA)
cv2.imshow('Frame',frame)