00001 #include "vpro_roi_process.h" 00002 //: 00003 // \file 00004 #include <vcl_iostream.h> 00005 #include <vil/vil_new.h> 00006 #include <vil/vil_image_resource.h> 00007 #include <vidl1/vidl1_movie.h> 00008 #include <vidl1/vidl1_clip.h> 00009 #include <vidl1/vidl1_io.h> 00010 #include <vsol/vsol_box_2d.h> 00011 #include <brip/brip_vil_float_ops.h> 00012 #include <brip/brip_roi.h> 00013 00014 bool vpro_roi_process::execute() 00015 { 00016 if (this->get_N_input_images()!=1) 00017 { 00018 vcl_cout << "In vpro_roi_process::execute() -" 00019 << " not exactly one input image\n"; 00020 return false; 00021 } 00022 vil_image_resource_sptr img = vpro_vil_video_process::get_input_image(0); 00023 this->clear_input(); 00024 vil_image_view<float> fimage = brip_vil_float_ops::convert_to_float(*img); 00025 brip_roi_sptr roi = new brip_roi(img->ni(), img->nj()); 00026 roi->add_region(x0_, y0_, xsize_, ysize_); 00027 vsol_box_2d_sptr box = roi->region(0); 00028 vil_image_view<float> out; 00029 brip_vil_float_ops::chip(fimage, box, out); 00030 vil_image_view<unsigned char> outb; 00031 outb = brip_vil_float_ops::convert_to_byte(out); 00032 vil_image_resource_sptr outr = vil_new_image_resource_of_view(outb); 00033 out_frames_.push_back(outr); 00034 return true; 00035 } 00036 00037 bool vpro_roi_process::finish() 00038 { 00039 if (!out_frames_.size()) 00040 return false; 00041 vidl1_clip_sptr clip = new vidl1_clip(out_frames_); 00042 vidl1_movie_sptr mov= new vidl1_movie(); 00043 mov->add_clip(clip); 00044 if (!vidl1_io::save(mov.ptr(), video_file_.c_str(), type_)) { 00045 vcl_cerr << "In vpro_roi_process::finish() - failed to save video\n"; 00046 return false; 00047 } 00048 out_frames_.clear(); 00049 return true; 00050 }
1.7.5.1