@@ -590,10 +590,11 @@ void TessBaseAPI::SetRectangle(int left, int top, int width, int height) {
590
590
* Get a copy of the internal thresholded image from Tesseract.
591
591
*/
592
592
Pix* TessBaseAPI::GetThresholdedImage () {
593
- if (tesseract_ == NULL || thresholder_ == NULL )
594
- return NULL ;
595
- if (tesseract_->pix_binary () == NULL )
596
- Threshold (tesseract_->mutable_pix_binary ());
593
+ if (tesseract_ == nullptr || thresholder_ == nullptr ) return nullptr ;
594
+ if (tesseract_->pix_binary () == nullptr &&
595
+ !Threshold (tesseract_->mutable_pix_binary ())) {
596
+ return nullptr ;
597
+ }
597
598
return pixClone (tesseract_->pix_binary ());
598
599
}
599
600
@@ -2189,7 +2190,7 @@ bool TessBaseAPI::InternalSetImage() {
2189
2190
* to an existing pixDestroyable Pix.
2190
2191
* The usual argument to Threshold is Tesseract::mutable_pix_binary().
2191
2192
*/
2192
- void TessBaseAPI::Threshold (Pix** pix) {
2193
+ bool TessBaseAPI::Threshold (Pix** pix) {
2193
2194
ASSERT_HOST (pix != NULL );
2194
2195
if (*pix != NULL )
2195
2196
pixDestroy (pix);
@@ -2205,7 +2206,7 @@ void TessBaseAPI::Threshold(Pix** pix) {
2205
2206
PageSegMode pageseg_mode =
2206
2207
static_cast <PageSegMode>(
2207
2208
static_cast <int >(tesseract_->tessedit_pageseg_mode ));
2208
- thresholder_->ThresholdToPix (pageseg_mode, pix);
2209
+ if (! thresholder_->ThresholdToPix (pageseg_mode, pix)) return false ;
2209
2210
thresholder_->GetImageSizes (&rect_left_, &rect_top_,
2210
2211
&rect_width_, &rect_height_,
2211
2212
&image_width_, &image_height_);
@@ -2229,6 +2230,7 @@ void TessBaseAPI::Threshold(Pix** pix) {
2229
2230
}
2230
2231
tesseract_->set_source_resolution (estimated_res);
2231
2232
SavePixForCrash (estimated_res, *pix);
2233
+ return true ;
2232
2234
}
2233
2235
2234
2236
/* * Find lines from the image making the BLOCK_LIST. */
@@ -2246,12 +2248,8 @@ int TessBaseAPI::FindLines() {
2246
2248
tesseract_ = new Tesseract;
2247
2249
tesseract_->InitAdaptiveClassifier (nullptr );
2248
2250
}
2249
- if (tesseract_->pix_binary () == NULL )
2250
- Threshold (tesseract_->mutable_pix_binary ());
2251
- if (tesseract_->ImageWidth () > MAX_INT16 ||
2252
- tesseract_->ImageHeight () > MAX_INT16) {
2253
- tprintf (" Image too large: (%d, %d)\n " ,
2254
- tesseract_->ImageWidth (), tesseract_->ImageHeight ());
2251
+ if (tesseract_->pix_binary () == NULL &&
2252
+ !Threshold (tesseract_->mutable_pix_binary ())) {
2255
2253
return -1 ;
2256
2254
}
2257
2255
@@ -2359,11 +2357,13 @@ bool TessBaseAPI::DetectOS(OSResults* osr) {
2359
2357
if (tesseract_ == NULL )
2360
2358
return false ;
2361
2359
ClearResults ();
2362
- if (tesseract_->pix_binary () == NULL )
2363
- Threshold (tesseract_->mutable_pix_binary ());
2360
+ if (tesseract_->pix_binary () == NULL &&
2361
+ !Threshold (tesseract_->mutable_pix_binary ())) {
2362
+ return false ;
2363
+ }
2364
2364
if (input_file_ == NULL )
2365
2365
input_file_ = new STRING (kInputFile );
2366
- return orientation_and_script_detection (*input_file_, osr, tesseract_);
2366
+ return orientation_and_script_detection (*input_file_, osr, tesseract_) > 0 ;
2367
2367
}
2368
2368
2369
2369
void TessBaseAPI::set_min_orientation_margin (double margin) {
0 commit comments