#NEWLINE# def gen_aligned_faces( basedir ) : #NEWLINE# #INDENT# '\n    Generates aligned face data from normal face data.\n    ' #NEWLINE# face_files = glob . glob ( join ( basedir , FACE_SUBDIR , '*' ) ) #NEWLINE# aligned_face_dir = join ( lm_file_base , ALIGNED_FACE_SUBDIR ) #NEWLINE# if ( not os . path . exists ( aligned_face_dir ) ) : #NEWLINE# #INDENT# os . mkdir ( aligned_face_dir ) #NEWLINE# #UNINDENT# ref_face = imread ( join ( basedir , FACE_SUBDIR , 'S011_006_00000001.png' ) , False ) #NEWLINE# ref_lms = read_landmarks ( join ( basedir , FACE_LM_SUBDIR , 'S011_006_00000001_landmarks.txt' ) ) #NEWLINE# for ( idx , face_file ) in enumerate ( face_files ) : #NEWLINE# #INDENT# face = cv2 . imread ( face_file , False ) #NEWLINE# lm_file_base = ( os . path . basename ( face_file ) . split ( '.' ) [ 0 ] + '_landmarks.txt' ) #NEWLINE# lms = read_landmarks ( join ( basedir , FACE_LM_SUBDIR , lm_file_base ) ) #NEWLINE# aligned_face = pwa . warp ( face , lms , ref_lms ) #NEWLINE# aligned_face_file = join ( aligned_face_dir , os . path . basename ( face_file ) ) #NEWLINE# cv2 . imwrite ( aligned_face_file , aligned_face ) #NEWLINE# if ( ( ( idx % 50 ) == 0 ) and ( idx != 0 ) ) : #NEWLINE# #INDENT# print ( ( '%d files processed' % idx ) ) #NEWLINE# #UNINDENT# #UNINDENT# print ( 'Done.' )