contrib/brl/bseg/vpro/vpro_half_res_process.cxx
Go to the documentation of this file.
00001 #include "vpro_half_res_process.h"
00002 //:
00003 // \file
00004 #include <vcl_iostream.h>
00005 #include <vil1/vil1_image.h>
00006 #include <vil1/vil1_memory_image_of.h>
00007 #include <vidl_vil1/vidl_vil1_movie.h>
00008 #include <vidl_vil1/vidl_vil1_clip.h>
00009 #include <vidl_vil1/vidl_vil1_io.h>
00010 #include <brip/brip_vil1_float_ops.h>
00011 
00012 vpro_half_res_process::vpro_half_res_process(vcl_string const& video_file)
00013 {
00014   video_file_ = video_file;
00015 }
00016 
00017 vpro_half_res_process::~vpro_half_res_process()
00018 {
00019 }
00020 
00021 bool vpro_half_res_process::execute()
00022 {
00023   if (this->get_N_input_images()!=1)
00024   {
00025     vcl_cout << "In vpro_half_res_process::execute() -"
00026              << " not exactly one input image\n";
00027   return false;
00028   }
00029   vil1_image img = vpro_video_process::get_input_image(0);
00030   this->clear_input();
00031   if (img.components()==1)
00032   {
00033     vil1_memory_image_of<float> fimg =
00034       brip_vil1_float_ops::convert_to_float(img);
00035     vil1_memory_image_of<float> half =
00036       brip_vil1_float_ops::half_resolution(fimg);
00037     vil1_memory_image_of<unsigned char> chalf =
00038       brip_vil1_float_ops::convert_to_byte(half);
00039     out_frames_.push_back(chalf);
00040     return true;
00041   }
00042   if (img.components()==3)
00043   {
00044     vil1_memory_image_of<vil1_rgb<unsigned char> > cimg(img);
00045     vil1_memory_image_of<vil1_rgb<unsigned char> > cimg_half =
00046     brip_vil1_float_ops::half_resolution(cimg);
00047     out_frames_.push_back(cimg_half);
00048     return true;
00049   }
00050   return false;
00051 }
00052 
00053 bool vpro_half_res_process::finish()
00054 {
00055   if (!out_frames_.size())
00056     return false;
00057   vidl_vil1_clip_sptr clip = new vidl_vil1_clip(out_frames_);
00058   vidl_vil1_movie_sptr mov= new vidl_vil1_movie();
00059   mov->add_clip(clip);
00060   if (!vidl_vil1_io::save(mov.ptr(), video_file_.c_str(), "AVI")){
00061     vcl_cout << "In vpro_half_res_process::finish()"
00062              << " - failed to save video" << vcl_endl;
00063     return false;
00064   }
00065   out_frames_.clear();
00066   return true;
00067  }
00068