forked from Rits1272/PythonPrograms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathface_detection.py
29 lines (23 loc) · 969 Bytes
/
face_detection.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import cv2 as cv
# Read image
original_image = cv.imread("C:/Users/RITs/Desktop/Old stuff/image.jpeg")
# Convert color image to grayscale for viola-jones
grayscale_image = cv.cvtColor(original_image, cv.COLOR_BGR2GRAY)
# Load the classifier and create a cascade object for face detection
face_cascade = cv.CascadeClassifier('C:/Users/RITs/Desktop/Old stuff/myBlog/myvenv/Lib/site-packages/cv2/data/haarcascade_frontalface_alt.xml')
# The term MultiScale indicates that the algorithm looks
# at subregions of the image in multiple scales, to detect
# faces of varying sizes:
detected_face = face_cascade.detectMultiScale(grayscale_image)
for (column, row, width, height) in detected_face:
cv.rectangle(
original_image,
(column, row),
(column + width, row + height),
(0, 255, 0),
2
)
# Displaying the image
cv.imshow('Image', original_image)
cv.waitKey(0)
cv.destroyAllWindows()