def load_data(file): if os.path.splitext(file)[1].lower() in [".jpg", ".jpeg"]: out = DFLJPG.load(file) else: out = DFLPNG.load(file) return out
def save_data(image_folder): files = get_file_list(image_folder) for file in files: if os.path.exists(file) == False: continue data_json = input(file) if (len(data_json) < 2): continue d = from_JSON(data_json) file_load = load_data(file) ## generate data dic dataDic = {} dataDic['type'] = d['type'] if d['type'] != '' else None dataDic['parentName'] = d['parentName'] if d['parentName'] != '' else None dataDic['rect'] = [d['x'], d['y'], d['x'] + d['w'], d['y'] + d['h']] if d['h'] != -1 else None dataDic['mat'] = [[d['matrix'][0], d['matrix'][1], d['matrix'][2]], [d['matrix'][3], d['matrix'][4], d['matrix'][5]]] if len(d['matrix']) > 0 else None dataDic['landmarks'] = d['landmarks'] if len(d['landmarks']) > 0 else None dataDic['sourceLandmarks'] = d['sourceLandmarks'] if len(d['sourceLandmarks']) > 0 else None dataDic['eyebrowsExpand'] = d['eyebrowsExpand'] if d['eyebrowsExpand'] > 0 else None dataDic['segPolys'] = d['iePolys'] if len(d['iePolys']) > 0 else None if (file_load is not None): file_load.embed_and_set(file, face_type=dataDic['type'], source_filename=dataDic['parentName'], source_landmarks=dataDic['sourceLandmarks'], source_rect=dataDic['rect'], image_to_face_mat=dataDic['mat'], landmarks=dataDic['landmarks'], seg_ie_polys=dataDic['segPolys'], eyebrows_expand_mod=dataDic['eyebrowsExpand']) else: if os.path.splitext(file)[1].lower() in [".jpg", ".jpeg"]: DFLJPG.embed_data(file, face_type=dataDic['type'], source_filename=dataDic['parentName'], source_landmarks=dataDic['sourceLandmarks'], source_rect=dataDic['rect'], image_to_face_mat=dataDic['mat'], landmarks=dataDic['landmarks'], seg_ie_polys=dataDic['segPolys'], eyebrows_expand_mod=dataDic['eyebrowsExpand']) else: DFLPNG.embed_data(file, face_type=dataDic['type'], source_filename=dataDic['parentName'], source_landmarks=dataDic['sourceLandmarks'], source_rect=dataDic['rect'], image_to_face_mat=dataDic['mat'], landmarks=dataDic['landmarks'], eyebrows_expand_mod=dataDic['eyebrowsExpand'])
def copy_to_file(image_folder, copy_folder): files = get_file_list(image_folder) for file in files: file_load = load_data(file) if file_load is not None: copy_file = os.path.join(copy_folder, os.path.basename(file)) pre, ext = os.path.splitext(copy_file) copy_file = pre + '.png' if (os.path.isfile(copy_file) == False): copy_file = pre + '.jpg' if (os.path.isfile(copy_file) == False): continue if os.path.splitext(copy_file)[1].lower() in [".jpg", ".jpeg"]: DFLJPG.embed_data(copy_file, face_type=file_load.get_face_type(), source_filename=file_load.get_source_filename(), source_landmarks=file_load.get_source_landmarks(), landmarks=file_load.get_landmarks(), source_rect=file_load.get_source_rect(), image_to_face_mat=file_load.get_image_to_face_mat(), eyebrows_expand_mod=file_load.get_eyebrows_expand_mod(), seg_ie_polys=file_load.get_seg_ie_polys(), xseg_mask=file_load.get_xseg_mask() ) else: DFLPNG.embed_data(copy_file, face_type=file_load.get_face_type(), source_filename=file_load.get_source_filename(), source_landmarks=file_load.get_source_landmarks(), landmarks=file_load.get_landmarks(), source_rect=file_load.get_source_rect(), eyebrows_expand_mod=file_load.get_eyebrows_expand_mod(), image_to_face_mat=file_load.get_image_to_face_mat() ) sys.stdout.write(file + '\n')