#include <boxchar.h>
|
static void | TranslateBoxes (int xshift, int yshift, std::vector< BoxChar *> *boxes) |
|
static void | PrepareToWrite (std::vector< BoxChar *> *boxes) |
|
static void | InsertNewlines (bool rtl_rules, bool vertical_rules, std::vector< BoxChar *> *boxes) |
|
static void | InsertSpaces (bool rtl_rules, bool vertical_rules, std::vector< BoxChar *> *boxes) |
|
static void | ReorderRTLText (std::vector< BoxChar *> *boxes) |
|
static bool | ContainsMostlyRTL (const std::vector< BoxChar *> &boxes) |
|
static bool | MostlyVertical (const std::vector< BoxChar *> &boxes) |
|
static int | TotalByteLength (const std::vector< BoxChar *> &boxes) |
|
static void | RotateBoxes (float rotation, int xcenter, int ycenter, int start_box, int end_box, std::vector< BoxChar *> *boxes) |
|
static void | WriteTesseractBoxFile (const std::string &name, int height, const std::vector< BoxChar *> &boxes) |
|
static std::string | GetTesseractBoxStr (int height, const std::vector< BoxChar *> &boxes) |
|
Definition at line 36 of file boxchar.h.
◆ BoxChar()
tesseract::BoxChar::BoxChar |
( |
const char * |
utf8_str, |
|
|
int |
len |
|
) |
| |
Definition at line 41 of file boxchar.cpp.
42 : ch_(utf8_str, len), box_(
nullptr), page_(0), rtl_index_(-1) {}
◆ ~BoxChar()
tesseract::BoxChar::~BoxChar |
( |
| ) |
|
Definition at line 44 of file boxchar.cpp.
44 { boxDestroy(&box_); }
◆ AddBox()
void tesseract::BoxChar::AddBox |
( |
int |
x, |
|
|
int |
y, |
|
|
int |
width, |
|
|
int |
height |
|
) |
| |
Definition at line 46 of file boxchar.cpp.
47 box_ = boxCreate(x, y, width, height);
◆ box()
const Box* tesseract::BoxChar::box |
( |
| ) |
const |
|
inline |
◆ ch()
const std::string& tesseract::BoxChar::ch |
( |
| ) |
const |
|
inline |
◆ ContainsMostlyRTL()
bool tesseract::BoxChar::ContainsMostlyRTL |
( |
const std::vector< BoxChar *> & |
boxes | ) |
|
|
static |
Definition at line 260 of file boxchar.cpp.
261 int num_rtl = 0, num_ltr = 0;
262 for (
int i = 0; i < boxes.size(); ++i) {
263 boxes[i]->GetDirection(&num_rtl, &num_ltr);
265 return num_rtl > num_ltr;
◆ GetDirection()
void tesseract::BoxChar::GetDirection |
( |
int * |
num_rtl, |
|
|
int * |
num_ltr |
|
) |
| const |
Definition at line 52 of file boxchar.cpp.
55 if (uni_vector.empty()) {
56 tprintf(
"Illegal utf8 in boxchar string:%s = ", ch_.c_str());
57 for (
int c = 0; c < ch_.size(); ++c) {
64 UCharDirection dir = u_charDirection(
ch);
65 if (dir == U_RIGHT_TO_LEFT || dir == U_RIGHT_TO_LEFT_ARABIC ||
66 dir == U_ARABIC_NUMBER || dir == U_RIGHT_TO_LEFT_ISOLATE) {
68 }
else if (dir != U_DIR_NON_SPACING_MARK && dir != U_BOUNDARY_NEUTRAL) {
const std::string & ch() const
DLLSYM void tprintf(const char *format,...)
static std::vector< char32 > UTF8ToUTF32(const char *utf8_str)
◆ GetTesseractBoxStr()
std::string tesseract::BoxChar::GetTesseractBoxStr |
( |
int |
height, |
|
|
const std::vector< BoxChar *> & |
boxes |
|
) |
| |
|
static |
Definition at line 327 of file boxchar.cpp.
331 for (
size_t i = 0; i < boxes.size(); ++i) {
332 const Box*
box = boxes[i]->box_;
333 if (
box ==
nullptr) {
334 tprintf(
"Error: Call PrepareToWrite before WriteTesseractBoxFile!!\n");
339 boxes[i]->ch_.c_str(),
box->x, height -
box->y -
box->h,
340 box->x +
box->w, height -
box->y, boxes[i]->page_);
341 output.append(buffer, nbytes);
DLLSYM void tprintf(const char *format,...)
◆ InsertNewlines()
void tesseract::BoxChar::InsertNewlines |
( |
bool |
rtl_rules, |
|
|
bool |
vertical_rules, |
|
|
std::vector< BoxChar *> * |
boxes |
|
) |
| |
|
static |
Definition at line 112 of file boxchar.cpp.
116 for (
size_t i = 0; i < boxes->size(); ++i) {
117 Box*
box = (*boxes)[i]->box_;
118 if (
box ==
nullptr) {
119 if (prev_i < 0 || prev_i + 1 < i || i + 1 == boxes->size()) {
123 boxes->erase(boxes->begin() + i);
125 }
while (i-- == boxes->size() && (*boxes)[i]->box_ ==
nullptr);
130 Box* prev_box = (*boxes)[prev_i]->box_;
131 int shift =
box->x - prev_box->x;
132 if (vertical_rules) {
133 shift =
box->y - prev_box->y;
134 }
else if (rtl_rules) {
137 if (-shift > max_shift) {
143 int x = prev_box->x + prev_box->w;
145 if (vertical_rules) {
147 y = prev_box->y + prev_box->h;
148 }
else if (rtl_rules) {
149 x = prev_box->x - width;
151 tprintf(
"prev x = %d, width=%d\n", prev_box->x, width);
155 if (prev_i + 1 == i) {
158 new_box->AddBox(x, y, width, height);
159 new_box->page_ = (*boxes)[i]->page_;
160 boxes->insert(boxes->begin() + i, new_box);
163 (*boxes)[i - 1]->AddBox(x, y, width, height);
164 (*boxes)[i - 1]->ch_ =
"\t";
167 }
else if (shift > max_shift) {
DLLSYM void tprintf(const char *format,...)
BoxChar(const char *utf8_str, int len)
◆ InsertSpaces()
void tesseract::BoxChar::InsertSpaces |
( |
bool |
rtl_rules, |
|
|
bool |
vertical_rules, |
|
|
std::vector< BoxChar *> * |
boxes |
|
) |
| |
|
static |
Definition at line 177 of file boxchar.cpp.
181 for (
size_t i = 1; i + 1 < boxes->size(); ++i) {
182 Box*
box = (*boxes)[i]->box_;
183 if (
box ==
nullptr) {
184 Box* prev = (*boxes)[i - 1]->box_;
185 Box* next = (*boxes)[i + 1]->box_;
187 int top = std::min(prev->y, next->y);
188 int bottom = std::max(prev->y + prev->h, next->y + next->h);
189 int left = prev->x + prev->w;
191 if (vertical_rules) {
192 top = prev->y + prev->h;
194 left = std::min(prev->x, next->x);
195 right = std::max(prev->x + prev->w, next->x + next->w);
196 }
else if (rtl_rules) {
201 left = next->x + next->w;
203 j >= 0 && (*boxes)[j]->ch_ !=
" " && (*boxes)[j]->ch_ !=
"\t";
205 prev = (*boxes)[j]->box_;
207 if (prev->x < right) {
213 for (
size_t j = i + 2;
214 j < boxes->size() && (*boxes)[j]->box_ !=
nullptr &&
215 (*boxes)[j]->ch_ !=
"\t";
217 next = (*boxes)[j]->box_;
218 if (next->x + next->w > left) {
219 left = next->x + next->w;
225 if (right <= left) right = left + 1;
226 if (bottom <= top) bottom = top + 1;
227 (*boxes)[i]->AddBox(left, top, right - left, bottom - top);
228 (*boxes)[i]->ch_ =
" ";
◆ MostlyVertical()
bool tesseract::BoxChar::MostlyVertical |
( |
const std::vector< BoxChar *> & |
boxes | ) |
|
|
static |
Definition at line 270 of file boxchar.cpp.
271 int64_t total_dx = 0, total_dy = 0;
272 for (
size_t i = 1; i < boxes.size(); ++i) {
273 if (boxes[i - 1]->box_ !=
nullptr && boxes[i]->box_ !=
nullptr &&
274 boxes[i - 1]->page_ == boxes[i]->page_) {
275 int dx = boxes[i]->box_->x - boxes[i - 1]->box_->x;
276 int dy = boxes[i]->box_->y - boxes[i - 1]->box_->y;
284 return total_dy > total_dx;
const int kMinNewlineRatio
◆ mutable_box()
Box* tesseract::BoxChar::mutable_box |
( |
| ) |
|
|
inline |
◆ mutable_ch()
std::string* tesseract::BoxChar::mutable_ch |
( |
| ) |
|
|
inline |
◆ operator<()
bool tesseract::BoxChar::operator< |
( |
const BoxChar & |
other | ) |
const |
|
inline |
Definition at line 59 of file boxchar.h.
60 if (box_ ==
nullptr)
return true;
61 if (other.box_ ==
nullptr)
return false;
62 return box_->x < other.box_->x;
◆ page()
const int& tesseract::BoxChar::page |
( |
| ) |
const |
|
inline |
◆ PrepareToWrite()
void tesseract::BoxChar::PrepareToWrite |
( |
std::vector< BoxChar *> * |
boxes | ) |
|
|
static |
Definition at line 97 of file boxchar.cpp.
102 for (
unsigned int i = 0; i < boxes->size(); ++i) {
103 if ((*boxes)[i]->box_ ==
nullptr)
tprintf(
"Null box at index %u\n", i);
static bool MostlyVertical(const std::vector< BoxChar *> &boxes)
static void ReorderRTLText(std::vector< BoxChar *> *boxes)
static void InsertNewlines(bool rtl_rules, bool vertical_rules, std::vector< BoxChar *> *boxes)
DLLSYM void tprintf(const char *format,...)
static void InsertSpaces(bool rtl_rules, bool vertical_rules, std::vector< BoxChar *> *boxes)
static bool ContainsMostlyRTL(const std::vector< BoxChar *> &boxes)
◆ ReorderRTLText()
void tesseract::BoxChar::ReorderRTLText |
( |
std::vector< BoxChar *> * |
boxes | ) |
|
|
static |
Definition at line 235 of file boxchar.cpp.
240 int num_boxes = boxes->size();
241 for (
int i = 0; i < num_boxes; ++i) {
242 int num_rtl = 0, num_ltr = 0;
243 (*boxes)[i]->GetDirection(&num_rtl, &num_ltr);
244 if (num_rtl > num_ltr) {
245 (*boxes)[i]->set_rtl_index(i);
246 (*boxes)[i]->ReverseUnicodesInBox();
249 BoxCharPtrSort sorter;
251 for (
size_t start = 0; start < boxes->size(); start = end + 1) {
253 while (end < boxes->size() && (*boxes)[end]->ch_ !=
"\t") ++end;
254 std::sort(boxes->begin() + start, boxes->begin() + end, sorter);
◆ ReverseUnicodesInBox()
void tesseract::BoxChar::ReverseUnicodesInBox |
( |
| ) |
|
Definition at line 76 of file boxchar.cpp.
static std::string UTF32ToUTF8(const std::vector< char32 > &str32)
static std::vector< char32 > UTF8ToUTF32(const char *utf8_str)
◆ RotateBoxes()
void tesseract::BoxChar::RotateBoxes |
( |
float |
rotation, |
|
|
int |
xcenter, |
|
|
int |
ycenter, |
|
|
int |
start_box, |
|
|
int |
end_box, |
|
|
std::vector< BoxChar *> * |
boxes |
|
) |
| |
|
static |
Definition at line 299 of file boxchar.cpp.
302 Boxa* orig = boxaCreate(0);
303 for (
int i = start_box; i < end_box; ++i) {
304 BOX*
box = (*boxes)[i]->box_;
305 if (
box) boxaAddBox(orig,
box, L_CLONE);
307 Boxa* rotated = boxaRotate(orig, xcenter, ycenter, rotation);
309 for (
int i = start_box, box_ind = 0; i < end_box; ++i) {
310 if ((*boxes)[i]->box_) {
311 boxDestroy(&((*boxes)[i]->box_));
312 (*boxes)[i]->box_ = boxaGetBox(rotated, box_ind++, L_CLONE);
315 boxaDestroy(&rotated);
◆ rtl_index()
const int& tesseract::BoxChar::rtl_index |
( |
| ) |
const |
|
inline |
Definition at line 47 of file boxchar.h.
47 {
return rtl_index_; }
◆ set_page()
void tesseract::BoxChar::set_page |
( |
int |
page | ) |
|
|
inline |
◆ set_rtl_index()
void tesseract::BoxChar::set_rtl_index |
( |
int |
index | ) |
|
|
inline |
Definition at line 46 of file boxchar.h.
46 { rtl_index_ = index; }
◆ TotalByteLength()
int tesseract::BoxChar::TotalByteLength |
( |
const std::vector< BoxChar *> & |
boxes | ) |
|
|
static |
Definition at line 289 of file boxchar.cpp.
290 int total_length = 0;
291 for (
size_t i = 0; i < boxes.size(); ++i)
292 total_length += boxes[i]->ch_.size();
◆ TranslateBoxes()
void tesseract::BoxChar::TranslateBoxes |
( |
int |
xshift, |
|
|
int |
yshift, |
|
|
std::vector< BoxChar *> * |
boxes |
|
) |
| |
|
static |
Definition at line 83 of file boxchar.cpp.
85 for (
size_t i = 0; i < boxes->size(); ++i) {
86 BOX*
box = (*boxes)[i]->box_;
◆ WriteTesseractBoxFile()
void tesseract::BoxChar::WriteTesseractBoxFile |
( |
const std::string & |
name, |
|
|
int |
height, |
|
|
const std::vector< BoxChar *> & |
boxes |
|
) |
| |
|
static |
Definition at line 320 of file boxchar.cpp.
static std::string GetTesseractBoxStr(int height, const std::vector< BoxChar *> &boxes)
static void WriteStringToFileOrDie(const std::string &str, const std::string &filename)
The documentation for this class was generated from the following files:
- /usr/src/tesseract-ocr.master/src/training/boxchar.h
- /usr/src/tesseract-ocr.master/src/training/boxchar.cpp