Skip to content

Instantly share code, notes, and snippets.

@kumarvipu1
Created December 2, 2020 11:38
Show Gist options
  • Save kumarvipu1/4052e42b4f2c8973520a67dff236ff4a to your computer and use it in GitHub Desktop.
Save kumarvipu1/4052e42b4f2c8973520a67dff236ff4a to your computer and use it in GitHub Desktop.
Sample code for full body detection with opencv
import cv2
# Import video
cap = cv2.VideoCapture("<path>/video.mp4")
cap.set(3, 640)
cap.set(4, 420)
# import cascade file for full body
bodyCascade = cv2.CascadeClassifier(cv2.data.haarcascades + "haarcascade_fullbody.xml")
while True:
success, img = cap.read()
imgGray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
# Getting corners around the body
body = bodyCascade.detectMultiScale(imgGray, 1.1, 2) # play around with these parameters to get the desired result
# drawing bounding box around body
for (x, y, w, h) in body:
img = cv2.rectangle(img, (x, y), (x + w, y + h), (0, 255, 0), 3)
cv2.imshow('body_detect', img)
if cv2.waitKey(10) & 0xFF == ord('q'):
break
cap.release()
cv2.destroyWindow('body_detect')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment