-
Notifications
You must be signed in to change notification settings - Fork 146
/
Copy pathconvert_current.py
33 lines (33 loc) · 1.14 KB
/
convert_current.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
import os
import cv2
import sys
pad='a'
root_path='./fer2013/test/'
rootPath='./'
cascPath=rootPath+'haarcascade_frontalface_alt.xml'
faceCasccade=cv2.CascadeClassifier(cascPath)
num=0
if __name__=='__main__':
if len(sys.argv)==2:
path=root_path+sys.argv[1]
path_w=root_path+pad+sys.argv[1]
#print(path,path_w)
if os.path.isdir(path):
if not os.path.exists(path_w):
os.makedirs(path_w)
lists=os.listdir(path)
for list in lists:
#print(list)
img=cv2.imread(path+'/'+list)
img_gray=cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
faces = faceCasccade.detectMultiScale(
img_gray,
scaleFactor=1.1,
minNeighbors=1,
minSize=(35,35),
)
for x,y,w,h in faces:
face_img_gray = img_gray[y:y+h,x:x+w]
print (path_w+'/%d'%num+'.jpg')
cv2.imwrite(path_w+'/%d'%num+'.jpg',face_img_gray)
num+=1