contrib/brl/bseg/vpro/vpro_basis_generator_process.cxx
Go to the documentation of this file.
00001 #include "vpro_basis_generator_process.h"
00002 //:
00003 // \file
00004 #include <vcl_list.h>
00005 #include <vcl_iostream.h>
00006 #include <vil1/vil1_image.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_basis_generator_process::vpro_basis_generator_process(vcl_string const& video_file)
00013 {
00014   video_file_ = video_file;
00015 }
00016 
00017 vpro_basis_generator_process::~vpro_basis_generator_process()
00018 {
00019 }
00020 
00021 bool vpro_basis_generator_process::execute()
00022 {
00023   if (this->get_N_input_images()!=1)
00024   {
00025     vcl_cout << "In vpro_basis_generator_process::execute() -"
00026              << " not exactly one input image\n";
00027     return false;
00028   }
00029 
00030   vil1_image img = vpro_video_process::get_input_image(0);
00031   input_images_.clear();
00032   vil1_memory_image_of<float> flt = brip_vil1_float_ops::convert_to_float(img);
00033   frames_.push_back(flt);
00034   return true;
00035 }
00036 
00037 bool vpro_basis_generator_process::finish()
00038 {
00039   if (!frames_.size())
00040     return false;
00041   vcl_vector<vil1_memory_image_of<float> > basis;
00042   brip_vil1_float_ops::basis_images(frames_, basis);
00043   vcl_list<vil1_image> basis_frames;
00044   for (vcl_vector<vil1_memory_image_of<float> >::iterator iit = basis.begin();
00045        iit != basis.end(); iit++)
00046   {
00047     vil1_image img = brip_vil1_float_ops::convert_to_byte(*iit);
00048     basis_frames.push_back(img);
00049   }
00050   vidl_vil1_clip_sptr clip = new vidl_vil1_clip(basis_frames);
00051   vidl_vil1_movie_sptr mov= new vidl_vil1_movie();
00052   mov->add_clip(clip);
00053   if (!vidl_vil1_io::save(mov.ptr(), video_file_.c_str(), "tiff"))
00054   {
00055     vcl_cout << "In vpro_basis_generator_process::finish()"
00056              << " - failed to save video" << vcl_endl;
00057     return false;
00058   }
00059   frames_.clear();
00060   return true;
00061 }
00062