def __getitem__(self, item): img_path = self.images[item] image = cv2.imread(img_path) landmark_path = self.landmarks[item] landmarks = utils.read_mat(landmark_path) return image, landmarks
def __getitem__(self, item): image, landmarks = super(AlignDataset, self).__getitem__(item) al_ldmk = utils.read_mat(self.algin_ldmk[item]) image, _, t = self.aligner(image, al_ldmk, noise=np.random.uniform(-self.max_jitter, self.max_jitter, 2), radian=np.random.uniform(-self.max_radian, self.max_radian)) landmarks = landmarks @ t[0:2, :] + t[2, :] # start_y = np.random.randint(0, self.aligner.scale[0] - self.shape[0] + 1) # start_x = np.random.randint(0, self.aligner.scale[1] - self.shape[1] + 1) # landmarks[:, 0] -= start_x # landmarks[:, 1] -= start_y landmarks[:, 0] /= self.shape[1] landmarks[:, 1] /= self.shape[0] # image = image[start_y:start_y + self.shape[0], start_x :start_x + self.shape[1]] if self.phase == 'train': if self.flip: image, landmarks = utils.random_flip(image, landmarks, 0.5) image = utils.random_gamma_trans(image, np.random.uniform(0.8, 1.2, 1)) image = utils.random_color(image) image = cv2.resize(image, self.shape) image = np.transpose(image, (2, 0, 1)).astype(np.float32) landmarks = landmarks[self.ldmk_ids, :] return image, np.reshape(landmarks, (-1))
def __getitem__(self, item): img_path = self.images[item] image = cv2.imread(img_path) landmark_path = self.landmarks[item] landmarks = utils.read_mat(landmark_path) bbox_path = self.bboxes[item] bbox = utils.read_bbox(bbox_path) return image, landmarks, np.array(bbox), self.file_list[item]
def __getitem__(self, item): image, gt_landmarks = super(AlignFusionDataset, self).__getitem__(item) pr_landmarks = utils.read_mat(self.algin_ldmk[item]) image, pr_landmarks, t = self.aligner(image, pr_landmarks, noise=np.random.uniform(-self.max_jitter, self.max_jitter, 2)) gt_landmarks = gt_landmarks @ t[0:2, :] + t[2, :] # start_y = np.random.randint(0, self.aligner.scale[0] - self.shape[0] + 1) # start_x = np.random.randint(0, self.aligner.scale[1] - self.shape[1] + 1) # gt_landmarks[:, 0] -= start_x # gt_landmarks[:, 1] -= start_y # pr_landmarks[:, 0] -= start_x # pr_landmarks[:, 1] -= start_y gt_landmarks[:, 0] /= self.shape[1] gt_landmarks[:, 1] /= self.shape[0] # image = image[start_y:start_y + self.shape[0], start_x:start_x + self.shape[1]] if self.phase == 'train': if self.flip: a = np.random.uniform(0, 1, 1) if a < 0.5: image = cv2.flip(image, 1) gt_landmarks = utils.landmark_flip(gt_landmarks) pr_landmarks = utils.landmark_flip(pr_landmarks, max_x=self.shape[1]) image = utils.random_gamma_trans(image, np.random.uniform(0.8, 1.2, 1)) image = utils.random_color(image) kernel_size = self.kernel_size sigma = self.sigma heatmaps = [] for idx in self.idxs: img = np.zeros((self.shape[0], self.shape[1]), np.uint8) draw_curve(img, pr_landmarks, idx) heatmaps.append(cv2.GaussianBlur(img, (kernel_size, kernel_size), sigma)) inputs = [] for i in range(len(heatmaps)): heatmaps[i] = heatmaps[i].astype(np.float32) / np.max(heatmaps[i]) inputs.append(image * np.expand_dims(heatmaps[i], -1)) inputs.append(image) # cv2.imshow(",", image) # cv2.waitKey(1) # for i in inputs: # cv2.imshow("", i.astype(np.uint8)) # cv2.waitKey(0) inputs = np.concatenate(inputs, axis=-1) inputs = np.transpose(inputs, [2, 0, 1]) heatmaps = np.stack(heatmaps, axis=2) heatmaps = np.transpose(heatmaps, [2, 0, 1]) return inputs, np.reshape(gt_landmarks, (-1)), heatmaps
def save_pic_and_lmk(kk): shuru = kk if shuru == 0: e = 1 #return 0 输入为0,说明只有一张图 else: lmk_dir = '/home/zhang/correctdata/data/landmark/' #注意lmk文件的后缀为.txt pic_dir = '/home/zhang/correctdata/data/picture/' bbox_dir = '/home/zhang/correctdata/bbox/' length = len(shuru) for i in range(length): if i % 2 == 0: filename1 = pic_dir + shuru[i] '''filename2 = pic_dir+shuru[i+1]''' lmk1 = utils.read_mat(lmk_dir + shuru[i + 1] + '.txt') lmk2 = utils.read_mat(lmk_dir + shuru[i] + '.txt') lmk = 0.5 * lmk1 + 0.5 * lmk2 image = plt.imread(filename1) #图一的landmark归一化 bbox1 = utils.read_bbox(bbox_dir + shuru[i + 1] + '.rect') lmk1 = utils.norm_landmarks(lmk1, bbox1) image = image[bbox1[1]:bbox1[3], bbox1[0]:bbox1[2]] #图一图二的插值图的landmark归一化 bbox2 = utils.read_bbox(bbox_dir + shuru[i] + '.rect') lmk = utils.norm_landmarks(lmk, bbox2) out = pwa.pwa(image.copy(), lmk1.copy(), lmk.copy(), (256, 256)) # 图片与lmk保存 utils.save_landmarks( lmk * 255, '/home/zhang/ming/save_for_lmk2/' + shuru[i][:-5] + "%d" % (200 + i) + '.jpg' + '.txt') io.imsave( '/home/zhang/ming/save_for_pic2/' + shuru[i][:-5] + "%d" % (200 + i) + '.jpg', out)
def __getitem__(self, item): image, landmarks = super(AlignDataset, self).__getitem__(item) al_ldmk = utils.read_mat(self.algin_ldmk[item]) image, _, t = self.aligner(image, al_ldmk) if self.phase == 'train': if self.flip: image, landmarks = utils.random_flip(image, landmarks, 0.5) image = utils.random_gamma_trans(image, np.random.uniform(0.8, 1.2, 1)) image = utils.random_color(image) # image = cv2.resize(image, self.shape) image = np.transpose(image, (2, 0, 1)).astype(np.float32) # landmarks = landmarks[self.ldmk_ids, :] return image, np.reshape(landmarks, (-1)), t, self.file_list[item]
def __getitem__(self, i): img_path = self.images[i] bbox_path = self.bboxes[i] landmark_path = self.landmarks[i] bbox = utils.read_bbox(bbox_path) landmarks = utils.read_mat(landmark_path) landmarks = utils.norm_landmarks(landmarks, bbox) image = cv2.imread(img_path) # minx, miny, maxx, maxy = bbox # image = image[miny:maxy+1, minx:maxx+1, :] # image = cv2.resize(image, self.shape) # cv2.imshow("t", image) # cv2.waitKey(0) image = np.transpose(image, (2, 0, 1)).astype(np.float32) #print('origin', origin_landmarks) return image, np.reshape(landmarks, (-1)), np.reshape(np.array(bbox), (2, 2))
bbox_dir = os.path.join(root, 'bbox') out_dir = os.path.join(root, 'crop') if not os.path.exists(out_dir): os.makedirs(os.path.join(out_dir, 'data/picture')) os.makedirs(os.path.join(out_dir, 'data/landmark')) for name in os.listdir(img_dir): img_name = name ldmk_name = name + '.txt' bbox_name = name + '.rect' img_path = os.path.join(img_dir, img_name) ldmk_path = os.path.join(ldmk_dir, ldmk_name) bbox_path = os.path.join(bbox_dir, bbox_name) img_out_path = img_path.replace(root, root + 'crop/').replace('.jpg', '.png') ldmk_out_path = ldmk_path.replace(root, root + 'crop/') img = plt.imread(img_path) bbox = utils.read_bbox(bbox_path) ldmk = utils.read_mat(ldmk_path) minx, miny, maxx, maxy = bbox ldmk -= [minx, miny] img = img[miny:maxy + 1, minx:maxx + 1, :] plt.imsave(img_out_path, img) utils.save_landmarks(ldmk, ldmk_out_path)
import numpy as np import cv2 from data import utils imgdir = '/data/icme/data/picture/AFW_5452623_1_5.jpg' landmarks = utils.read_mat('/data/icme/data/landmark/AFW_5452623_1_5.jpg.txt') bbox = utils.read_bbox('/data/icme/bbox/AFW_5452623_1_5.jpg.rect') img = cv2.imread(imgdir) minx, miny, maxx, maxy = bbox img = img[miny:maxy+1, minx:maxx+1, :] landmarks = utils.norm_landmarks(landmarks, bbox) img, landmarks = utils.random_flip(img, landmarks, 1) img = np.transpose(img, (2, 0, 1)) img = utils.draw_landmarks(img, landmarks, (255, 255, 255)) img = np.transpose(img, (1, 2, 0)) cv2.imshow('', img) cv2.waitKey(0)
def main(): if not os.path.exists('cache'): os.system('mkdir cache') # 我偷懒了,所以最好不要写成'/home/yqi/data/icme/' root_dir = '/data/icme' lamdmark_dir = os.path.join(root_dir, 'data/landmark') image_dir = os.path.join(root_dir, 'data/picture') bbox_dir = os.path.join(root_dir, 'bbox') try: filenames = joblib.load('cache/filenames.pkl') norm_landmarks = joblib.load('cache/norm_landmarks.pkl') mean_landmarks = joblib.load('cache/mean_landmarks.pkl') bboxes = joblib.load('cache/bboxes.pkl') split = joblib.load('cache/split.pkl') except: filenames = os.listdir(image_dir) norm_landmarks = [] bboxes = [] split = {} for filename in filenames: id = get_id(filename) if np.random.uniform(0, 1) < 0.8: split[id] = 'train' landmark_path = os.path.join(lamdmark_dir, filename + '.txt') bbox_path = os.path.join(bbox_dir, filename + '.rect') bbox = utils.read_bbox(bbox_path) landmarks = utils.read_mat(landmark_path) landmarks = utils.norm_landmarks(landmarks, bbox) norm_landmarks.append(landmarks) else: split[id] = 'valid' bbox_path = os.path.join(bbox_dir, filename + '.rect') bbox = utils.read_bbox(bbox_path) bboxes.append(bbox) norm_landmarks = np.stack(norm_landmarks, axis=0) mean_landmarks = np.mean(norm_landmarks, axis=0) joblib.dump(norm_landmarks, 'cache/norm_landmarks.pkl', compress=3) joblib.dump(mean_landmarks, 'cache/mean_landmarks.pkl', compress=3) joblib.dump(filenames, 'cache/filenames.pkl', compress=3) joblib.dump(bboxes, 'cache/bboxes.pkl', compress=3) joblib.dump(split, 'cache/split.pkl', compress=3) # for i in range(106): # plt.scatter(mean_landmarks[i, 0], mean_landmarks[i, 1]) # plt.show() try: transform_matrix = joblib.load('cache/transform_matrix.pkl') aligned = joblib.load('cache/aligned.pkl') except: transform_matrix = [] aligned = [] i = -1 for filename in filenames: if split[get_id(filename)] == 'valid': continue i += 1 curr = norm_landmarks[i, :] one = np.ones(shape=(106, 1)) curr = np.concatenate((curr, one), axis=1) t = procrustes(curr, mean_landmarks) transform_matrix.append(t) aligned.append(np.reshape(curr@t, (-1))) joblib.dump(transform_matrix, 'cache/transform_matrix.pkl', compress=3) joblib.dump(aligned, 'cache/aligned.pkl', compress=3) temp = (aligned - np.mean(aligned, axis=0)) covariance = 1.0 / len(aligned) * temp.T.dot(temp) U, S, V = np.linalg.svd(covariance) joblib.dump(U, 'cache/u.pkl', compress=3) pc = temp.dot(U[:, 0]) plt.hist(pc,bins=11) plt.show() for i, filename in enumerate(filenames): img_path = os.path.join(image_dir, filename) if pc[i] > 0.793: n = '1' elif pc[i] > 0.615: n = '2' elif pc[i] > 0.44: n = '3' elif pc[i] > 0.26: n = '4' elif pc[i] > 0.087: n = '5' elif pc[i] > -0.0913: n = '6' elif pc[i] > -0.264: n = '7' elif pc[i] > -0.448: n = '8' elif pc[i] > -0.62: n = '9' elif pc[i] > -0.79: n = '10' else: n = '11' id = get_id(filename) cmd = 'ln -s %s %s/%s/%s/%s' % (img_path, root_dir, split[id], n, filename) os.system(cmd)
import matplotlib.pyplot as plt import numpy as np from data import utils import os lmk_input = '/home/zhang/ming/save_for_lmk/' pic_input = '/home/zhang/ming/save_for_pic/' pic_filename = os.listdir(pic_input) lmk_filename = os.listdir(lmk_input) for img_name in pic_filename: img = plt.imread(pic_input + img_name) out = (np.transpose(img, (2, 0, 1))).astype(np.uint8) lmk = utils.read_mat(lmk_input + img_name + '.txt') output = utils.draw_landmarks(out, lmk / 255, (255, 0, 0)) output = np.transpose(output, (1, 2, 0)) plt.imshow(output) plt.show()
src = np.concatenate([src, add], axis=0) dst = np.concatenate([dst, add], axis=0) tform = PiecewiseAffineTransform() tform.estimate(dst, src) # out_rows ,out_cols = shape out_rows = image.shape[0] out_cols = image.shape[1] out = warp(image, tform, output_shape=(out_rows, out_cols)) return out if __name__ == '__main__': import matplotlib.pyplot as plt image = plt.imread('/data/icme/data/picture/AFW_134212_1_0.jpg') bbox = utils.read_bbox('/data/icme/bbox/AFW_134212_1_0.jpg.rect') src = utils.read_mat('/data/icme/data/landmark/AFW_134212_1_0.jpg.txt') src = utils.norm_landmarks(src, bbox) image = image[bbox[1]:bbox[3], bbox[0]:bbox[2]] bbox = utils.read_bbox('/data/icme/bbox/AFW_134212_1_3.jpg.rect') dst = utils.read_mat('/data/icme/data/landmark/AFW_134212_1_3.jpg.txt') dst = utils.norm_landmarks(dst, bbox) out = pwa(image, src, dst, (128, 128)) plt.subplot(1, 2, 1) plt.imshow(image) plt.subplot(1, 2, 2) plt.imshow(out) # plt.plot(tform.inverse(src)[:, 0], tform.inverse(src)[:, 1], '.b')
metrics = Metrics().add_nme().add_auc() model_name = 'nose-model-8400.pth' saver.load(net, model_name) all_pr = [] all_gt = [] save_dir = '/data/icme/data/pred_landmark_align_nose' base_dir = '/data/icme/data/pred_landmark_align' if not os.path.exists(save_dir): os.makedirs(save_dir) batch_iterator = iter(DataLoader(a, batch_size=1, shuffle=False, num_workers=4)) for i in range(len(a)): image, gt, t, name = next(batch_iterator) pr = utils.read_mat(os.path.join(base_dir, name[0] + '.txt')) image = image.cuda() with torch.no_grad(): nose = net.forward(image) nose = nose.cpu().data.numpy() gt = gt.data.numpy() t = t.data.numpy() nose = np.reshape(nose, (-1, 2)) nose[:, 0] *= a.shape[1] nose[:, 1] *= a.shape[0] nose = a.aligner.inverse(nose, t[0]) pr[ids] = nose gt = np.reshape(gt, (-1, 2)) all_pr.append(pr) all_gt.append(gt)
img_dir = '/data/icme/data/picture' bbox_dir = '/data/icme/bbox' landmark_dir = '/data/icme/data/landmark' aligner = alignment.Align('cache/mean_landmarks.pkl') idx = np.argsort(pc) for i in range(5000, len(idx) - 5): id = list(idx[i:i + 5]) names = filenames[id] for j in range(1, 5): src = names[0] dst = names[j] image = plt.imread(os.path.join(img_dir, src)) bbox = utils.read_bbox(os.path.join(bbox_dir, src + '.rect')) src = utils.read_mat(os.path.join(landmark_dir, src + '.txt')) image, src, _ = aligner(image, src, bbox) src[:, 0] /= aligner.scale[0] src[:, 1] /= aligner.scale[1] image2 = plt.imread(os.path.join(img_dir, dst)) bbox = utils.read_bbox(os.path.join(bbox_dir, dst + '.rect')) dst = utils.read_mat(os.path.join(landmark_dir, dst + '.txt')) image2, dst, _ = aligner(image2, dst, bbox) dst[:, 0] /= aligner.scale[0] dst[:, 1] /= aligner.scale[1] dst[0:34, :] = src[0:34, :] out = pwa.pwa(image, src, dst, (128, 128)) plt.subplot(1, 3, 1) plt.imshow(image)
img_dir = '/data/icme/data/picture' bbox_dir = '/data/icme/bbox' landmark_dir = '/data/icme/data/landmark' out_dir = '/data/expand/' N = 7 #每次选择的目标landmark数目,src_nums : dst_nums = 1 : N stop = len(idx) - N for i in range(0, stop): print('Nums:', stop - 1, 'Done:', i) id = list(idx[i:i + N + 1]) #取N + 1张图片 names = filenames[id] src_name = names[0] src_image = plt.imread(os.path.join(img_dir, src_name)) src_landmark = utils.read_mat(os.path.join(landmark_dir, src_name + '.txt')) ali_src_image, ali_src_landmark, _ = aligner(src_image.copy(), src_landmark.copy()) ali_src_landmark[:, 0] /= aligner.scale[0] ali_src_landmark[:, 1] /= aligner.scale[1] for j in range(1, N + 1): dst_name = names[j] dst_image = plt.imread(os.path.join(img_dir, dst_name)) dst_landmark = utils.read_mat( os.path.join(landmark_dir, dst_name + '.txt')) ali_dst_image, ali_dst_landmark, _ = aligner(dst_image.copy(), dst_landmark.copy()) ali_dst_landmark[:, 0] /= aligner.scale[0] ali_dst_landmark[:, 1] /= aligner.scale[1]
feature_params = dict(maxCorners=100, qualityLevel=0.3, minDistance=7, blockSize=7) # Parameters for lucas kanade optical flow lk_params = dict(winSize=(15, 15), maxLevel=2, criteria=(cv.TERM_CRITERIA_EPS | cv.TERM_CRITERIA_COUNT, 10, 0.03)) # Create some random colors # color = np.random.randint(0,255,(106,3)) # Take first frame and find corners in it old_frame = cv.imread('/data/icme/data/picture/AFW_70037463_1_2.jpg') old_gray = cv.cvtColor(old_frame, cv.COLOR_BGR2GRAY) # p0 = cv.goodFeaturesToTrack(old_gray, mask = None, **feature_params) p0 = utils.read_mat('/data/icme/data/landmark/AFW_70037463_1_2.jpg.txt') p0 = np.expand_dims(p0, 1) for new in p0: a, b = new.ravel() # c, d = old.ravel() # mask = cv.line(mask, (a,b),(c,d), color[i].tolist(), 2) frame = cv.circle(old_frame, (a, b), 2, (0, 0, 255), 1) cv.imshow("frame", frame) cv.waitKey(0) # Create a mask image for drawing purposes mask = np.zeros_like(old_frame) for i in [3, 4]: name = '/data/icme/data/picture/AFW_70037463_1_%d.jpg' % i frame = cv.imread(name) frame_gray = cv.cvtColor(frame, cv.COLOR_BGR2GRAY) # calculate optical flow
def main(): def get_id(name): t = name.split('_')[0:2] return t[0] + t[1] root_dir = 'D:\icmedata\correctdata\\' lamdmark_dir = os.path.join(root_dir, 'data/landmark') image_dir = os.path.join(root_dir, 'data/picture') bbox_dir = os.path.join(root_dir, 'bbox') filenames = os.listdir(image_dir) norm_landmarks = [] bboxes = [] split = {} for filename in filenames: id = get_id(filename) if np.random.uniform(0, 1) < 0.8: split[id] = 'train' else: split[id] = 'valid' landmark_path = os.path.join(lamdmark_dir, filename + '.txt') bbox_path = os.path.join(bbox_dir, filename + '.rect') bbox = utils.read_bbox(bbox_path) landmarks = utils.read_mat(landmark_path) landmarks = utils.norm_landmarks(landmarks, bbox) norm_landmarks.append(landmarks) bboxes.append(bbox) norm_landmarks = np.stack(norm_landmarks, axis=0) mean_landmarks = np.mean(norm_landmarks, axis=0) # for i in range(106): # plt.scatter(mean_landmarks[i, 0], mean_landmarks[i, 1]) # plt.show() target=[] for i, filename in enumerate(filenames): curr = norm_landmarks[i, :] y = curr[1::2] y_max = np.max(y) y_min = np.min(y) x = curr[::2] x_max = np.max(x) x_min = np.min(x) chang = x_max - x_min kuan = y_max - y_min Slandmark = chang * kuan #print((Slandmark)) #print(bboxes[i]) # bbox_tempt = np.array(bboxes) # Sbbox = (bbox_tempt[:, 2] - bbox_tempt[:, 0]) * (bbox_tempt[:, 3] - bbox_tempt[:, 1]) # print(Sbbox[i]) #landmark就是基于bbox做的归一化在untils。norm——landmark所以就不用求Sbbox target.append(Slandmark) draw_hist(target, 'acreage title', 'SL/SB', 'amount', 0, 1, 0, 3000) for i, filename in enumerate(filenames): img_path = os.path.join(image_dir, filename) if target[i] > 0.8: n = 's1' elif target[i] > 0.75: n = 's2' elif target[i] > 0.7: n = 's3' elif target[i] > 0.64: n = 's4' elif target[i] > 0.6: n = 's5' elif target[i] > 0.54: n = 's6' elif target[i] > 0.5: n = 's7' else: n = 's8' id = get_id(filename) cmd = 'ln -s %s %s/%s/%s/%s' % (img_path, root_dir, split[id], n, filename) os.system(cmd)
root_dir = 'D:\icmedata\sendaligned\\aligned\\' lamdmark_dir = os.path.join(root_dir, 'landmark') image_dir = os.path.join(root_dir, 'picture') #bbox_dir = os.path.join(root_dir, 'bbox') filenames = os.listdir(image_dir) for filename in filenames: id = get_id(filename) image_path = os.path.join(image_dir, filename) image = cv.imread(image_path) landmark_path = os.path.join(lamdmark_dir, filename + '.txt') landmarks = utils.read_mat(landmark_path) x = landmarks[0:33, 0] y = landmarks[0:33, 1] # img = img +255 # img.fill(255) color = (255, 255, 255) # print(landmarks[0,:]) # print(landmarks[1,:]) #脸部外轮廓 img = np.zeros((128, 128, 3), np.uint8) for j in range(32): cv.line(img, (landmarks[j, 0], landmarks[j, 1]), (landmarks[j + 1, 0], landmarks[j + 1, 1]), color,
bins = os.listdir(bin_dir) file_list = [] b = bins[pose] curr = os.path.join(bin_dir, b) files = os.listdir(curr) for i in files: file_list.append(i) for i in range(100): img_dir = os.path.join(root_dir, 'data/picture') landmark_dir = os.path.join(root_dir, 'data/landmark') bbox_dir = os.path.join(root_dir, 'bbox') images = [os.path.join(img_dir, f) for f in file_list] landmarks = [os.path.join(landmark_dir, f + '.txt') for f in file_list] bboxes = [os.path.join(bbox_dir, f + '.rect') for f in file_list] img_path = images[i] bbox_path = bboxes[i] landmark_path = landmarks[i] bbox = ul.read_bbox(bbox_path) landmarks = ul.read_mat(landmark_path) image = cv2.imread(img_path) image, landmark, t = a(image, landmarks) plt.imshow(image) plt.scatter(landmark[:, 0], landmark[:, 1]) # plt.scatter(self.reference[:, 0], self.reference[:, 1]) # plt.plot(bbox[:, 0], bbox[:, 1]) plt.xlim(0, a.scale[0]) plt.ylim(a.scale[1], 0) plt.show()
import os from utils import pwa from data import utils import numpy as np import matplotlib.pyplot as plt filename = os.listdir("/home/zhzhong/Desktop/correctdata/train/1/") img_dir = '/home/zhzhong/Desktop/correctdata/train/1/' base_dir = "/home/zhzhong/Desktop/correctdata/bbox/" new_dir = "/home/zhzhong/Desktop/newdata/1/" bbox1 = np.array([0, 0, 128, 128]) bbox2 = np.array([0, 0, 128, 128]) dst = utils.read_mat( '/home/zhzhong/Desktop/correctdata/data/landmark/AFW_5452623_1_5.jpg.txt') dst = utils.norm_landmarks(dst, bbox2) filenameforlmk = os.listdir("/home/zhzhong/Desktop/correctdata/data/landmark/") base_diroflmk = "/home/zhzhong/Desktop/correctdata/data/landmark/" for img in filename: image = plt.imread(img_dir + img) # plt.imshow(image) # plt.show() box_dir = "/home/zhzhong/Desktop/correctdata/bbox/" + img + '.rect' box = utils.read_bbox(box_dir) image = image[box[1]:box[3], box[0]:box[2]] for lmk in filenameforlmk: src = utils.read_mat(base_diroflmk + lmk) src = utils.norm_landmarks(src, bbox1) image_pwa, _ = pwa.pwa(image, src, dst, (128, 128)) #image_pwa.save(new_dir + img) plt.imshow(image_pwa) plt.show()