How would I do this? Example code would be helpful. It's a simple tracking application. A pedestrian steps onto the street and the program should place a bounding box. This should be in real time and thougb I have tried other examples such as the one provided by opencv, they're all too slow or way too wrong.
Thanks for taking the time to read this
EDIT: This is the very slow functioning python code. You need the pedestrian xml haar cascade.import numpy
import cv2
import sys
import time
cascPath = "pedestrian.xml"
#cascPath1 = "cascades/haarcascade_stop.xml"
faceCascade = cv2.CascadeClassifier(cascPath)
#stopCascade = cv2.CascadeClassifier(cascPath1)
video_capture = cv2.VideoCapture(1)
time.sleep(2)
while True:
# Capture frame-by-frame
ret, frame = video_capture.read()
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
body = faceCascade.detectMultiScale(
gray,
scaleFactor=1.1,
minNeighbors=10,
)
# stop = stopCascade.detectMultiScale(
# gray,
# scaleFactor=1.2,
# minNeighbors=10
# )
# Draw a rectangle around the faces
for (x, y, w, h) in body:
cv2.rectangle(frame, (x, y), (x+w, y+h), (255, 255, 0), 4)
# for (x, y, w, h) in stop:
# Display the resulting frame
cv2.imshow('Video', frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
# When everything is done, release the capture
video_capture.release()
cv2.destroyAllWindows()
解决方案Nobody will supply you with a simple answer to this. Fast tracking of human objects is cutting edge science.
1. Do your research and find out what is possible. You are unlikely to exceed that with your effort. Google is replete with material.
2. Develop an algorithm that meets your requirements. For this python and opencv is fine i.e. slow detection.
http://stackoverflow.com/questions/16673698/people-detection-and-tracking[^]
https://www.youtube.com/watch?v=AKLEuAtFDXQ[^]
3. Improve the performance by optimising the code (maybe c++) and perhaps improving hardware.
No simple answers, of course, but there is one idea: perhaps you only need a motion detector. The logic would be: if you monitor the road permanently, a pedestrian cannot get in the view without the motion. Normally, motion is easier detected than all those image features. Then you could use, say, the optical flow concept: http://opencv-python-tutroals.readthedocs.org/en/latest/py_tutorials/py_video/py_lucas_kanade/py_lucas_kanade.html[^].
Even though you've answered me that the cars and cyclists are not a problem, I cannot understand how it could be practical. Anyway, a need to discriminate pedestrians and other players, it can make the problem extremely complex.
—SA