资源简介
博文:基于python的行人与车辆检测和跟踪实现(HOG+SVM/HAAR)
链接:https://blog.csdn.net/qq_38523834/article/details/89619697
文件里面有我提到的视频,cars.xml文件和myhaar.xml文件。需要的Python库在requirements.txt有提及:
cmake==3.12.0
dlib==19.16.0
numpy==1.15.3
opencv-python==3.4.3.18
这些是最低版本,可以比这个高。我是用python3.6运行的。
没有安装dlib库的同学,注意在安装好所需库之后,需要自行下载一个.whl文件后才能用pip install dlib 安装成功哦。
相关下载链接在这个博文里:https://blog.csdn.net/wzx479/article/details/79890440
代码片段和文件信息
import cv2
import dlib
import time
import threading
import numpy as np
# from imutils.object_detection import non_max_suppression
import math
hog = cv2.HOGDescriptor()
hog.setSVMDetector(cv2.HOGDescriptor_getDefaultPeopleDetector())
# carCascade = cv2.CascadeClassifier(‘myhaar.xml‘)
video = cv2.VideoCapture(‘project_output_haar1.avi‘)
def estimateSpeed(location1 location2):
d_pixels = math.sqrt(math.pow(location2[0] - location1[0] 2) + math.pow(location2[1] - location1[1] 2))
# ppm = location2[2] / carWidht
ppm = 8.8
d_meters = d_pixels / ppm
# print(“d_pixels=“ + str(d_pixels) “d_meters=“ + str(d_meters))
fps = 18
speed = d_meters * fps * 3.6
return speed
def trackMultipleobjects():
out = None
counter_right = []
counter_moto = []
counter_wrong = []
counter_wrong_detect = []
rects = []
line_pass_left = np.array([[115200][115320]])
line_pass_right = np.array([[930 200] [930 320]])
mask_people = np.array([line_pass_left[0] line_pass_left[1] line_pass_right[1] line_pass_right[0]])
# line_down = [(0 360) (800 360)]
# rectangleColor = (0 255 0)
frameCounter = 0
currentCarID = 0
fps = 0
carTracker = {}
carNumbers = {}
carLocation1 = {}
carLocation2 = {}
speed = [None] * 1000
HEIGHT = 720
WIDTH = 1280
# EXIT_COLOR = (66 183 42)
# Write output to video file
out = cv2.VideoWriter(‘project_output_haar_and_svm1.avi‘ cv2.VideoWriter_fourcc(‘m‘‘p‘‘4‘‘v‘) 10 (WIDTH HEIGHT))
while True:
start_time = time.time()
rc image = video.read()
if type(image) == type(None):
break
image = cv2.resize(image (WIDTH HEIGHT))
resultImage = image.copy()
frameCounter = frameCounter + 1
carIDtoDelete = []
for carID in carTracker.keys():
trackingQuality = carTracker[carID].update(image)
if trackingQuality < 7:
carIDtoDelete.append(carID)
for carID in carIDtoDelete:
print (‘Removing carID ‘ + str(carID) + ‘ from list of trackers.‘)
print (‘Removing carID ‘ + str(carID) + ‘ previous location.‘)
print (‘Removing carID ‘ + str(carID) + ‘ current location.‘)
carTracker.pop(carID None)
carLocation1.pop(carID None)
carLocation2.pop(carID None)
# detecting
if not (frameCounter % 10):
#gray = cv2.cvtColor(image cv2.COLOR_BGR2GRAY)
(rects weights) = hog.detectMultiScale(image winStride=(4 4)
padding=(8 8) scale=1.05)
for (_x _y _w _h) in rects:
x = int(_x)
y = int(_y)
w = int(_w)
h = int(_h)
x_bar = x + 0.5 * w
y_bar = y +
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
.C..... 1278 2018-10-24 00:52 vehicle-speed-check-master\.gitignore
.CA.... 1385458 2018-10-24 00:52 vehicle-speed-check-master\cars.mp4
.CA.... 118803 2017-09-21 00:01 vehicle-speed-check-master\cars.xm
.CA.... 375639 2018-10-24 00:52 vehicle-speed-check-master\myhaar.xm
.CA.... 9893 2019-04-23 15:15 vehicle-speed-check-master\people_tracking.py
.CA.... 11913613 2019-04-22 08:08 vehicle-speed-check-master\project.mp4
.C..... 1058 2018-10-24 00:52 vehicle-speed-check-master\README.md
.C..... 66 2018-10-24 00:52 vehicle-speed-check-master\requirements.txt
.CA.... 7610 2019-04-23 15:02 vehicle-speed-check-master\speed_check.py
.C.D... 0 2019-04-28 00:57 vehicle-speed-check-master
----------- --------- ---------- ----- ----
13813418 10
评论
共有 条评论