python-opencv people detection HELP

asked 2013-11-08 21:40:05 -0500

ceds.. gravatar image

updated 2013-11-08 21:50:50 -0500

import cv2 import numpy as np from glob import glob import itertools as it

cam = cv2.VideoCapture(0) s, img = cam.read()

winName = "Movement Indicator"

hog = cv2.HOGDescriptor() hog.setSVMDetector( cv2.HOGDescriptor_getDefaultPeopleDetector() )

def inside(r, q): rx, ry, rw, rh = r qx, qy, qw, qh = q return rx > qx and ry > qy and rx + rw < qx + qw and ry + rh < qy + qh

def draw_detections(img, rects, thickness = 1): for x, y, w, h in rects:

    pad_w, pad_h = int(0.15*w), int(0.05*h)
    cv2.rectangle(img, (x+pad_w, y+pad_h), (x+w-pad_w, y+h-pad_h), (0, 255, 0), thickness)

i = 0

while s: #cv2.imshow( winName,img )

s, img = cam.read()
#if i % 5 == 0: 
found, w = hog.detectMultiScale(img, winStride=(8,8), padding=(32,32), scale=1.05)
found_filtered = []
for ri, r in enumerate(found):
    for qi, q in enumerate(found):
        if ri != qi and inside(r, q):
            break
    else:
        found_filtered.append(r)
draw_detections(img, found)
draw_detections(img, found_filtered, 1)
#print '%d (%d) found' % (len(found_filtered), len(found))


key = cv2.waitKey(10)
if key == 27:
    cv2.destroyAllWindows()
    break
i += 1
cv2.imshow('img', img)

print "Human Detection Bet"

the output of this code is very slow.... can someone help me make it better and faster

i am a newbie trying to make a school project...

edit retag flag offensive close merge delete