Last active
September 23, 2023 15:36
-
-
Save madhawav/cd913f68b9405b438833b614ccb49b57 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
import cv2 | |
import time | |
person_cascade = cv2.CascadeClassifier( | |
os.path.join('/path/to/haarcascade_fullbody.xml')) | |
cap = cv2.VideoCapture("/path/to/test/video") | |
while True: | |
r, frame = cap.read() | |
if r: | |
start_time = time.time() | |
frame = cv2.resize(frame,(640,360)) # Downscale to improve frame rate | |
gray_frame = cv2.cvtColor(frame, cv2.COLOR_RGB2GRAY) # Haar-cascade classifier needs a grayscale image | |
rects = person_cascade.detectMultiScale(gray_frame) | |
end_time = time.time() | |
print("Elapsed Time:",end_time-start_time) | |
for (x, y, w, h) in rects: | |
cv2.rectangle(frame, (x,y), (x+w,y+h),(0,255,0),2) | |
cv2.imshow("preview", frame) | |
k = cv2.waitKey(1) | |
if k & 0xFF == ord("q"): # Exit condition | |
break |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment