contrib/brl/bseg/vpro/vpro_capture_process.cxx
Go to the documentation of this file.
00001 #include "vpro_capture_process.h"
00002 //:
00003 // \file
00004 #include <vcl_iostream.h>
00005 #include <vcl_fstream.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 
00011 vul_timer vpro_capture_process::time_;
00012 
00013 bool vpro_capture_process::capture_started_=false;
00014 
00015 vpro_capture_process::vpro_capture_process(vcl_string const& video_file)
00016 {
00017   video_file_ = video_file;
00018 }
00019 
00020 vpro_capture_process::~vpro_capture_process()
00021 {
00022 }
00023 
00024 bool vpro_capture_process::execute()
00025 {
00026   if (this->get_N_input_images()!=1)
00027   {
00028     vcl_cout << "In vpro_capture_process::execute() -"
00029              << " not exactly one input image\n";
00030     return false;
00031   }
00032     //JLM
00033   //vil1_memory_image_of<unsigned char> img(vpro_video_process::get_input_image(0));
00034   vil1_image img = vpro_video_process::get_input_image(0);
00035   frames_.push_back(img);
00036 
00037   //reset the timer if this is the first image captured
00038   if (!capture_started_){
00039     capture_started_ = true;
00040     time_.mark();
00041   }
00042   time_stamps_.push_back(time_.real());
00043   return true;
00044 }
00045 
00046 bool vpro_capture_process::finish()
00047 {
00048   if (!frames_.size())
00049     return false;
00050   vidl_vil1_clip_sptr clip = new vidl_vil1_clip(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     vcl_cout << "In vpro_capture_process::finish()"
00055              << " - failed to save video" << vcl_endl;
00056     return false;
00057   }
00058   frames_.clear();
00059   capture_started_ = false;
00060   if ( !save_time_stamps() ) {
00061     vcl_cout << "In vpro_capture_process::finish()"
00062              << " - failed to save time stamps"<< vcl_endl;
00063     return false;
00064   }
00065   time_stamps_.clear();
00066   vcl_cout << "Finished Saving Captured Video File\n";
00067   return true;
00068 }
00069 
00070 // Write the time stamps to a text file
00071 bool vpro_capture_process::save_time_stamps()
00072 {
00073   vcl_string file_name = video_file_+"time_stamps.txt";
00074   vcl_ofstream time_file(file_name.c_str());
00075   vcl_cout << file_name.c_str() << vcl_endl;
00076   for (unsigned i=0; i<time_stamps_.size(); ++i) {
00077     time_file << i << '\t' << time_stamps_[i] << vcl_endl;
00078   }
00079   time_file.close();
00080   return true;
00081 }