Click here to Skip to main content
15,896,201 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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">
Posted
Updated 9-Feb-15 15:13pm
v3
Comments
Zoltán Zörgő 8-Feb-15 17:13pm    
Pedestrion detector? What exactly do you want? Counting? Tracking? Simpel detection of presence of any pedestrian?
Member 11436931 8-Feb-15 17:32pm    
Just detection of presence of pedestrian. I've tried the Haar cascades but they're too slow with a lot of false positives and HOG is too slow. Any ideas? Maybe machine learning but I would need an example.
Zoltán Zörgő 8-Feb-15 17:34pm    
You can train Haar cascade to be more precise - if you need performance, Python is not a good approach, even compiled.
[no name] 9-Feb-15 0:04am    
You have not asked a question yet. Describe what you are trying to do in a bit of detail. What is the data source and the goal?
Member 11436931 9-Feb-15 20:49pm    
Thanks, just got updated

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.
 
Share this answer
 
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
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900