Find lines from the image making the BLOCK_LIST. */
| 2258 | |
| 2259 | /** Find lines from the image making the BLOCK_LIST. */ |
| 2260 | int TessBaseAPI::FindLines() { |
| 2261 | if (thresholder_ == NULL || thresholder_->IsEmpty()) { |
| 2262 | tprintf("Please call SetImage before attempting recognition."); |
| 2263 | return -1; |
| 2264 | } |
| 2265 | if (recognition_done_) |
| 2266 | ClearResults(); |
| 2267 | if (!block_list_->empty()) { |
| 2268 | return 0; |
| 2269 | } |
| 2270 | if (tesseract_ == NULL) { |
| 2271 | tesseract_ = new Tesseract; |
| 2272 | tesseract_->InitAdaptiveClassifier(false); |
| 2273 | } |
| 2274 | if (tesseract_->pix_binary() == NULL) |
| 2275 | Threshold(tesseract_->mutable_pix_binary()); |
| 2276 | if (tesseract_->ImageWidth() > MAX_INT16 || |
| 2277 | tesseract_->ImageHeight() > MAX_INT16) { |
| 2278 | tprintf("Image too large: (%d, %d)\n", |
| 2279 | tesseract_->ImageWidth(), tesseract_->ImageHeight()); |
| 2280 | return -1; |
| 2281 | } |
| 2282 | |
| 2283 | tesseract_->PrepareForPageseg(); |
| 2284 | |
| 2285 | if (tesseract_->textord_equation_detect) { |
| 2286 | if (equ_detect_ == NULL && datapath_ != NULL) { |
| 2287 | equ_detect_ = new EquationDetect(datapath_->string(), NULL); |
| 2288 | } |
| 2289 | tesseract_->SetEquationDetect(equ_detect_); |
| 2290 | } |
| 2291 | |
| 2292 | Tesseract* osd_tess = osd_tesseract_; |
| 2293 | OSResults osr; |
| 2294 | if (PSM_OSD_ENABLED(tesseract_->tessedit_pageseg_mode) && osd_tess == NULL) { |
| 2295 | if (strcmp(language_->string(), "osd") == 0) { |
| 2296 | osd_tess = tesseract_; |
| 2297 | } else { |
| 2298 | osd_tesseract_ = new Tesseract; |
| 2299 | if (osd_tesseract_->init_tesseract( |
| 2300 | datapath_->string(), NULL, "osd", OEM_TESSERACT_ONLY, |
| 2301 | NULL, 0, NULL, NULL, false) == 0) { |
| 2302 | osd_tess = osd_tesseract_; |
| 2303 | osd_tesseract_->set_source_resolution( |
| 2304 | thresholder_->GetSourceYResolution()); |
| 2305 | } else { |
| 2306 | tprintf("Warning: Auto orientation and script detection requested," |
| 2307 | " but osd language failed to load\n"); |
| 2308 | delete osd_tesseract_; |
| 2309 | osd_tesseract_ = NULL; |
| 2310 | } |
| 2311 | } |
| 2312 | } |
| 2313 | |
| 2314 | if (tesseract_->SegmentPage(input_file_, block_list_, osd_tess, &osr) < 0) |
| 2315 | return -1; |
| 2316 | // If Devanagari is being recognized, we use different images for page seg |
| 2317 | // and for OCR. |
nothing calls this directly
no test coverage detected