def run_global_CIF_metrics(input, output):
    if os.path.exists(output[0]): os.unlink(output[0])
    lines_to_add = [
                    "varout_1 = '%s*" % output[0],
                    "var_database = %s*" % options.database_file,
                    ]
    run_matlab_script_compiled(options.fr_matlab_scripts_dir +"dbp_6_CIF_stats_X.m", lines_to_add, mulitcore_matlab=MATLAB_MULTICORE_MODE, queue_run=QUEUE_RUN_MODE, cluster_run=CLUSTER_RUN_MODE, debug = DEBUGGING_MODE)
    hold_for_output(output[0])
def convert_original_to_jpeg(input, output):
    
    try: os.mkdir(os.path.split(output)[0])
    except: pass
    if os.path.exists(output): os.unlink(output)
    lines_to_add = [
                    "varin_1 = '%s'" % input,
                    "var_database = %s*" % options.database_file,
                    "varin_image_path = %s*" % input,
                    "varout_image_path = %s*" % output,
                    ]
    run_matlab_script_compiled(options.fr_matlab_scripts_dir +"dbp_0_create_jpeg_X.m", lines_to_add, mulitcore_matlab=MATLAB_MULTICORE_MODE, queue_run=QUEUE_RUN_MODE, cluster_run=CLUSTER_RUN_MODE, debug = DEBUGGING_MODE)
    hold_for_output(output)
def run_improved_landmark_detection(input, output):
    
    if os.path.exists(output): os.unlink(output)
    lines_to_add = [
                    "varin_1 = '%s'" % input,
                    "varin_2 = '%s'" % options.VJ_root_path,
                    "varin_3 = '%s'" % options.Face_feat_model,
                    "var_database = %s*" % options.database_file,
                    "varout_1 = '%s*" % output,
                    ]
    list_of_non_symlink_var = [
                               "varin_image_path = %s*" % os.path.abspath(input),
                               ]
    run_matlab_script_compiled(options.fr_matlab_scripts_dir +"dbp_2_find_facial_lands_X.m", lines_to_add, list_of_non_symlink_var=list_of_non_symlink_var, mulitcore_matlab=MATLAB_MULTICORE_MODE, queue_run=QUEUE_RUN_MODE, cluster_run=CLUSTER_RUN_MODE, debug = DEBUGGING_MODE)
    
    hold_for_output(output)
def run_FS_feature_transform(input, output):
    #sys.exit(1)
    if os.path.exists(output[0]): os.unlink(output[0])
    try: os.mkdir(os.path.split(output[0])[0])
    except: assert  os.path.exists(os.path.split(output[0])[0])
    lines_to_add = [
                    "varin_1 = %s*" % input[0][0],
                    "varin_2 = %s*" % options.FS_model,
                    #"varin_3 = '%s'" % options.Face_feat_model,
                    "varout_1 = '%s*" % output[0],
                    "var_database = %s*" % options.database_file,
                    ]
    list_of_non_symlink_var = [
                               "varin_image_path = %s*" % os.path.abspath(input[0][0]),
                               ]
    run_matlab_script_compiled(options.fr_matlab_scripts_dir +"dbp_5_lmnn_vectors_X.m", lines_to_add, list_of_non_symlink_var=list_of_non_symlink_var, mulitcore_matlab=MATLAB_MULTICORE_MODE, queue_run=QUEUE_RUN_MODE, cluster_run=CLUSTER_RUN_MODE, debug = DEBUGGING_MODE)
    hold_for_output(output[0])
def run_AAM_fitting(input, output):

    if os.path.exists(output): os.unlink(output)
    lines_to_add = [
                    "varin_1 = '%s'" % input[0][1],
                    "varin_2 = '%s'" % input[0][0],
                    #"varin_image_path = '%s*" % input[0][1],
                    "varin_3 = %s*" % options.AAM_models,
                    "varout_1 = '%s*" % output,
                    "var_database = %s*" % options.database_file,
                    ]
    list_of_non_symlink_var = [
                               "varin_image_path = %s*" % os.path.abspath(input[0][1]),
                               ]
    run_matlab_script_compiled(options.fr_matlab_scripts_dir +"dbp_3_AAM_X.m", lines_to_add, list_of_non_symlink_var=list_of_non_symlink_var, mulitcore_matlab=MATLAB_MULTICORE_MODE, queue_run=QUEUE_RUN_MODE, cluster_run=CLUSTER_RUN_MODE, debug = DEBUGGING_MODE)
    #run_matlab_script_compiled(options.fr_matlab_scripts_dir +"pipe_3_AAM_X.m", lines_to_add, mulitcore_matlab=MATLAB_MULTICORE_MODE, queue_run=QUEUE_RUN_MODE, cluster_run=CLUSTER_RUN_MODE, debug = DEBUGGING_MODE)
    #except:
    #    open(output, "w").close()
    hold_for_output(output)
def create_processing_data_record(input, output):
    
    original_image_name = "".join(input.split(PIPE_OUT_FOLDER))[:-4]
    original_image_name_suffix = original_image_name.split("_")[-1]
    original_image_name = original_image_name[:-len(original_image_name_suffix)-1]+"."+original_image_name_suffix
    
    
    #####
    try: os.mkdir(os.path.split(output)[0])
    except: pass
    if os.path.exists(output): os.unlink(output)
    
    lines_to_add = [
                    "varin_1 = '%s'" % original_image_name,
                    "var_database = %s*" % options.database_file,
                    "varout_1 = %s*" % output,
                    ]
    list_of_non_symlink_var = [
                               "varin_image_path = %s*" % os.path.abspath(input),
                               "varout_image_path = %s*" % os.path.abspath(output[:-4]+"jpg"),
                               ]
    run_matlab_script_compiled(options.fr_matlab_scripts_dir +"dbp_1_store_image_X.m", lines_to_add,list_of_non_symlink_var=list_of_non_symlink_var, mulitcore_matlab=MATLAB_MULTICORE_MODE, queue_run=QUEUE_RUN_MODE, cluster_run=CLUSTER_RUN_MODE, debug = DEBUGGING_MODE)
    #run_matlab_script_compiled(options.fr_matlab_scripts_dir +"pipe_0_png2jpg_X.m", lines_to_add, mulitcore_matlab=MATLAB_MULTICORE_MODE, queue_run=QUEUE_RUN_MODE, cluster_run=CLUSTER_RUN_MODE, debug = DEBUGGING_MODE)
    hold_for_output(output)
def create_database(input, output):
    lines_to_add = [
                    "var_database = %s*" % options.database_file,
                    ]
    run_matlab_script_compiled(options.fr_matlab_scripts_dir +"dbp_0_create_DB_X.m", lines_to_add, mulitcore_matlab=MATLAB_MULTICORE_MODE, queue_run=QUEUE_RUN_MODE, cluster_run=CLUSTER_RUN_MODE, debug = DEBUGGING_MODE)
    hold_for_output(output)