@@ -121,7 +121,6 @@ TessBaseAPI::TessBaseAPI()
121
121
block_list_(NULL ),
122
122
page_res_(NULL ),
123
123
input_file_(NULL ),
124
- input_image_(NULL ),
125
124
output_file_(NULL ),
126
125
datapath_(NULL ),
127
126
language_(NULL ),
@@ -515,19 +514,19 @@ void TessBaseAPI::ClearAdaptiveClassifier() {
515
514
516
515
/* *
517
516
* Provide an image for Tesseract to recognize. Format is as
518
- * TesseractRect above. Does not copy the image buffer, or take
519
- * ownership. The source image may be destroyed after Recognize is called,
520
- * either explicitly or implicitly via one of the Get*Text functions.
517
+ * TesseractRect above. Copies the image buffer and converts to Pix.
521
518
* SetImage clears all recognition results, and sets the rectangle to the
522
519
* full image, so it may be followed immediately by a GetUTF8Text, and it
523
520
* will automatically perform recognition.
524
521
*/
525
522
void TessBaseAPI::SetImage (const unsigned char * imagedata,
526
523
int width, int height,
527
524
int bytes_per_pixel, int bytes_per_line) {
528
- if (InternalSetImage ())
525
+ if (InternalSetImage ()) {
529
526
thresholder_->SetImage (imagedata, width, height,
530
527
bytes_per_pixel, bytes_per_line);
528
+ SetInputImage (thresholder_->GetPixRect ());
529
+ }
531
530
}
532
531
533
532
void TessBaseAPI::SetSourceResolution (int ppi) {
@@ -539,18 +538,17 @@ void TessBaseAPI::SetSourceResolution(int ppi) {
539
538
540
539
/* *
541
540
* Provide an image for Tesseract to recognize. As with SetImage above,
542
- * Tesseract doesn't take a copy or ownership or pixDestroy the image, so
543
- * it must persist until after Recognize.
541
+ * Tesseract takes its own copy of the image, so it need not persist until
542
+ * after Recognize.
544
543
* Pix vs raw, which to use?
545
- * Use Pix where possible. A future version of Tesseract may choose to use Pix
546
- * as its internal representation and discard IMAGE altogether.
547
- * Because of that, an implementation that sources and targets Pix may end up
548
- * with less copies than an implementation that does not.
544
+ * Use Pix where possible. Tesseract uses Pix as its internal representation
545
+ * and it is therefore more efficient to provide a Pix directly.
549
546
*/
550
547
void TessBaseAPI::SetImage (Pix* pix) {
551
- if (InternalSetImage ())
548
+ if (InternalSetImage ()) {
552
549
thresholder_->SetImage (pix);
553
- SetInputImage (pix);
550
+ SetInputImage (thresholder_->GetPixRect ());
551
+ }
554
552
}
555
553
556
554
/* *
@@ -693,8 +691,8 @@ Boxa* TessBaseAPI::GetComponentImages(PageIteratorLevel level,
693
691
if (pixa != NULL ) {
694
692
Pix* pix = NULL ;
695
693
if (raw_image) {
696
- pix = page_it->GetImage (level, raw_padding, input_image_ ,
697
- &left, & top);
694
+ pix = page_it->GetImage (level, raw_padding, GetInputImage (), &left ,
695
+ &top);
698
696
} else {
699
697
pix = page_it->GetBinaryImage (level);
700
698
}
@@ -849,13 +847,17 @@ int TessBaseAPI::Recognize(ETEXT_DESC* monitor) {
849
847
} else if (tesseract_->tessedit_resegment_from_boxes ) {
850
848
page_res_ = tesseract_->ApplyBoxes (*input_file_, false , block_list_);
851
849
} else {
852
- // TODO(rays) LSTM here.
853
- page_res_ = new PAGE_RES (false ,
850
+ page_res_ = new PAGE_RES (tesseract_->AnyLSTMLang (),
854
851
block_list_, &tesseract_->prev_word_best_choice_ );
855
852
}
856
853
if (page_res_ == NULL ) {
857
854
return -1 ;
858
855
}
856
+ if (tesseract_->tessedit_train_line_recognizer ) {
857
+ tesseract_->TrainLineRecognizer (*input_file_, *output_file_, block_list_);
858
+ tesseract_->CorrectClassifyWords (page_res_);
859
+ return 0 ;
860
+ }
859
861
if (tesseract_->tessedit_make_boxes_from_boxes ) {
860
862
tesseract_->CorrectClassifyWords (page_res_);
861
863
return 0 ;
@@ -938,17 +940,10 @@ int TessBaseAPI::RecognizeForChopTest(ETEXT_DESC* monitor) {
938
940
return 0 ;
939
941
}
940
942
941
- void TessBaseAPI::SetInputImage (Pix *pix) {
942
- if (input_image_)
943
- pixDestroy (&input_image_);
944
- input_image_ = NULL ;
945
- if (pix)
946
- input_image_ = pixCopy (NULL , pix);
947
- }
943
+ // Takes ownership of the input pix.
944
+ void TessBaseAPI::SetInputImage (Pix* pix) { tesseract_->set_pix_original (pix); }
948
945
949
- Pix* TessBaseAPI::GetInputImage () {
950
- return input_image_;
951
- }
946
+ Pix* TessBaseAPI::GetInputImage () { return tesseract_->pix_original (); }
952
947
953
948
const char * TessBaseAPI::GetInputName () {
954
949
if (input_file_)
@@ -992,8 +987,7 @@ bool TessBaseAPI::ProcessPagesFileList(FILE *flist,
992
987
}
993
988
994
989
// Begin producing output
995
- const char * kUnknownTitle = " " ;
996
- if (renderer && !renderer->BeginDocument (kUnknownTitle )) {
990
+ if (renderer && !renderer->BeginDocument (unknown_title_)) {
997
991
return false ;
998
992
}
999
993
@@ -1105,7 +1099,6 @@ bool TessBaseAPI::ProcessPagesInternal(const char* filename,
1105
1099
const char * retry_config,
1106
1100
int timeout_millisec,
1107
1101
TessResultRenderer* renderer) {
1108
- #ifndef ANDROID_BUILD
1109
1102
PERF_COUNT_START (" ProcessPages" )
1110
1103
bool stdInput = !strcmp (filename, " stdin" ) || !strcmp (filename, " -" );
1111
1104
if (stdInput) {
@@ -1162,8 +1155,7 @@ bool TessBaseAPI::ProcessPagesInternal(const char* filename,
1162
1155
}
1163
1156
1164
1157
// Begin the output
1165
- const char * kUnknownTitle = " " ;
1166
- if (renderer && !renderer->BeginDocument (kUnknownTitle )) {
1158
+ if (renderer && !renderer->BeginDocument (unknown_title_)) {
1167
1159
pixDestroy (&pix);
1168
1160
return false ;
1169
1161
}
@@ -1185,9 +1177,6 @@ bool TessBaseAPI::ProcessPagesInternal(const char* filename,
1185
1177
}
1186
1178
PERF_COUNT_END
1187
1179
return true ;
1188
- #else
1189
- return false ;
1190
- #endif
1191
1180
}
1192
1181
1193
1182
bool TessBaseAPI::ProcessPage (Pix* pix, int page_index, const char * filename,
@@ -2107,10 +2096,6 @@ void TessBaseAPI::End() {
2107
2096
delete input_file_;
2108
2097
input_file_ = NULL ;
2109
2098
}
2110
- if (input_image_ != NULL ) {
2111
- pixDestroy (&input_image_);
2112
- input_image_ = NULL ;
2113
- }
2114
2099
if (output_file_ != NULL ) {
2115
2100
delete output_file_;
2116
2101
output_file_ = NULL ;
0 commit comments