libeblearntools
|
00001 /*************************************************************************** 00002 * Copyright (C) 2009 by Pierre Sermanet * 00003 * pierre.sermanet@gmail.com * 00004 * All rights reserved. 00005 * 00006 * Redistribution and use in source and binary forms, with or without 00007 * modification, are permitted provided that the following conditions are met: 00008 * * Redistributions of source code must retain the above copyright 00009 * notice, this list of conditions and the following disclaimer. 00010 * * Redistributions in binary form must reproduce the above copyright 00011 * notice, this list of conditions and the following disclaimer in the 00012 * documentation and/or other materials provided with the distribution. 00013 * * Redistribution under a license not approved by the Open Source 00014 * Initiative (http://www.opensource.org) must display the 00015 * following acknowledgement in all advertising material: 00016 * This product includes software developed at the Courant 00017 * Institute of Mathematical Sciences (http://cims.nyu.edu). 00018 * * The names of the authors may not be used to endorse or promote products 00019 * derived from this software without specific prior written permission. 00020 * 00021 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED 00022 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 00023 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00024 * DISCLAIMED. IN NO EVENT SHALL ThE AUTHORS BE LIABLE FOR ANY 00025 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 00026 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00027 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 00028 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00029 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00030 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00031 ***************************************************************************/ 00032 00033 #ifndef PASCAL_DATASET_H_ 00034 #define PASCAL_DATASET_H_ 00035 00036 #include "dataset.h" 00037 #include "xml_utils.h" 00038 #include "pascal_xml.h" 00039 00040 namespace ebl { 00041 00047 template <class Tdata> class pascal_dataset : public dataset<Tdata> { 00048 public: 00049 00051 // constructors 00052 00060 pascal_dataset(const char *name, const char *inroot = NULL, 00061 bool ignore_diff = true, bool ignore_trunc = false, 00062 bool ignore_occluded = false, 00063 const char *annotations = NULL, 00064 const char *ignore_path = NULL, 00065 bool ignore_bbox = false); 00066 00068 virtual ~pascal_dataset(); 00069 00071 // data 00072 00074 virtual bool extract(); 00076 virtual void extract_statistics(); 00079 virtual void set_min_aspect_ratio(float minar); 00082 virtual void set_max_aspect_ratio(float maxar); 00085 virtual void set_minborders(idxdim &d); 00088 virtual void set_max_jitter_match(float match); 00089 00090 protected: 00091 00092 #ifdef __BOOST__ // disable some derived methods if BOOST not available 00093 #ifdef __XML__ // disable some derived methods if XML not available 00094 00097 virtual bool included(const string &class_name, uint difficult, 00098 uint truncated, uint occluded); 00099 00101 // data 00102 00104 virtual intg count_samples(); 00107 virtual void count_sample(Node::NodeList &olist); 00108 00110 // internal methods 00111 00113 virtual bool process_xml(const string &xmlfile); 00115 virtual bool process_objects(const vector<object*> &objs, 00116 int height, int width, 00117 const string &image_fullname, 00118 const string &image_filename, 00119 const rect<int> *cropr = NULL); 00125 virtual void process_image(midx<Tdata> &img, const rect<int> &r, 00126 string &obj_class, uint difficult, 00127 const string &image_filename, 00128 pair<int,int> *center, 00129 const rect<int> *visr = NULL, 00130 const rect<int> *cropr = NULL); 00132 virtual void load_data(const string &fname); 00133 00134 #endif /* __XML__ */ 00135 #endif /* __BOOST__ */ 00136 00139 virtual void compute_random_jitter(); 00143 virtual void remove_jitter_matches(const std::vector<object*> &objs, 00144 uint iobj, float max_match); 00146 virtual void write_statistics(string &xml, ofstream &fp); 00147 00148 protected: 00149 // "difficult" samples ///////////////////////////////////////// 00150 std::vector<object*> objects; 00151 uint iobj; 00152 bool ignore_difficult; 00153 bool ignore_bbox; 00154 intg total_difficult; 00155 bool ignore_truncated; 00156 intg total_truncated; 00157 bool ignore_occluded; 00158 intg total_occluded; 00159 intg total_ignored; 00160 float min_aspect_ratio; 00161 float max_aspect_ratio; 00162 idxdim minborders; 00163 idxdim indims; 00164 uint input_height; 00165 uint input_width; 00166 // directories ///////////////////////////////////////////////// 00167 string annroot; 00168 string imgroot; 00169 string ignore_root; 00170 // base class members to be used /////////////////////////////// 00171 using dataset<Tdata>::load_img; 00172 using dataset<Tdata>::usepose; 00173 using dataset<Tdata>::useparts; 00174 using dataset<Tdata>::usepartsonly; 00175 using dataset<Tdata>::allocated; 00176 using dataset<Tdata>::total_samples; 00177 using dataset<Tdata>::inroot; 00178 using dataset<Tdata>::display_extraction; 00179 using dataset<Tdata>::display_result; 00180 using dataset<Tdata>::outdims; 00181 using dataset<Tdata>::full; 00182 using dataset<Tdata>::add_data; 00183 using dataset<Tdata>::print_stats; 00184 using dataset<Tdata>::data_cnt; 00185 using dataset<Tdata>::extension; 00186 using dataset<Tdata>::scale_mode; 00187 using dataset<Tdata>::exclude; 00188 using dataset<Tdata>::include; 00189 using dataset<Tdata>::force_label; 00190 using dataset<Tdata>::mindims; 00191 using dataset<Tdata>::xtimer; 00192 using dataset<Tdata>::processed_cnt; 00193 using dataset<Tdata>::minvisibility; 00194 using dataset<Tdata>::save_mode; 00195 using dataset<Tdata>::outdir; 00196 // jitter ////////////////////////////////////////////////////// 00197 using dataset<Tdata>::random_jitter; 00198 float max_jitter_match; 00199 }; 00200 00201 } // end namespace ebl 00202 00203 #include "pascal_dataset.hpp" 00204 00205 #endif /* PASCAL_DATASET_H_ */