1 // This is brl/bseg/bapl/pro/processes/bapl_connectivity_processes.cxx 2 #include <bapl/bapl_connectivity.h> 3 //: 4 // \file 5 // \brief Processes to find tracks from a connectivity graph of an image set 6 // 7 // \author Ozge Can Ozcanli 8 // \date September 16, 2010 9 // 10 // \verbatim 11 // Modifications 12 // none 13 // \endverbatim 14 15 #include <bprb/bprb_func_process.h> 16 #include <bprb/bprb_parameters.h> 17 18 #include <bapl/bapl_connectivity_sptr.h> 19 #include <bapl/bapl_keypoint_set.h> 20 21 //: Constructor 22 // sets up an empty table instance bapl_create_conn_table_process_cons(bprb_func_process & pro)23bool bapl_create_conn_table_process_cons(bprb_func_process& pro) 24 { 25 bool ok=false; 26 std::vector<std::string> input_types; 27 ok = pro.set_input_types(input_types); 28 input_types.emplace_back("int"); // number of images 29 if (!ok) return ok; 30 31 std::vector<std::string> output_types; 32 output_types.emplace_back("bapl_conn_table_sptr"); 33 ok = pro.set_output_types(output_types); 34 if (!ok) return ok; 35 return true; 36 } 37 bapl_create_conn_table_process(bprb_func_process & pro)38bool bapl_create_conn_table_process(bprb_func_process& pro) 39 { 40 // Sanity check 41 if (pro.n_inputs() < 1) { 42 std::cout << "bapl_create_conn_table_process: The input number should be 1" << std::endl; 43 return false; 44 } 45 unsigned i=0; 46 int n_images = pro.get_input<int>(i++); 47 48 bapl_conn_table_sptr table = new bapl_conn_table(n_images); 49 pro.set_output_val<bapl_conn_table_sptr>(0, table); 50 return true; 51 } 52 53 //: Constructor 54 // add a match set to the table bapl_add_match_set_process_cons(bprb_func_process & pro)55bool bapl_add_match_set_process_cons(bprb_func_process& pro) 56 { 57 bool ok=false; 58 std::vector<std::string> input_types; 59 input_types.emplace_back("bapl_conn_table_sptr"); 60 input_types.emplace_back("bapl_keypoint_match_set_sptr"); 61 ok = pro.set_input_types(input_types); 62 if (!ok) return ok; 63 64 std::vector<std::string> output_types; 65 ok = pro.set_output_types(output_types); 66 if (!ok) return ok; 67 return true; 68 } 69 bapl_add_match_set_process(bprb_func_process & pro)70bool bapl_add_match_set_process(bprb_func_process& pro) 71 { 72 // Sanity check 73 if (pro.n_inputs() < 2) { 74 std::cout << "bapl_add_match_set_process: The input number should be 2" << std::endl; 75 return false; 76 } 77 // get the inputs 78 unsigned i=0; 79 bapl_conn_table_sptr tab = pro.get_input<bapl_conn_table_sptr>(i++); 80 bapl_keypoint_match_set_sptr set = pro.get_input<bapl_keypoint_match_set_sptr>(i++); 81 if (!tab->add_sym(set)) { 82 std::cout << "In bapl_add_match_set_process() -- cannot add match set for image pair: (" << set->id_left_ << ", " << set->id_right_ << ")!\n"; 83 return false; 84 } 85 std::cout << *tab << std::endl; 86 87 return true; 88 } 89 90 //: Constructor 91 // add a match set to the table bapl_add_image_keys_process_cons(bprb_func_process & pro)92bool bapl_add_image_keys_process_cons(bprb_func_process& pro) 93 { 94 bool ok=false; 95 std::vector<std::string> input_types; 96 input_types.emplace_back("bapl_conn_table_sptr"); 97 input_types.emplace_back("int"); 98 input_types.emplace_back("bapl_keypoint_set_sptr"); 99 ok = pro.set_input_types(input_types); 100 if (!ok) return ok; 101 102 std::vector<std::string> output_types; 103 ok = pro.set_output_types(output_types); 104 if (!ok) return ok; 105 return true; 106 } 107 bapl_add_image_keys_process(bprb_func_process & pro)108bool bapl_add_image_keys_process(bprb_func_process& pro) 109 { 110 // Sanity check 111 if (pro.n_inputs() < 3) { 112 std::cout << "bapl_add_image_keys_process: The input number should be 3" << std::endl; 113 return false; 114 } 115 // get the inputs 116 unsigned i=0; 117 bapl_conn_table_sptr tab = pro.get_input<bapl_conn_table_sptr>(i++); 118 int img_id = pro.get_input<int>(i++); 119 bapl_keypoint_set_sptr set = pro.get_input<bapl_keypoint_set_sptr>(i++); 120 tab->add_image_data(img_id, set); 121 return true; 122 } 123 bapl_compute_tracks_process_cons(bprb_func_process & pro)124bool bapl_compute_tracks_process_cons(bprb_func_process& pro) 125 { 126 bool ok=false; 127 std::vector<std::string> input_types; 128 input_types.emplace_back("bapl_conn_table_sptr"); 129 input_types.emplace_back("vcl_string"); // output file to print correspondences 130 ok = pro.set_input_types(input_types); 131 if (!ok) return ok; 132 133 std::vector<std::string> output_types; 134 ok = pro.set_output_types(output_types); 135 if (!ok) return ok; 136 return true; 137 } 138 bapl_compute_tracks_process(bprb_func_process & pro)139bool bapl_compute_tracks_process(bprb_func_process& pro) 140 { 141 // Sanity check 142 if (pro.n_inputs() < 2) { 143 std::cout << "bapl_compute_tracks_process: The input number should be 2" << std::endl; 144 return false; 145 } 146 // get the inputs 147 unsigned i=0; 148 bapl_conn_table_sptr tab = pro.get_input<bapl_conn_table_sptr>(i++); 149 std::string out_file = pro.get_input<std::string>(i++); 150 std::cout << "match table (should be symmetric):" << std::endl; 151 tab->print_table(); 152 std::vector<bapl_track_data> tracks; 153 tab->compute_tracks(tracks); 154 155 // Print tracks as correspondences in BWM_VIDEO_SITE format for visualization 156 std::ofstream os(out_file.c_str()); 157 print_tracks(os, tracks); 158 os.close(); 159 160 return true; 161 } 162