Mtcnn의 얼굴 자르기 및 정렬 B
Mtcnn의 얼굴 자르기 및 정렬 1 from scipy import misc
2 import tensorflow as tf
3 import detect_face
4 import cv2
5 # import matplotlib.pyplot as plt
6 from PIL import Image
7 import os
8 # import scipy.misc
9 # %pylab inline
10 fin = 'D:\data\male'
11 fout = 'D:\data\\rain\male'
12 minsize = 20 # minimum size of face
13 threshold = [0.6, 0.7, 0.7] # three steps's threshold
14 factor = 0.709 # scale factor
15 margin = 44
16 frame_interval = 3
17 batch_size = 1000
18 image_size = 182
19 input_image_size = 160
20
21 print('Creating networks and loading parameters')
22
23 with tf.Graph().as_default():
24 gpu_options = tf.GPUOptions(allow_growth=True)
25 sess = tf.Session(config=tf.ConfigProto(gpu_options=gpu_options, log_device_placement=False))
26 with sess.as_default():
27 pnet, rnet, onet = detect_face.create_mtcnn(sess, 'D:\\code\\real-time-deep-face-recognition-master\\20170512-110547')
28
29
30 i= 0
31
32 for file in os.listdir(fin):
33 try:
34
35 file_fullname = fin + '/' + file
36 img = misc.imread(file_fullname)
37 # i+= 1
38 # img = misc.imread(image_path)
39 bounding_boxes, _ = detect_face.detect_face(img, minsize, pnet, rnet, onet, threshold, factor)
40 nrof_faces = bounding_boxes.shape[0] #
41 print(nrof_faces)
42 #print(' :{}'.format(nrof_faces))
43
44 # print(bounding_boxes)
45
46 crop_faces = []
47 if nrof_faces != 0 :
48 for face_position in bounding_boxes:
49 face_position = face_position.astype(int)
50 print(face_position[0:4])
51 cv2.rectangle(img, (face_position[0], face_position[1]), (face_position[2], face_position[3]), (0, 255, 0), 2)
52 crop = img[face_position[1]:face_position[3],
53 face_position[0]:face_position[2], ]
54 # print(crop)
55 # crop = cv2.resize(crop, (96, 96), interpolation=cv2.INTER_CUBIC)
56 crop_faces.append(crop)
57 img2 = Image.open(file_fullname)
58 a = face_position[0:4]
59 # print('crop_faces:',crop_faces)
60 # a = [face_position[0:4]]
61 box = (a)
62 roi = img2.crop(box)
63 i = roi.resize((224, 224))
64
65 out_path = fout + '/' + file
66
67 i.save(out_path)
68 print('success')
69 else:
70 pass
71 except:
72 pass
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
다양한 언어의 JSON
JSON은 Javascript 표기법을 사용하여 데이터 구조를 레이아웃하는 데이터 형식입니다.
그러나 Javascript가 코드에서 이러한 구조를 나타낼 수 있는 유일한 언어는 아닙니다.
저는 일반적으로 '객체'{}...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.
1 from scipy import misc
2 import tensorflow as tf
3 import detect_face
4 import cv2
5 # import matplotlib.pyplot as plt
6 from PIL import Image
7 import os
8 # import scipy.misc
9 # %pylab inline
10 fin = 'D:\data\male'
11 fout = 'D:\data\\rain\male'
12 minsize = 20 # minimum size of face
13 threshold = [0.6, 0.7, 0.7] # three steps's threshold
14 factor = 0.709 # scale factor
15 margin = 44
16 frame_interval = 3
17 batch_size = 1000
18 image_size = 182
19 input_image_size = 160
20
21 print('Creating networks and loading parameters')
22
23 with tf.Graph().as_default():
24 gpu_options = tf.GPUOptions(allow_growth=True)
25 sess = tf.Session(config=tf.ConfigProto(gpu_options=gpu_options, log_device_placement=False))
26 with sess.as_default():
27 pnet, rnet, onet = detect_face.create_mtcnn(sess, 'D:\\code\\real-time-deep-face-recognition-master\\20170512-110547')
28
29
30 i= 0
31
32 for file in os.listdir(fin):
33 try:
34
35 file_fullname = fin + '/' + file
36 img = misc.imread(file_fullname)
37 # i+= 1
38 # img = misc.imread(image_path)
39 bounding_boxes, _ = detect_face.detect_face(img, minsize, pnet, rnet, onet, threshold, factor)
40 nrof_faces = bounding_boxes.shape[0] #
41 print(nrof_faces)
42 #print(' :{}'.format(nrof_faces))
43
44 # print(bounding_boxes)
45
46 crop_faces = []
47 if nrof_faces != 0 :
48 for face_position in bounding_boxes:
49 face_position = face_position.astype(int)
50 print(face_position[0:4])
51 cv2.rectangle(img, (face_position[0], face_position[1]), (face_position[2], face_position[3]), (0, 255, 0), 2)
52 crop = img[face_position[1]:face_position[3],
53 face_position[0]:face_position[2], ]
54 # print(crop)
55 # crop = cv2.resize(crop, (96, 96), interpolation=cv2.INTER_CUBIC)
56 crop_faces.append(crop)
57 img2 = Image.open(file_fullname)
58 a = face_position[0:4]
59 # print('crop_faces:',crop_faces)
60 # a = [face_position[0:4]]
61 box = (a)
62 roi = img2.crop(box)
63 i = roi.resize((224, 224))
64
65 out_path = fout + '/' + file
66
67 i.save(out_path)
68 print('success')
69 else:
70 pass
71 except:
72 pass
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
다양한 언어의 JSONJSON은 Javascript 표기법을 사용하여 데이터 구조를 레이아웃하는 데이터 형식입니다. 그러나 Javascript가 코드에서 이러한 구조를 나타낼 수 있는 유일한 언어는 아닙니다. 저는 일반적으로 '객체'{}...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.