-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathface_filter.py
More file actions
44 lines (39 loc) · 1.24 KB
/
face_filter.py
File metadata and controls
44 lines (39 loc) · 1.24 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
import os
import shutil
import dlib
import cv2
def CreateDir(path):
isExists=os.path.exists(path)
if not isExists:
os.makedirs(path)
#print(path+' 目录创建成功')
#else:
#print(path+' 目录已存在')
def FilterFace(filepath, newPath):
fileNames = os.listdir(filepath)
for file in fileNames:
#path = "./picture.txt"
#f = open(path)
#lines = f.readlines()
#print(line)
#linesplit = line.split('\n')[0]
newDir = filepath + '/' + file
if os.path.isfile(newDir):
print(newDir)
newFile = newPath + file
detector = dlib.get_frontal_face_detector()
image = cv2.imread(newDir)
b, g, r = cv2.split(image)
image_rgb = cv2.merge([r, g, b])
rects = detector(image_rgb, 1)
if len(rects) >= 1:
shutil.copyfile(newDir, newFile)
else:
FilterFace(newDir,newPath)
if __name__ == "__main__":
#path = input("输入需要复制文件目录:")
path = './Images'
# 创建目标文件夹
mkPath = "./Filtered_Images/"
#CreateDir(mkPath)
FilterFace(path,mkPath)