Last active
January 19, 2016 16:34
-
-
Save arijitx/e2769142ef544c5f13e9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#OpenCV python HOG feature based people detector applied on video | |
#Find the peopledetect.py on opencv-master/samples/python on your OpenCV installation | |
import numpy as np | |
import cv2 | |
def draw_detections(img, rects, thickness = 1): | |
for x, y, w, h in rects: | |
# the HOG detector returns slightly larger rectangles than the real objects. | |
# so we slightly shrink the rectangles to get a nicer output. | |
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) | |
if __name__ == '__main__': | |
hog = cv2.HOGDescriptor() | |
hog.setSVMDetector( cv2.HOGDescriptor_getDefaultPeopleDetector() ) | |
cap=cv2.VideoCapture('vid.avi') | |
while True: | |
_,frame=cap.read() | |
found,w=hog.detectMultiScale(frame, winStride=(8,8), padding=(32,32), scale=1.05) | |
draw_detections(frame,found) | |
cv2.imshow('feed',frame) | |
ch = 0xFF & cv2.waitKey(30) | |
if ch == 27: | |
break | |
cv2.destroyAllWindows() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment