Go to the documentation of this file.00001
00002 #include "strk_feature_capture_process.h"
00003 #include <vcl_iostream.h>
00004 #include <vcl_vector.h>
00005 #include <vgl/vgl_point_2d.h>
00006 #include <vtol/vtol_topology_object.h>
00007 #include <vtol/vtol_edge.h>
00008 #include <vtol/vtol_face_2d.h>
00009 #include <strk/strk_io.h>
00010 #include <strk/strk_tracking_face_2d.h>
00011
00012 strk_feature_capture_process::strk_feature_capture_process(strk_info_tracker_params & tp)
00013 : tracker_(tp)
00014 {
00015 failure_ = false;
00016 first_frame_ = true;
00017 face_index_ =0;
00018 }
00019
00020 strk_feature_capture_process::~strk_feature_capture_process()
00021 {
00022 }
00023
00024 bool strk_feature_capture_process::execute()
00025 {
00026 if (failure_)
00027 return false;
00028 if (this->get_N_input_images()!=1)
00029 {
00030 vcl_cout << "In strk_feature_capture_process::execute() -"
00031 << " not exactly one input image\n";
00032 failure_ = true;
00033 return false;
00034 }
00035 vil1_image img = vpro_video_process::get_input_image(0);
00036 input_images_.clear();
00037 static int n_faces = 0;
00038 if (first_frame_)
00039 {
00040 face_index_ = 0;
00041 tracker_.set_image_0(img);
00042 n_faces = tracked_faces_.size();
00043 if (!n_faces)
00044 {
00045 vcl_cout << "In strk_feature_capture_process::execute() -"
00046 << " no faces found in track file\n";
00047 failure_ = true;
00048 }
00049 vtol_face_2d_sptr f = tracked_faces_[face_index_];
00050 tracker_.set_initial_model(f);
00051 tracker_.init();
00052 first_frame_ = false;
00053 tracked_hist_.push_back(tracker_.capture_histograms(true));
00054 return true;
00055 }
00056 face_index_++;
00057 tracker_.set_image_i(img);
00058 vtol_face_2d_sptr f = tracked_faces_[face_index_];
00059 tracker_.set_capture_face(f);
00060 tracked_hist_.push_back(tracker_.capture_histograms());
00061 vcl_vector<vtol_edge_sptr> edges;
00062 f->edges(edges);
00063 output_topo_objs_.clear();
00064 for (vcl_vector<vtol_edge_sptr>::iterator eit = edges.begin();
00065 eit != edges.end(); eit++)
00066 {
00067 vtol_topology_object_sptr to = (*eit)->cast_to_edge();
00068 output_topo_objs_.push_back(to);
00069 }
00070 return true;
00071 }
00072
00073 bool strk_feature_capture_process::finish()
00074 {
00075 first_frame_ = true;
00076 face_index_ = 0;
00077 failure_ = false;
00078 vcl_ofstream strm(hist_file_.c_str());
00079 if (!strm)
00080 {
00081 vcl_cout << "In strk_feature_capture_process::set_input_file() -"
00082 << " could not open file " << hist_file_ << '\n';
00083 return false;
00084 }
00085 strk_tracking_face_2d_sptr tf = tracker_.capture_tf();
00086 if (!tf)
00087 return false;
00088 int n_pix = tf->face()->Npix();
00089 float dia = tf->face()->Diameter();
00090 float r = tf->face()->AspectRatio();
00091 vcl_vector<vcl_vector<float> > junk;
00092 if (!strk_io::write_histogram_data(start_frame_, n_pix, dia, r,
00093 tracker_.intensity_hist_bins_,
00094 tracker_.gradient_dir_hist_bins_,
00095 tracker_.color_hist_bins_,
00096 tracked_hist_,
00097 strm))
00098 return false;
00099 return true;
00100 }
00101
00102 bool strk_feature_capture_process::set_input_file(vcl_string const& file_name)
00103 {
00104 start_frame_ = 0;
00105 track_file_ = file_name;
00106 if (track_file_=="")
00107 return false;
00108 vcl_ifstream str(track_file_.c_str());
00109 if (!str)
00110 {
00111 vcl_cout << "In strk_feature_capture_process::set_input_file() -"
00112 << " could not open file " << track_file_ << '\n';
00113 return false;
00114 }
00115 vcl_vector<vgl_point_2d<double> > tracked_cogs;
00116 unsigned int n_frames = 0;
00117 if (!strk_io::read_track_data(str, start_frame_, n_frames,
00118 tracked_cogs, tracked_faces_))
00119 {
00120 str.close();
00121 return false;
00122 }
00123 end_frame_ = start_frame_+n_frames -1;
00124 str.close();
00125 return true;
00126 }
00127
00128 bool strk_feature_capture_process::set_output_file(vcl_string const& file_name)
00129 {
00130 hist_file_ = file_name;
00131 return true;
00132 }