hylee commited on
Commit
2fe3ec4
1 Parent(s): 2ea7ce8
Files changed (2) hide show
  1. APDrawingGAN2/preprocess/get_partmask.py +17 -2
  2. app.py +4 -3
APDrawingGAN2/preprocess/get_partmask.py CHANGED
@@ -51,19 +51,34 @@ def shape_to_np(shape, dtype="int"):
51
  # return the list of (x, y)-coordinates
52
  return coords
53
 
54
- def get_68lm(imgfile,savepath, detector, predictor):
55
  image = cv2.imread(imgfile)
56
  rgbImg = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
57
  rects = detector(rgbImg, 1)
58
  for (i, rect) in enumerate(rects):
59
  landmarks = predictor(rgbImg, rect)
60
  landmarks = shape_to_np(landmarks)
61
- f = open(savepath,'w')
62
  for i in range(len(landmarks)):
63
  lm = landmarks[i]
64
  print(lm[0], lm[1], file=f)
65
  f.close()
66
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
67
  def get_partmask(imgfile,part,lmpath,savefile):
68
  img = cv2.imread(imgfile)
69
  mask = np.zeros(img.shape, np.uint8)
 
51
  # return the list of (x, y)-coordinates
52
  return coords
53
 
54
+ def get_68lm(imgfile,savepath5,savepath68, detector, predictor):
55
  image = cv2.imread(imgfile)
56
  rgbImg = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
57
  rects = detector(rgbImg, 1)
58
  for (i, rect) in enumerate(rects):
59
  landmarks = predictor(rgbImg, rect)
60
  landmarks = shape_to_np(landmarks)
61
+ f = open(savepath68,'w')
62
  for i in range(len(landmarks)):
63
  lm = landmarks[i]
64
  print(lm[0], lm[1], file=f)
65
  f.close()
66
 
67
+ ff = open(savepath5, 'w')
68
+
69
+ lm = landmarks[36]
70
+ print(lm[0], lm[1], file=ff)
71
+ lm = landmarks[45]
72
+ print(lm[0], lm[1], file=ff)
73
+ lm = landmarks[30]
74
+ print(lm[0], lm[1], file=ff)
75
+ lm = landmarks[48]
76
+ print(lm[0], lm[1], file=ff)
77
+ lm = landmarks[54]
78
+ print(lm[0], lm[1], file=ff)
79
+
80
+ ff.close()
81
+
82
  def get_partmask(imgfile,part,lmpath,savefile):
83
  img = cv2.imread(imgfile)
84
  mask = np.zeros(img.shape, np.uint8)
app.py CHANGED
@@ -139,14 +139,15 @@ def run(
139
  shutil.copyfile(mask.name, os.path.join(opt.bg_dir, name+'.png'))
140
 
141
  imgfile = os.path.join(opt.dataroot, fullname)
142
- lmfile = os.path.join(opt.lm_dir, name+'.txt')
 
143
  # 预处理数据
144
- get_68lm(imgfile, lmfile, detector, predictor)
145
 
146
  imgs = []
147
  for part in ['eyel', 'eyer', 'nose', 'mouth']:
148
  savepath = os.path.join(opt.cmask_dir + part, name+'.png')
149
- get_partmask(imgfile, part, lmfile, savepath)
150
  #imgs.append(savepath)
151
 
152
  data_loader = CreateDataLoader(opt)
 
139
  shutil.copyfile(mask.name, os.path.join(opt.bg_dir, name+'.png'))
140
 
141
  imgfile = os.path.join(opt.dataroot, fullname)
142
+ lmfile5 = os.path.join(opt.lm_dir, name+'.txt')
143
+ lmfile68 = os.path.join(opt.lm_dir, name + '_68.txt')
144
  # 预处理数据
145
+ get_68lm(imgfile, lmfile5, lmfile68, detector, predictor)
146
 
147
  imgs = []
148
  for part in ['eyel', 'eyer', 'nose', 'mouth']:
149
  savepath = os.path.join(opt.cmask_dir + part, name+'.png')
150
+ get_partmask(imgfile, part, lmfile68, savepath)
151
  #imgs.append(savepath)
152
 
153
  data_loader = CreateDataLoader(opt)