1 // This is brl/bpro/core/vil_pro/processes/bil_create_arf_image_istream_process.cxx 2 #include <iostream> 3 #include <string> 4 #include <sstream> 5 #include <bprb/bprb_func_process.h> 6 //: 7 // \file 8 9 #include <bprb/bprb_parameters.h> 10 #ifdef _MSC_VER 11 # include "vcl_msvc_warnings.h" 12 #endif 13 #include "vil/vil_image_view_base.h" 14 #include <bil/bil_arf_image_istream.h> 15 16 17 //: Constructor bil_create_arf_image_istream_process_cons(bprb_func_process & pro)18bool bil_create_arf_image_istream_process_cons(bprb_func_process& pro) 19 { 20 //process takes 1 input 21 std::vector<std::string> input_types_(1); 22 input_types_[0] = "vcl_string"; //raw file 23 24 // process has 1 output: 25 std::vector<std::string> output_types_(2); 26 output_types_[0] = "bil_arf_image_istream_sptr"; //an initialized istream_sptr 27 output_types_[1] = "int"; 28 return pro.set_input_types(input_types_) && pro.set_output_types(output_types_); 29 } 30 31 32 //: Execute the process bil_create_arf_image_istream_process(bprb_func_process & pro)33bool bil_create_arf_image_istream_process(bprb_func_process& pro) 34 { 35 // Sanity check 36 if (pro.n_inputs()<1) { 37 std::cout << "bil_create_arf_image_istream_process: The input number should be 1" << std::endl; 38 return false; 39 } 40 //Retrieve filename from input 41 std::string raw_file = pro.get_input<std::string>(0); 42 43 //: Constructor - from a file glob string 44 bil_arf_image_istream_sptr stream = new bil_arf_image_istream(raw_file); 45 pro.set_output_val<bil_arf_image_istream_sptr>(0, stream); 46 pro.set_output_val<int> (1, stream->num_frames()); 47 return true; 48 } 49 //--------------------------------------------------------------- 50 // get next image from stream process 51 //--------------------------------------------------------------- 52 //: Constructor bil_arf_read_frame_process_cons(bprb_func_process & pro)53bool bil_arf_read_frame_process_cons(bprb_func_process& pro) 54 { 55 //process takes 1 input 56 std::vector<std::string> input_types_(1); 57 input_types_[0] = "bil_arf_image_istream_sptr"; //raw file 58 59 // process has 1 output: 60 std::vector<std::string> output_types_(2); 61 output_types_[0] = "vil_image_view_base_sptr"; //an initialized istream_sptr 62 output_types_[1] = "unsigned"; //time stamp 63 return pro.set_input_types(input_types_) && pro.set_output_types(output_types_); 64 } 65 66 //: Execute the process bil_arf_read_frame_process(bprb_func_process & pro)67bool bil_arf_read_frame_process(bprb_func_process& pro) 68 { 69 // Sanity check 70 if (pro.n_inputs()<1) { 71 std::cout << "bil_create_arf_image_istream_process: The input number should be 1" << std::endl; 72 return false; 73 } 74 //Retrieve filename from input 75 bil_arf_image_istream_sptr stream = pro.get_input<bil_arf_image_istream_sptr>(0); 76 vil_image_view_base_sptr img = stream->read_frame(); 77 unsigned time = stream->time_stamp(); 78 79 //out 80 pro.set_output_val<vil_image_view_base_sptr>(0, img); 81 pro.set_output_val<unsigned>(1, time); 82 return true; 83 } 84 85 86 //--------------------------------------------------------------- 87 // seek stream to a certain image 88 //--------------------------------------------------------------- 89 //: Constructor bil_arf_seek_frame_process_cons(bprb_func_process & pro)90bool bil_arf_seek_frame_process_cons(bprb_func_process& pro) 91 { 92 //process takes 1 input 93 std::vector<std::string> input_types_(2); 94 input_types_[0] = "bil_arf_image_istream_sptr"; //raw file 95 input_types_[1] = "unsigned"; //frame to seek to 96 97 // process has 1 output: 98 std::vector<std::string> output_types_(2); 99 output_types_[0] = "vil_image_view_base_sptr"; //an initialized istream_sptr 100 output_types_[1] = "unsigned"; //time stamp 101 return pro.set_input_types(input_types_) && pro.set_output_types(output_types_); 102 } 103 104 //: Execute the process bil_arf_seek_frame_process(bprb_func_process & pro)105bool bil_arf_seek_frame_process(bprb_func_process& pro) 106 { 107 // Sanity check 108 if (pro.n_inputs()<1) { 109 std::cout << "bil_create_arf_image_istream_process: The input number should be 1" << std::endl; 110 return false; 111 } 112 //Retrieve filename from input 113 bil_arf_image_istream_sptr stream = pro.get_input<bil_arf_image_istream_sptr>(0); 114 auto frame = pro.get_input<unsigned>(1); 115 116 //seek, retrieve image, and output 117 stream->seek_frame(frame); 118 vil_image_view_base_sptr img = stream->read_frame(); 119 unsigned time = stream->time_stamp(); 120 121 //out 122 pro.set_output_val<vil_image_view_base_sptr>(0, img); 123 pro.set_output_val<unsigned>(1, time); 124 return true; 125 } 126