-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfaceIdentification.py
59 lines (45 loc) · 1.86 KB
/
faceIdentification.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
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
#python3
#Steven face identification
#process: 1.preprecess 2. face position 3.feature extraction 4.face recognition
import os,sys
import cv2
import numpy as np
from CascadeClassifier import CascadeClassifier
from commonModule.ImageBase import *
from commonModule.imagePlot import plotImagList
newW=364 #must equal to the training cfg,refer to genLabel.py
newH=440
def resizeImg(img,NewW,NewH):
h,w = getImgHW(img)
#return cv2.resize(img, (int(h*ratio), int(w*ratio)), interpolation=cv2.INTER_CUBIC) #INTER_LANCZOS4
return cv2.resize(img, (NewW,NewH), interpolation=cv2.INTER_CUBIC) #INTER_CUBIC INTER_NEAREST INTER_LINEAR INTER_AREA
def CascadeDetect(cascPath=r'./res/haarcascade_frontalface_default.xml'):
return CascadeClassifier(cascPath)
def main():
cv2.useOptimized()
file = r'./res/trump.jpg'##obama.jpg #r'./res/Lenna.png' #
print('Number of parameter:', len(sys.argv))
print('Parameters:', str(sys.argv))
if len(sys.argv)>1:
file = sys.argv[1]
img = loadImg(file,mode=cv2.IMREAD_COLOR) # IMREAD_GRAYSCALE IMREAD_COLOR
faceROI = CascadeDetect()
faceR=faceROI.getDetectImg(img) #reSize=(newW,newH)
#print('faceR.shape=',faceR.shape)
face = faceROI.detecvFaceImgOne(img.copy()) #reSize=(newW,newH)
faceGray = cv2.cvtColor(face, cv2.COLOR_BGR2GRAY)
img = changeBgr2Rbg(img)
faceR = changeBgr2Rbg(faceR)
face = changeBgr2Rbg(face)
faceGray = changeBgr2Rbg(faceGray)
ls,names = [],[]
ls.append(img),names.append('orignal')
ls.append(faceR),names.append('faceR')
ls.append(face),names.append('face')
ls.append(faceGray),names.append('faceGray')
plotImagList(ls,names,showTitle=False,showticks=True)
#faceGray = resizeImg(faceGray,newW,newH)
writeImg(face,'./res/Lenna1.png')
#writeImg(faceGray,'./res/myface_gray.png')
if __name__=="__main__":
main()