forked from jixianpeng/AU_predictor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdata_seg_store.py
63 lines (61 loc) · 2.02 KB
/
data_seg_store.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
59
60
61
62
63
'''coding=utf-8'''
import os
import numpy as np
batch_size=16
from face_seg import *
root_path='./test/cropped_aligned/'
path='./test/seg/'
video=[i for i in os.listdir(root_path)]
# print(video)
# for i in video:
# os.makedirs(path+i+'/')
for v in video:
print(v)
for f in os.listdir(root_path+v):
if f.endswith('.jpg'):
print(f)
file_list=[root_path+v+'/'+f]
images=seg(file_list)
Image.fromarray(images[0]).save(path+v+'/'+f)
else:
continue
'''coding=utf-8'''
import os
import numpy as np
batch_size=16
from face_seg import *
root_path='./test/cropped_aligned/'
path_s='./test/seg/'
path_='./test/boder/'
video=[i for i in os.listdir(path_s)]
# print(video)
# for i in video:
# os.makedirs(path_+i+'/')
for v in video:
print(v)
for f in os.listdir(path_s+v):
print(f)
if f.endswith('.jpg'):
path=path_s+v+'/'+f
img = Image.open(path) # 读图片并转化为灰度图
img_array = np.array(img) # 转化为数组
w, h = img_array.shape
img_border = np.zeros((w - 1, h - 1))
for x in range(1, w - 1):
for y in range(1, h - 1):
Sx = img_array[x + 1][y - 1] + 2 * img_array[x + 1][y] + img_array[x + 1][y + 1] - \
img_array[x - 1][y - 1] - 2 * \
img_array[x - 1][y] - img_array[x - 1][y + 1]
Sy = img_array[x - 1][y + 1] + 2 * img_array[x][y + 1] + img_array[x + 1][y + 1] - \
img_array[x - 1][y - 1] - 2 * \
img_array[x][y - 1] - img_array[x + 1][y - 1]
img_border[x][y] = (Sx * Sx + Sy * Sy) ** 0.5
# img2 = Image.fromarray(img_border + img_array[0:-1, 0:-1])
img2 = Image.fromarray(img_border).resize(size=(112,112)).convert('L')
img2.save(path_+v+'/'+f)
else:
continue
#
#
#
#