00001 # ifndef PixelLine15_h 00002 # define PixelLine15_h PixelLine15_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 "Root.h" // parent 00021 # include "Coord.h" 00022 00023 namespace Conjecture { 00024 00025 // ################################################################## 00032 // ################################################################## 00033 00034 // IMPLEMENTATION NOTES: 00035 // - this class is designed for highly efficient space utiliation, 00036 // while also providing support for highly efficient feature 00037 // analysis. 00038 // - some "auxillary" methods are quite slow (i.e. 'set' and 00039 // 'clear' - this class is meant to be used primarily on 00040 // frozen images, so setting and clearing bits is not a 00041 // priority for efficient implementation. 00042 // - does NOT store the size of the pixel line (assumed to be 00043 // be maintained elsewhere). This implies that the number of 00044 // white pixels cannot be reported without obtaining the size 00045 // (#black is stored, and #white = total - #black). 00046 // - not using setters internally in some situations because 00047 // bit-specifiers cause temporaries to be used in returns 00048 00049 class PixelLine15 : public Root { 00050 public: 00051 // Constructors/Destructors 00052 PixelLine15(unsigned int pixels); 00053 00054 // ************** 00055 // Accessors 00056 inline unsigned int holes() const { return this->_holes; } 00057 inline unsigned int pixels() const { return this->_pixels; } 00058 inline unsigned int black() const { return this->_black; } 00059 00060 // ************** 00061 // Input/Output 00062 00063 // ************** 00064 // Interface 00065 00070 inline bool get(unsigned i) const { 00071 return (this->pixels() & (1<<i)) ? true : false; 00072 } 00073 00078 void set(unsigned i); 00079 00084 void clear(unsigned i); 00085 00087 std::string str(char on = '#', char off = '.', unsigned char size = 15) const; 00088 00089 static void test(int argc = 0, const char* argv[] = NULL); 00090 00091 protected: 00092 // ************** 00093 // Accessors 00094 inline void holesIs(unsigned int holes) { this->_holes = holes; } 00095 inline void pixelsIs(unsigned int pixels) { this->_pixels = pixels; } 00096 inline void blackIs(unsigned int black) { this->_black = black; } 00097 00098 // ************** 00099 // Methods 00100 00101 private: 00102 // ************** 00103 // Accessors 00104 00105 // ************** 00106 // Methods 00107 void updateMeta(); 00108 00109 // ************** 00110 // State 00111 00118 unsigned int _pixels:15; 00119 00124 unsigned int _clean:1; 00125 00127 unsigned int _black:4; 00128 00139 unsigned int _holes:3; 00140 00141 // FUTURE FIX: There are still 8 bits remaining that can be 00142 // filled with other information useful to feature analysis. 00143 // Possibilities include: 00144 // - 2 bits to indicate whether the left-most black pixel 00145 // is at left border (0), 1 in from left border (1), 00146 // 2 in from left border (2), or 3+ in from left border 00147 // (3). An analogous 2 bits for right-most black pixel 00148 // as well. Leaves 4 bits for other things. 00149 // - index of left-most black pixel (4 bits) and index of 00150 // right-most black pixel (4 bits). 00151 00152 }; 00153 } 00154 00155 # endif // PixelLine15_h 00156