00001 #ifndef mfpf_pose_predictor_builder_h_ 00002 #define mfpf_pose_predictor_builder_h_ 00003 //: 00004 // \file 00005 // \brief Trains regressor in an mfpf_pose_predictor 00006 // \author Tim Cootes 00007 00008 #include <mfpf/mfpf_pose_predictor.h> 00009 #include <vnl/vnl_random.h> 00010 #include <vcl_iosfwd.h> 00011 00012 //: Trains regressor in an mfpf_pose_predictor. 00013 // Object set up with a pose predictor which has been 00014 // partially initialised so as to allow calculation of the 00015 // image samples. 00016 // Given a set of training images, this samples at random 00017 // displacements and trains a linear regressor to predict 00018 // the given displacement. 00019 // The internal pose predictor is just used to do the image 00020 // sampling (to reduce code duplication). 00021 class mfpf_pose_predictor_builder 00022 { 00023 private: 00024 //: Pose predictor object used to do image sampling 00025 mfpf_pose_predictor sampler_; 00026 00027 //: Random number generator for offsets 00028 vnl_random rand_; 00029 00030 //: Number of random samples to use per example 00031 unsigned n_per_eg_; 00032 00033 //: Samples (one per row) 00034 vnl_matrix<double> samples_; 00035 00036 //: Pose vectors for each sample (one per row) 00037 vnl_matrix<double> poses_; 00038 00039 //: Current index into samples_/poses_ 00040 unsigned ci_; 00041 00042 //: Define default values 00043 void set_defaults(); 00044 00045 public: 00046 00047 // Dflt ctor 00048 mfpf_pose_predictor_builder(); 00049 00050 // Destructor 00051 virtual ~mfpf_pose_predictor_builder(); 00052 00053 //: Define sampling region and method 00054 // Supplied predictor is partially initialised 00055 void set_sampling(const mfpf_pose_predictor&); 00056 00057 //: Define number of samples per training image 00058 void set_n_per_eg(unsigned n); 00059 00060 //: Initialise building 00061 // Must be called before any calls to add_example(...) 00062 virtual void clear(unsigned n_egs); 00063 00064 //: Add one example to the model 00065 virtual void add_example(const vimt_image_2d_of<float>& image, 00066 const mfpf_pose& pose); 00067 00068 //: Build object from the data supplied in add_example() 00069 virtual void build(mfpf_pose_predictor&); 00070 00071 //: Version number for I/O 00072 short version_no() const; 00073 00074 //: Name of the class 00075 virtual vcl_string is_a() const; 00076 00077 //: Create a copy on the heap and return base class pointer 00078 virtual mfpf_pose_predictor_builder* clone() const; 00079 00080 //: Print class to os 00081 virtual void print_summary(vcl_ostream& os) const; 00082 00083 //: Prints ASCII representation of shape to os 00084 void print_shape(vcl_ostream& os) const; 00085 00086 //: Save class to binary file stream 00087 virtual void b_write(vsl_b_ostream& bfs) const; 00088 00089 //: Load class from binary file stream 00090 virtual void b_read(vsl_b_istream& bfs); 00091 00092 //: Test equality 00093 bool operator==(const mfpf_pose_predictor_builder& nc) const; 00094 }; 00095 00096 //: Binary file stream output operator for class reference 00097 void vsl_b_write(vsl_b_ostream& bfs, 00098 const mfpf_pose_predictor_builder& b); 00099 00100 //: Binary file stream input operator for class reference 00101 void vsl_b_read(vsl_b_istream& bfs, 00102 mfpf_pose_predictor_builder& b); 00103 00104 //: Stream output operator for class reference 00105 vcl_ostream& operator<<(vcl_ostream& os, 00106 const mfpf_pose_predictor_builder& b); 00107 00108 #endif