def load_instances(input_filepath, output_filepath, mesh_list, symemtry_part_index): dirnames = glob.glob(input_filepath + "/*") exp_name = os.path.basename(os.path.normpath(input_filepath + "/../")) exp_output_filepath = output_filepath + "/images/" + exp_name print (exp_name) if not os.path.isdir(output_filepath + "/images/"): os.mkdir(output_filepath + "/images/") if not os.path.isdir(exp_output_filepath): os.mkdir(exp_output_filepath) instances = [] for dirname in dirnames: if not os.path.isdir(dirname): continue prefix = os.path.basename(dirname) # print prefix if not prefix in mesh_list: continue abs_dirname = os.path.abspath(dirname) is_loaded = True candidate_index = librr.find_best_candidate(dirname, prefix) # print('Candidate index: ' + str(candidate_index)) absolute_image_filepath = [] image_filenames = [] # image_filenames.append(prefix + '_view.png') image_filenames.append(prefix + "_input.png") image_filenames.append("../../part_assembly/" + prefix + "/" + prefix + "_assembly_cuboid.png") image_filenames.append("../../part_assembly/" + prefix + "/" + prefix + "_assembly_accuracy.png") image_filenames.append(prefix + "_" + str(candidate_index) + ".png") # image_filenames.append(prefix + '_' + str(candidate_index) + '_symmetry_accuracy.png') # image_filenames.append(prefix + '_' + str(candidate_index) + '_symmetry_completeness.png') image_filenames.append(prefix + "_" + str(candidate_index) + "_database_accuracy.png") # image_filenames.append(prefix + '_' + str(candidate_index) + '_database_completeness.png') # image_filenames.append(prefix + '_' + str(candidate_index) + '_fusion_accuracy.png') # image_filenames.append(prefix + '_' + str(candidate_index) + '_fusion_completeness.png') for image_filename in image_filenames: if not os.path.exists(dirname + "/" + image_filename): print 'Warning: File does not exist: "' + (dirname + "/" + image_filename) + '"' is_loaded = False break if not os.path.exists(output_filepath + "/" + image_filename): # Copy the image. shutil.copy(dirname + "/" + image_filename, exp_output_filepath) """ # Create a thumbnail. librr.create_thumbnails(output_filepath + '/' + image_filename, librr.thumbname_width) """ # Get relative file path. # absolute_image_filepath.append(abs_dirname + '/' + image_filename) absolute_image_filepath.append("images/" + exp_name + "/" + os.path.basename(image_filename)) if not is_loaded: continue accuracy_values = [] completeness_values = [] csv_filename_postfixes = [] csv_filename_postfixes.append("_" + str(candidate_index) + "_symmetry") csv_filename_postfixes.append("_" + str(candidate_index) + "_database") csv_filename_postfixes.append("_" + str(candidate_index) + "_fusion") for csv_filename_postfix in csv_filename_postfixes: csv_filename = dirname + "/" + prefix + csv_filename_postfix + ".csv" if symemtry_part_index >= 0: # Read per-part files. csv_filename = dirname + "/" + prefix + csv_filename_postfix + "_" + str(symemtry_part_index) + ".csv" all_values = librr.get_csv_value(csv_filename, librr.threshold) if not all_values: accuracy_values.append(float("NaN")) completeness_values.append(float("NaN")) else: accuracy_values.append(all_values[0]) completeness_values.append(all_values[1]) instance = OutputInstance( # prefix, absolute_image_filepath[0], absolute_image_filepath[1], absolute_image_filepath[2], absolute_image_filepath[3], absolute_image_filepath[4], # absolute_image_filepath[5], # absolute_image_filepath[6], # absolute_image_filepath[7], # absolute_image_filepath[8], # accuracy_values[0], completeness_values[0], # accuracy_values[1], completeness_values[1], # accuracy_values[2], completeness_values[2] ) instances.append(instance) return instances
def load_instances(input_filepath, output_filepath, symemtry_part_index): dirnames = glob.glob(input_filepath + '/*') instances = [] for dirname in dirnames: if not os.path.isdir(dirname): continue prefix = os.path.basename(dirname) print prefix abs_dirname = os.path.abspath(dirname) is_loaded = True candidate_index = librr.find_best_candidate(dirname, prefix) print('Candidate index: ' + str(candidate_index)) absolute_image_filepath = [] image_filenames = [] image_filenames.append(prefix + '_view.png') image_filenames.append(prefix + '_input.png') image_filenames.append(prefix + '_' + str(candidate_index) + '.png') image_filenames.append(prefix + '_' + str(candidate_index) + '_symmetry_accuracy.png') image_filenames.append(prefix + '_' + str(candidate_index) + '_symmetry_completeness.png') image_filenames.append(prefix + '_' + str(candidate_index) + '_database_accuracy.png') image_filenames.append(prefix + '_' + str(candidate_index) + '_database_completeness.png') image_filenames.append(prefix + '_' + str(candidate_index) + '_fusion_accuracy.png') image_filenames.append(prefix + '_' + str(candidate_index) + '_fusion_completeness.png') for image_filename in image_filenames: if not os.path.exists(dirname + '/' + image_filename): print 'Warning: File does not exist: "' + (dirname + '/' + image_filename) + '"' is_loaded = False break if not os.path.exists(output_filepath + '/' + image_filename): ''' # Copy the image. shutil.copy(dirname + '/' + image_filename, output_filepath) # Create a thumbnail. librr.create_thumbnails(output_filepath + '/' + image_filename, librr.thumbname_width) ''' # Get relative file path. absolute_image_filepath.append(abs_dirname + '/' + image_filename) if not is_loaded: continue accuracy_values = [] completeness_values = [] csv_filename_postfixes = [] csv_filename_postfixes.append('_' + str(candidate_index) + '_symmetry') csv_filename_postfixes.append('_' + str(candidate_index) + '_database') csv_filename_postfixes.append('_' + str(candidate_index) + '_fusion') for csv_filename_postfix in csv_filename_postfixes: csv_filename = dirname + '/' + prefix + csv_filename_postfix + '.csv' if symemtry_part_index >= 0: # Read per-part files. csv_filename = dirname + '/' + prefix + csv_filename_postfix\ + '_' + str(symemtry_part_index) + '.csv' all_values = librr.get_csv_value(csv_filename, librr.threshold) if not all_values: accuracy_values.append(float("NaN")) completeness_values.append(float("NaN")) else: accuracy_values.append(all_values[0]) completeness_values.append(all_values[1]) instance = OutputInstance(prefix, absolute_image_filepath[0], absolute_image_filepath[1], absolute_image_filepath[2], absolute_image_filepath[3], absolute_image_filepath[4], absolute_image_filepath[5], absolute_image_filepath[6], absolute_image_filepath[7], absolute_image_filepath[8], accuracy_values[0], completeness_values[0], accuracy_values[1], completeness_values[1], accuracy_values[2], completeness_values[2]) instances.append(instance) return instances
def load_instances(input_filepath, output_filepath, symemtry_part_index): dirnames = glob.glob(input_filepath + '/*') instances = [] for dirname in dirnames: if not os.path.isdir(dirname): continue prefix = os.path.basename(dirname) print prefix is_loaded = True candidate_index = librr.find_best_candidate(dirname, prefix) print('Candidate index: ' + str(candidate_index)) # Read images. relative_image_filepath = [] image_filenames = [] image_filenames.append(prefix + '_view.png') image_filenames.append(prefix + '_input.png') image_filenames.append(prefix + '_' + str(candidate_index) + '.png') image_filenames.append(prefix + '_' + str(candidate_index) + '_symmetry_accuracy.png') image_filenames.append(prefix + '_' + str(candidate_index) + '_symmetry_completeness.png') image_filenames.append(prefix + '_' + str(candidate_index) + '_database_accuracy.png') image_filenames.append(prefix + '_' + str(candidate_index) + '_database_completeness.png') image_filenames.append(prefix + '_' + str(candidate_index) + '_fusion_accuracy.png') image_filenames.append(prefix + '_' + str(candidate_index) + '_fusion_completeness.png') for image_filename in image_filenames: if not os.path.exists(dirname + '/' + image_filename): print 'Warning: File does not exist: "' + ( dirname + '/' + image_filename) + '"' is_loaded = False break if not os.path.exists(output_filepath + '/' + image_filename): # Copy the image. shutil.copy(dirname + '/' + image_filename, output_filepath) # Create a thumbnail. librr.create_thumbnails(output_filepath + '/' + image_filename, librr.thumbname_width) # Get relative file path. relative_image_filepath.append('./' + image_filename) if not is_loaded: continue # Read stats. accuracy_values = [] completeness_values = [] csv_filename_postfixes = [] csv_filename_postfixes.append('_' + str(candidate_index) + '_symmetry') csv_filename_postfixes.append('_' + str(candidate_index) + '_database') csv_filename_postfixes.append('_' + str(candidate_index) + '_fusion') for csv_filename_postfix in csv_filename_postfixes: csv_filename = dirname + '/' + prefix + csv_filename_postfix + '.csv' if symemtry_part_index >= 0: # Read per-part files. csv_filename = dirname + '/' + prefix + csv_filename_postfix\ + '_' + str(symemtry_part_index) + '.csv' if not os.path.exists(csv_filename): print 'Warning: File does not exist: "' + csv_filename + '"' is_loaded = False break else: all_values = librr.get_csv_value(csv_filename, librr.threshold) if not all_values: accuracy_values.append(float("NaN")) completeness_values.append(float("NaN")) else: accuracy_values.append(all_values[0]) completeness_values.append(all_values[1]) if not is_loaded: continue # Read per-point labeling accuracy. csv_filename = dirname + '/' + prefix + '_' + str( candidate_index) + '_labeling_stats.csv' if not os.path.exists(csv_filename): print 'Warning: File does not exist: "' + csv_filename + '"' continue else: per_point_labeling_accuracy = read_value_from_csv_file( csv_filename, symemtry_part_index, 3) # Read cuboid distance to ground truth. csv_filename = dirname + '/' + prefix + '_' + str( candidate_index) + '_cuboid_distance.csv' if not os.path.exists(csv_filename): print 'Warning: File does not exist: "' + csv_filename + '"' continue else: cuboid_distance_to_ground_truth = read_value_from_csv_file( csv_filename, symemtry_part_index, 1) instance = OutputInstance( prefix, relative_image_filepath[0], relative_image_filepath[1], relative_image_filepath[2], relative_image_filepath[3], relative_image_filepath[4], relative_image_filepath[5], relative_image_filepath[6], relative_image_filepath[7], relative_image_filepath[8], accuracy_values[0], completeness_values[0], accuracy_values[1], completeness_values[1], accuracy_values[2], completeness_values[2], per_point_labeling_accuracy, cuboid_distance_to_ground_truth) instances.append(instance) return instances
def load_instances(input_filepath, output_filepath): dirnames = glob.glob(input_filepath + '/*') all_accu_values = [[], [], [], [], []] all_comp_values = [[], [], [], [], []] x_values = [] count_instances = 0 for dirname in dirnames: if not os.path.isdir(dirname): continue prefix = os.path.basename(dirname) #print prefix is_loaded = True candidate_index = librr.find_best_candidate(dirname, prefix) #print('Candidate index: ' + str(candidate_index)) relative_image_filepath = [] image_filenames = [] image_filenames.append(prefix + '_view.png') image_filenames.append(prefix + '_input.png') image_filenames.append(prefix + '_' + str(candidate_index) + '.png') image_filenames.append(prefix + '_' + str(candidate_index) + '_symmetry_accuracy.png') image_filenames.append(prefix + '_' + str(candidate_index) + '_symmetry_completeness.png') image_filenames.append(prefix + '_' + str(candidate_index) + '_database_accuracy.png') image_filenames.append(prefix + '_' + str(candidate_index) + '_database_completeness.png') image_filenames.append(prefix + '_' + str(candidate_index) + '_fusion_accuracy.png') image_filenames.append(prefix + '_' + str(candidate_index) + '_fusion_completeness.png') for image_filename in image_filenames: if not os.path.exists(dirname + '/' + image_filename): print 'Warning: File does not exist: "' + (dirname + '/' + image_filename) + '"' is_loaded = False break if not is_loaded: continue csv_filename_postfixes = [] csv_filename_postfixes.append(prefix + '_' + str(candidate_index) + '_symmetry') csv_filename_postfixes.append(prefix + '_' + str(candidate_index) + '_database') csv_filename_postfixes.append(prefix + '_' + str(candidate_index) + '_fusion') csv_filename_postfixes.append('/../../part_assembly/' + prefix + '/' + prefix +'_assembly') csv_filename_postfixes.append('/../../symmetry_detection/' + prefix + '/' + prefix +'_symm_detection_recon') file_exist = True for i in range(len(csv_filename_postfixes)): csv_filename_postfix = csv_filename_postfixes[i] csv_filename = dirname + '/' + csv_filename_postfix + '.csv' if not os.path.isfile(csv_filename): file_exist = False break if not file_exist: continue for i in range(len(csv_filename_postfixes)): csv_filename_postfix = csv_filename_postfixes[i] csv_filename = dirname + '/' + csv_filename_postfix + '.csv' if not os.path.isfile(csv_filename): continue (accu_values, comp_values, x_values) = librr.get_csv_all_value(csv_filename) if not all_accu_values[i]: all_accu_values[i] = accu_values if not all_comp_values[i]: all_comp_values[i] = comp_values all_accu_values[i] = [x+y for x,y in zip(all_accu_values[i], accu_values)] all_comp_values[i] = [x+y for x,y in zip(all_comp_values[i], comp_values)] count_instances += 1 if count_instances > 0: for i in range(len(all_accu_values)): all_accu_values[i] = [x / count_instances for x in all_accu_values[i]] for i in range(len(all_comp_values)): all_comp_values[i] = [x / count_instances for x in all_comp_values[i]] return (all_accu_values, all_comp_values, x_values)
def load_instances(input_filepath, output_filepath, symemtry_part_index): dirnames = glob.glob(input_filepath + '/*') instances = [] for dirname in dirnames: if not os.path.isdir(dirname): continue prefix = os.path.basename(dirname) print prefix is_loaded = True candidate_index = librr.find_best_candidate(dirname, prefix) print('Candidate index: ' + str(candidate_index)) # Read images. relative_image_filepath = [] image_filenames = [] image_filenames.append(prefix + '_view.png') image_filenames.append(prefix + '_input.png') image_filenames.append(prefix + '_' + str(candidate_index) + '.png') image_filenames.append(prefix + '_' + str(candidate_index) + '_symmetry_accuracy.png') image_filenames.append(prefix + '_' + str(candidate_index) + '_symmetry_completeness.png') image_filenames.append(prefix + '_' + str(candidate_index) + '_database_accuracy.png') image_filenames.append(prefix + '_' + str(candidate_index) + '_database_completeness.png') image_filenames.append(prefix + '_' + str(candidate_index) + '_fusion_accuracy.png') image_filenames.append(prefix + '_' + str(candidate_index) + '_fusion_completeness.png') for image_filename in image_filenames: if not os.path.exists(dirname + '/' + image_filename): print 'Warning: File does not exist: "' + (dirname + '/' + image_filename) + '"' is_loaded = False break if not os.path.exists(output_filepath + '/' + image_filename): # Copy the image. shutil.copy(dirname + '/' + image_filename, output_filepath) # Create a thumbnail. librr.create_thumbnails(output_filepath + '/' + image_filename, librr.thumbname_width) # Get relative file path. relative_image_filepath.append('./' + image_filename) if not is_loaded: continue # Read stats. accuracy_values = [] completeness_values = [] csv_filename_postfixes = [] csv_filename_postfixes.append('_' + str(candidate_index) + '_symmetry') csv_filename_postfixes.append('_' + str(candidate_index) + '_database') csv_filename_postfixes.append('_' + str(candidate_index) + '_fusion') for csv_filename_postfix in csv_filename_postfixes: csv_filename = dirname + '/' + prefix + csv_filename_postfix + '.csv' if symemtry_part_index >= 0: # Read per-part files. csv_filename = dirname + '/' + prefix + csv_filename_postfix\ + '_' + str(symemtry_part_index) + '.csv' if not os.path.exists(csv_filename): print 'Warning: File does not exist: "' + csv_filename + '"' is_loaded = False break else: all_values = librr.get_csv_value(csv_filename, librr.threshold) if not all_values: accuracy_values.append(float("NaN")) completeness_values.append(float("NaN")) else: accuracy_values.append(all_values[0]) completeness_values.append(all_values[1]) if not is_loaded: continue # Read per-point labeling accuracy. csv_filename = dirname + '/' + prefix + '_' + str(candidate_index) + '_labeling_stats.csv' if not os.path.exists(csv_filename): print 'Warning: File does not exist: "' + csv_filename + '"' continue else: per_point_labeling_accuracy = read_value_from_csv_file(csv_filename, symemtry_part_index, 3) # Read cuboid distance to ground truth. csv_filename = dirname + '/' + prefix + '_' + str(candidate_index) + '_cuboid_distance.csv' if not os.path.exists(csv_filename): print 'Warning: File does not exist: "' + csv_filename + '"' continue else: cuboid_distance_to_ground_truth = read_value_from_csv_file(csv_filename, symemtry_part_index, 1) instance = OutputInstance(prefix, relative_image_filepath[0], relative_image_filepath[1], relative_image_filepath[2], relative_image_filepath[3], relative_image_filepath[4], relative_image_filepath[5], relative_image_filepath[6], relative_image_filepath[7], relative_image_filepath[8], accuracy_values[0], completeness_values[0], accuracy_values[1], completeness_values[1], accuracy_values[2], completeness_values[2], per_point_labeling_accuracy, cuboid_distance_to_ground_truth) instances.append(instance) return instances
def load_instances(input_filepath, output_filepath, symemtry_part_index): output_file_prefix = os.path.basename(os.path.normpath(input_filepath + '/../')) dirnames = glob.glob(input_filepath + '/*') print(output_file_prefix + '_ours.csv') print(output_file_prefix + '_podolak.csv') ours_file = open(output_file_prefix + '_ours.csv', 'w') podolak_file = open(output_file_prefix + '_podolak.csv', 'w') for dirname in dirnames: if not os.path.isdir(dirname): continue prefix = os.path.basename(dirname) print prefix is_loaded = True candidate_index = librr.find_best_candidate(dirname, prefix) print('Candidate index: ' + str(candidate_index)) relative_image_filepath = [] image_filenames = [] image_filenames.append(prefix + '_view.png') image_filenames.append(prefix + '_input.png') image_filenames.append(prefix + '_' + str(candidate_index) + '.png') image_filenames.append(prefix + '_' + str(candidate_index) + '_symmetry_accuracy.png') image_filenames.append(prefix + '_' + str(candidate_index) + '_symmetry_completeness.png') image_filenames.append(prefix + '_' + str(candidate_index) + '_database_accuracy.png') image_filenames.append(prefix + '_' + str(candidate_index) + '_database_completeness.png') image_filenames.append(prefix + '_' + str(candidate_index) + '_fusion_accuracy.png') image_filenames.append(prefix + '_' + str(candidate_index) + '_fusion_completeness.png') for image_filename in image_filenames: if not os.path.exists(dirname + '/' + image_filename): print 'Warning: File does not exist: "' + (dirname + '/' + image_filename) + '"' is_loaded = False break # Get relative file path. relative_image_filepath.append('./' + image_filename) if not is_loaded: continue ours_symm_filename_postfix = '_' + str(candidate_index) + '_symmetry_info.txt' ours_symm_filename = dirname + '/' + prefix + ours_symm_filename_postfix if os.path.exists(ours_symm_filename): with open(ours_symm_filename, 'r') as csv_file: data = csv.reader(csv_file, delimiter=',') x_data = data.next() n = np.array([float(x_data[1]), float(x_data[2]), float(x_data[3])]) t = float(x_data[4]) n = n / np.linalg.norm(n) ours_file.write(str(n[0]) + ',' + str(n[1]) + ',' + str(n[2]) + ',' + str(t) + '\n') podolak_symm_filename_postfix = '_symmetry_info.txt' podolak_symm_filename = dirname + '/../../symmetry_detection/' + prefix + '/' + prefix + podolak_symm_filename_postfix print(podolak_symm_filename) if os.path.exists(podolak_symm_filename): with open(podolak_symm_filename, 'r') as csv_file: data = csv.reader(csv_file, delimiter=',') x_data = data.next() n = np.array([float(x_data[1]), float(x_data[2]), float(x_data[3])]) t = float(x_data[4]) n = n / np.linalg.norm(n) podolak_file.write(str(n[0]) + ',' + str(n[1]) + ',' + str(n[2]) + ',' + str(t) + '\n') ours_file.close() podolak_file.close()