tesseract
3.03
|
00001 /********************************************************************** 00002 * File: boxchar.h 00003 * Description: Simple class to associate a Tesseract classification unit with 00004 * its bounding box so that the boxes can be rotated as the image 00005 * is rotated for degradation. Also includes routines to output 00006 * the character-tagged boxes to a boxfile. 00007 * Author: Ray Smith 00008 * Created: Mon Nov 18 2013 00009 * 00010 * (C) Copyright 2013, Google Inc. 00011 * Licensed under the Apache License, Version 2.0 (the "License"); 00012 * you may not use this file except in compliance with the License. 00013 * You may obtain a copy of the License at 00014 * http://www.apache.org/licenses/LICENSE-2.0 00015 * Unless required by applicable law or agreed to in writing, software 00016 * distributed under the License is distributed on an "AS IS" BASIS, 00017 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00018 * See the License for the specific language governing permissions and 00019 * limitations under the License. 00020 * 00021 **********************************************************************/ 00022 00023 #ifndef TESSERACT_TRAINING_BOXCHAR_H_ 00024 #define TESSERACT_TRAINING_BOXCHAR_H_ 00025 00026 #include <string> 00027 #include <vector> 00028 00029 #include "allheaders.h" // from Leptonica 00030 00031 #ifdef USE_STD_NAMESPACE 00032 using std::string; 00033 using std::vector; 00034 #endif 00035 00036 struct Box; 00037 00038 namespace tesseract { 00039 00040 class BoxChar { 00041 public: 00042 BoxChar(const char* utf8_str, int len); 00043 00044 ~BoxChar(); 00045 00046 // Accessors. 00047 const string& ch() const { return ch_; } 00048 const Box* box() const { return box_; } 00049 const int& page() const { return page_; } 00050 00051 00052 // Set the box_ member. 00053 void AddBox(int x, int y, int width, int height); 00054 00055 void set_page(int page) { page_ = page; } 00056 00057 string* mutable_ch() { return &ch_; } 00058 Box* mutable_box() { return box_; } 00059 00060 static void TranslateBoxes(int xshift, int yshift, 00061 vector<BoxChar*>* boxes); 00062 00063 // Rotate the vector of boxes between start and end by the given rotation. 00064 // The rotation is in radians clockwise about the given center. 00065 static void RotateBoxes(float rotation, 00066 int xcenter, 00067 int ycenter, 00068 int start_box, 00069 int end_box, 00070 vector<BoxChar*>* boxes); 00071 00072 // Create a tesseract box file from the vector of boxes. The image height 00073 // is needed to convert to tesseract coordinates. 00074 static void WriteTesseractBoxFile(const string& name, int height, 00075 const vector<BoxChar*>& boxes); 00076 00077 private: 00078 string ch_; 00079 Box* box_; 00080 int page_; 00081 }; 00082 } // namespace tesseract 00083 00084 #endif // TESSERACT_TRAINING_BOXCHAR_H_