-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFace Detect.py
More file actions
55 lines (37 loc) · 1.5 KB
/
Face Detect.py
File metadata and controls
55 lines (37 loc) · 1.5 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
' Using preloaded pictures in the database of Photos Folder '
import cv2 as cv
#read pictures
img = cv.imread('Photos/av.jpg')
'''# ORIGINAL IMAGE
cv.imshow('Gal', img)'''
#scaling function
def rescaleFrame(frame, scale = 0.65):
width = int((frame.shape[1]) * scale)
height = int((frame.shape[0]) * scale)
dimensions = (width ,height)
#downgrading interpolation
return cv.resize(frame, dimensions, interpolation=cv.INTER_AREA)
resized_image = rescaleFrame(img)
cv.imshow('Image', resized_image)
#Converting to greyscale
gray = cv.cvtColor(resized_image, cv.COLOR_BGR2GRAY)
cv.imshow('Grey Person', gray)
#read the xml file n store in a variable
haar_cascade = cv.CascadeClassifier('haarcascade_frontalface_default.xml')
#detect faces with greyscale
# minNeighbors :- specifies a number of {neighbours} or ractangle to be a face
#DETECT FACES n return the rect co-ordintes as a list to the variable
faces_rect = haar_cascade.detectMultiScale(resized_image, scaleFactor=1.3, minNeighbors=3)
print(f'Number of faces found = {len(faces_rect)}')
#loop over list of co-ordinates of rects n draw rect on faces
for(x,y,w,h) in faces_rect:
#points n green rect
cv.rectangle(resized_image, (x,y), (x+w,y+h), (0,255,0), thickness = 2)
cv.imshow('Detected faces', resized_image)
#resize
resize = cv.resize(resized_image, (400,300), interpolation=cv.INTER_CUBIC)
cv.imshow('Resize', resize)
#Edge Cascade
''' canny = cv.Canny(resized_image, 125, 175)
cv.imshow('Canny Edges', canny) '''
cv.waitKey(0)