Skip to content

Instantly share code, notes, and snippets.

@d4rkc0de
Created February 21, 2019 12:43
Show Gist options
  • Save d4rkc0de/dac401f1c191e435dd0c9fcfc399336f to your computer and use it in GitHub Desktop.
Save d4rkc0de/dac401f1c191e435dd0c9fcfc399336f to your computer and use it in GitHub Desktop.
import numpy as np
from PIL import ImageGrab
import cv2
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)
hog = cv2.HOGDescriptor()
hog.setSVMDetector( cv2.HOGDescriptor_getDefaultPeopleDetector() )
cap=cv2.VideoCapture('vid.avi')
while(True):
screen = np.array(ImageGrab.grab(bbox=(0,40,800, 640)))
#screen = cv2.Canny(screen ,threshold1 = 200,threshold2 = 200 )
found,w=hog.detectMultiScale(screen, winStride=(8,8), padding=(32,32), scale=1.05)
draw_detections(screen,found)
cv2.imshow('window',screen)
if cv2.waitKey(25) & 0xFF == ord('q'):
cv2.destroyAllWindows()
break
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment