Created
May 16, 2020 08:53
-
-
Save kengggg/a2e505a16f3d87a31c8c5f4bfc26172e to your computer and use it in GitHub Desktop.
Human Detection using OpenCV's HOG people detector
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
import cv2 | |
import time | |
hog = cv2.HOGDescriptor() | |
hog.setSVMDetector(cv2.HOGDescriptor_getDefaultPeopleDetector()) | |
cap = cv2.VideoCapture('XVR_ch11_main_20200510120008_20200510130008.dav') | |
if(cap.isOpened() == False): | |
print("Error!") | |
while(cap.isOpened()): | |
ret, frame = cap.read() | |
if ret == True: | |
start_time = time.time() | |
frame = cv2.resize(frame,(1280, 720)) | |
gray_frame = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) | |
rects, weights = hog.detectMultiScale(gray_frame) | |
end_time = time.time() | |
print(f"Elapsed time: {end_time-start_time}") | |
for i, (x, y, w, h) in enumerate(rects): | |
if weights[i] < 0.7: | |
continue | |
cv2.rectangle(frame, (x,y), (x+w, y+h), (0,255,0), 2) | |
cv2.imshow('Body detector!', frame) | |
if(cv2.waitKey(25) & 0xFF == ord('q')): | |
break | |
else: | |
break | |
cap.release() | |
cv2.destroyAllWindows() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment