// Reads all boxes from the given filename. // Reads a specific target_page number if >= 0, or all pages otherwise. // Skips blanks if skip_blanks is true. // The UTF-8 label of the box is put in texts, and the full box definition as // a string is put in box_texts, with the corresponding page number in pages. // Each of the output vectors is optional (may be NULL). // Returns false if no boxes are found. bool ReadAllBoxes(int target_page, bool skip_blanks, const STRING& filename, GenericVector<TBOX>* boxes, GenericVector<STRING>* texts, GenericVector<STRING>* box_texts, GenericVector<int>* pages) { GenericVector<char> box_data; if (!tesseract::LoadDataFromFile(BoxFileName(filename), &box_data)) return false; return ReadMemBoxes(target_page, skip_blanks, &box_data[0], boxes, texts, box_texts, pages); }
// Reads all boxes from the given filename. // Reads a specific target_page number if >= 0, or all pages otherwise. // Skips blanks if skip_blanks is true. // The UTF-8 label of the box is put in texts, and the full box definition as // a string is put in box_texts, with the corresponding page number in pages. // Each of the output vectors is optional (may be NULL). // Returns false if no boxes are found. bool ReadAllBoxes(int target_page, bool skip_blanks, const STRING& filename, GenericVector<TBOX>* boxes, GenericVector<STRING>* texts, GenericVector<STRING>* box_texts, GenericVector<int>* pages) { GenericVector<char> box_data; if (!tesseract::LoadDataFromFile(BoxFileName(filename), &box_data)) return false; // Convert the array of bytes to a string, so it can be used by the parser. box_data.push_back('\0'); return ReadMemBoxes(target_page, skip_blanks, &box_data[0], boxes, texts, box_texts, pages); }
// Parses the text string as a box file and adds any discovered boxes that // match the page number. Returns false on error. bool ImageData::AddBoxes(const char* box_text) { if (box_text != NULL && box_text[0] != '\0') { GenericVector<TBOX> boxes; GenericVector<STRING> texts; GenericVector<int> box_pages; if (ReadMemBoxes(page_number_, false, box_text, &boxes, &texts, NULL, &box_pages)) { AddBoxes(boxes, texts, box_pages); return true; } else { tprintf("Error: No boxes for page %d from image %s!\n", page_number_, imagefilename_.string()); } } return false; }