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()
<pre lang="Python">