OptIm.h

00001 # ifndef OptIm_h
00002 # define OptIm_h OptIm_h
00003 
00004 // ####################################################################
00005 // # Conjecture: An Extensible Optical Character Recognition Framework  #
00006 // #                                                                  #
00007 // # Copyright: Lesser GNU Public License (LGPL)                      #
00008 // #                                                                  #
00009 // # Overview:                                                        #
00010 // #  - Conjecture is a collection of C++ classes, and an OCR engine    #
00011 // #  - Conjecture is designed to allow customization at all levels     #
00012 // #    and to encourage individuals to contribute incremental        #
00013 // #    improvements in algorithms.                                   #
00014 // #  - Overall design discussions can be found in                    #
00015 // #      $SNROOT/docs/doxygen/html/index.html                        #
00016 // #  - Conjecture is designed to interact with and build on other      #
00017 // #    open-source OCR programs.                                     #
00018 // ####################################################################
00019 
00020 # include <vector>
00021 # include "Root.h"  // parent
00022 # include "PixelLine.h" // has-a
00023 
00024 # include "GlyphFeatures.h"  // Variant
00025 
00026 
00027 namespace Conjecture {
00028     class Image;
00029     class ImageArgs;
00030     
00031     // ##################################################################
00113     // ##################################################################
00114     class OptIm : public Root {
00115         friend class PixFilt;
00116 
00117       public:
00118         // Types
00119         typedef std::vector<PixelLine> PixelMatrix;
00120 
00121         // Constructors/Destructors
00122         OptIm(const std::vector<unsigned int>& rows, u1 width = PixelLine::MaxPixels);
00123         OptIm(const Image* image, const ImageArgs& config);
00124         
00125         //static u1 BitImage(const Image* image, const ImageArgs& args, std::vector<u4>& rows);
00126 
00127 
00128         // **************
00129         // Accessors
00130         inline const u1 & width() const { return this->_width; }
00131         inline const PixelMatrix & cols() const { return this->_cols; }
00132         inline const PixelMatrix & rows() const { return this->_rows; }
00133         
00134         // **************
00135         // Input/Output
00136         
00137         // **************
00138         // Interface
00139         void updateMeta();
00140 
00141         // FUTURE FIX: These methods currently return 0 if the
00142         // instance isn't updated. Should we just be updateding the image
00143         // automatically? Or should we throw asserts that are removed
00144         // in production code?
00145 
00147         int rblack(u1 i) const { return (this->updated() ? this->rows()[i].black() : 0); }
00149         int rholes(u1 i) const { return (this->updated() ? this->rows()[i].holes() : 0); }
00151         int cblack(u1 i) const { return (this->updated() ? this->cols()[i].black() : 0); }
00153         int choles(u1 i) const { return (this->updated() ? this->cols()[i].holes() : 0); }
00154 
00155         u1 height() const { return this->rows().size(); } 
00156 
00159         inline bool get(u2 x, u2 y) const { int w = this->width(); return this->rows()[y].get(w-1-x); }
00160 
00164         inline std::string str(char on = '#', char off = '.') const { return this->str("",0,on,off); }
00165 
00170         std::string str(const std::string& title, int valign = 0, char on = '#', char off = '.') const;
00171 
00185         bool crop(int level = 0);
00186         bool crop(int topthick, int bottomthick, int leftthick, int rightthick);
00187         bool crop(int topthick, int bottomthick, int leftthick, int rightthick, int& topref, int& bottomref, int& leftref, int& rightref);
00188 
00196         void identifyFeatures(GlyphFeatures& features);
00197         
00201         inline const PixelLine& row(int i) const {
00202             if ( i < 0 ) { i += this->height(); }
00203             return this->rows()[i];
00204         }
00205 
00211         bool removeBottomSerifs();
00212 
00218         bool removeTopSerifs();
00219 
00220         static void test(int argc = 0, const char* argv[] = NULL);
00221 
00222         inline void print(ostream& os = cout) const { os << this->str() << endl; }
00223         
00224       protected:
00225         // **************
00226         // Accessors
00227         inline bool  updated() const                                 { return this->_updated; }
00228         inline void  updatedIs(const bool & updated)                   { this->_updated = updated; }
00229         inline void  widthIs(const u1 & width)                     { this->_width = width; }
00230         inline void  colsIs(const PixelMatrix & cols) { this->_cols  = cols;  }
00231         inline void  rowsIs(const PixelMatrix & rows) { this->_rows  = rows;  }
00232         
00233         // **************
00234         // Methods 
00235         std::string rawstr(const PixelMatrix& vec, char on = '1', char off = '0', unsigned char size = PixelLine::MaxPixels) const;
00236 
00240         inline PixelLine& row(int i) {
00241             if ( i < 0 ) { i += this->height(); }
00242             return this->rowsRef()[i];
00243         }
00244 
00245         GlyphFeatures::Variant analyzeLines(u1 min, u2 max, const PixelMatrix& matrix, u1 dom, u1 rec, u1 halfn);
00246         
00247       private: 
00248         // **************
00249         // Accessors
00250         inline bool& updatedRef()                   { return this->_updated; }
00251         inline u1& widthRef()                       { return this->_width; }
00252         inline PixelMatrix& colsRef()  { return this->_cols;  }
00253         inline PixelMatrix& rowsRef()  { return this->_rows;  }
00254         
00255         // **************
00256         // Methods 
00257         
00258         // **************
00259         // State
00260 
00263         bool                     _updated;
00264 
00275         u1                       _width;
00276 
00278         PixelMatrix _rows;
00279 
00281         PixelMatrix _cols;
00282     };
00283 }
00284 
00285 # endif // OptIm_h
00286 

Generated on Wed Jun 14 15:08:02 2006 for Conjecture by  doxygen 1.4.6