Skip to content

Commit e837df4

Browse files
authored
Create detection.py
1 parent b6adc71 commit e837df4

1 file changed

Lines changed: 35 additions & 0 deletions

File tree

Body Detection/detection.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import cv2
2+
3+
# Load the Cascade Classifier
4+
body_cascade = cv2.CascadeClassifier("haarcascade_fullbody.xml")
5+
videopath=input("Enter the video Path : ")
6+
#Capture the video
7+
cap = cv2.VideoCapture(videopath)
8+
9+
while True:
10+
11+
#read image from video
12+
response,frame = cap.read()
13+
14+
if response == False:
15+
break
16+
17+
# Convert to grayscale
18+
gray_img = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
19+
20+
# Detect the full body
21+
faces = body_cascade.detectMultiScale(gray_img, 1.5, 1)
22+
23+
#display rectangle
24+
for (x, y, w, h) in faces:
25+
cv2.rectangle(frame, (x, y), (x+w, y+h), (0, 255, 0), 2)
26+
27+
# display video
28+
cv2.imshow('img', frame)
29+
30+
if cv2.waitKey(1) & 0xFF == ord('q'):# Enter q to quit
31+
break
32+
33+
# Release the VideoCapture object
34+
cap.release()
35+
cv2.destroyAllWindows()

0 commit comments

Comments
 (0)