-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
62 lines (46 loc) · 1.92 KB
/
main.py
File metadata and controls
62 lines (46 loc) · 1.92 KB
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import cv2
# initiates video capture
video = cv2.VideoCapture(0) #Sets 0 at camera ID
video.set (3, 640) # set width
video.set (4, 480) # set height
# Add haar cascade classifiers
#Data of frontal face classifiers
frontal_cascade = cv2.CascadeClassifier(cv2.data.haarcascades
+ 'haarcascade_frontalface_default.xml')
#Data of profile face classifiers
profile_cascade = cv2.CascadeClassifier(cv2.data.haarcascades
+ 'haarcascade_profileface.xml')
# Loop that initiates the camera
while True:
capture, img=video.read()
# Converts image into grayscale
img_gray=cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
# Detects faces on image
face_frontal = frontal_cascade.detectMultiScale(
img_gray,
scaleFactor=1.3, # Reduces the image
minNeighbors=4 # Defines the number rectanglesnto detect a face
)
face_profile = profile_cascade.detectMultiScale(
img_gray,
scaleFactor=1.3, # Reduces the image
minNeighbors=4 # Defines the number rectangles to detect a face
)
# Join both classifiers
merge_faces=list(face_frontal) + list (face_profile)
# Aplied gaussian blurr for every face detected
for (x, y, w, h) in merge_faces:
# Defines the submatrix of the region we want to blurr
roi = img[y:y + h, x:x + w]
# Applies Gaussian blur to the "roi"
blur = cv2.GaussianBlur(roi, (99, 99), 0)
# Replace the original face region with the blurr
img[y:y + h, x: x + w] = blur
#Open camera
cv2.imshow("Face blurring", img) # Pass image frame
# Standart quote to close de camera
if cv2.waitKey(1) & 0xFF==ord('q'): # Press 'q' from the keyboard to close the program
break
#Release the window resources at close
video.release()
cv2.destroyAllWindows()