2007-03-08 04:03:40 +08:00
|
|
|
/**********************************************************************
|
2017-07-03 05:35:47 +08:00
|
|
|
* File: tface.cpp (Formerly tface.c)
|
2007-03-08 04:03:40 +08:00
|
|
|
* Description: C side of the Tess/tessedit C/C++ interface.
|
|
|
|
* Author: Ray Smith
|
|
|
|
* Created: Mon Apr 27 11:57:06 BST 1992
|
|
|
|
*
|
|
|
|
* (C) Copyright 1992, Hewlett-Packard Ltd.
|
|
|
|
** Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
** you may not use this file except in compliance with the License.
|
|
|
|
** You may obtain a copy of the License at
|
|
|
|
** http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
** Unless required by applicable law or agreed to in writing, software
|
|
|
|
** distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
** See the License for the specific language governing permissions and
|
|
|
|
** limitations under the License.
|
|
|
|
*
|
|
|
|
**********************************************************************/
|
2010-11-24 02:34:14 +08:00
|
|
|
|
|
|
|
#include "callcpp.h"
|
|
|
|
#include "chop.h"
|
|
|
|
#include "chopper.h"
|
2007-03-08 04:03:40 +08:00
|
|
|
#include "danerror.h"
|
|
|
|
#include "globals.h"
|
|
|
|
#include "gradechop.h"
|
2010-11-24 02:34:14 +08:00
|
|
|
#include "pageres.h"
|
2009-07-11 10:46:01 +08:00
|
|
|
#include "wordrec.h"
|
2010-11-24 02:34:14 +08:00
|
|
|
#include "featdefs.h"
|
2013-09-23 23:26:50 +08:00
|
|
|
#include "params_model.h"
|
2007-03-08 04:03:40 +08:00
|
|
|
|
|
|
|
#include <math.h>
|
|
|
|
#ifdef __UNIX__
|
|
|
|
#include <unistd.h>
|
|
|
|
#endif
|
2009-07-11 10:46:01 +08:00
|
|
|
|
|
|
|
|
|
|
|
namespace tesseract {
|
2007-03-08 04:03:40 +08:00
|
|
|
|
2010-07-27 21:23:23 +08:00
|
|
|
/**
|
|
|
|
* @name program_editup
|
2007-03-08 04:03:40 +08:00
|
|
|
*
|
|
|
|
* Initialize all the things in the program that need to be initialized.
|
2009-07-11 10:46:01 +08:00
|
|
|
* init_permute determines whether to initialize the permute functions
|
|
|
|
* and Dawg models.
|
2010-07-27 21:23:23 +08:00
|
|
|
*/
|
2010-11-24 02:34:14 +08:00
|
|
|
void Wordrec::program_editup(const char *textbase,
|
2017-04-28 06:48:23 +08:00
|
|
|
TessdataManager *init_classifier,
|
|
|
|
TessdataManager *init_dict) {
|
2010-11-24 02:34:14 +08:00
|
|
|
if (textbase != NULL) imagefile = textbase;
|
|
|
|
InitFeatureDefs(&feature_defs_);
|
|
|
|
InitAdaptiveClassifier(init_classifier);
|
2016-11-08 07:38:07 +08:00
|
|
|
if (init_dict) {
|
|
|
|
getDict().SetupForLoad(Dict::GlobalDawgCache());
|
2017-04-28 06:48:23 +08:00
|
|
|
getDict().Load(lang, init_dict);
|
2016-11-08 07:38:07 +08:00
|
|
|
getDict().FinishLoad();
|
|
|
|
}
|
2009-07-11 10:46:01 +08:00
|
|
|
pass2_ok_split = chop_ok_split;
|
2007-03-08 04:03:40 +08:00
|
|
|
}
|
|
|
|
|
2010-07-27 21:23:23 +08:00
|
|
|
/**
|
|
|
|
* @name end_recog
|
2007-03-08 04:03:40 +08:00
|
|
|
*
|
|
|
|
* Cleanup and exit the recog program.
|
2010-07-27 21:23:23 +08:00
|
|
|
*/
|
2009-07-11 10:46:01 +08:00
|
|
|
int Wordrec::end_recog() {
|
2007-03-08 04:03:40 +08:00
|
|
|
program_editdown (0);
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-07-27 21:23:23 +08:00
|
|
|
/**
|
|
|
|
* @name program_editdown
|
2007-03-08 04:03:40 +08:00
|
|
|
*
|
|
|
|
* This function holds any nessessary post processing for the Wise Owl
|
|
|
|
* program.
|
2010-07-27 21:23:23 +08:00
|
|
|
*/
|
Use POSIX data types and macros (#878)
* api: Replace Tesseract data types by POSIX data types
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* ccmain: Replace Tesseract data types by POSIX data types
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* ccstruct: Replace Tesseract data types by POSIX data types
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* classify: Replace Tesseract data types by POSIX data types
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* cutil: Replace Tesseract data types by POSIX data types
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* dict: Replace Tesseract data types by POSIX data types
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* textord: Replace Tesseract data types by POSIX data types
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* training: Replace Tesseract data types by POSIX data types
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* wordrec: Replace Tesseract data types by POSIX data types
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* ccutil: Replace Tesseract data types by POSIX data types
Now all Tesseract data types which are no longer needed can be removed
from ccutil/host.h.
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* ccmain: Replace Tesseract's MIN_*INT, MAX_*INT* by POSIX *INT*_MIN, *INT*_MAX
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* ccstruct: Replace Tesseract's MIN_*INT, MAX_*INT* by POSIX *INT*_MIN, *INT*_MAX
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* classify: Replace Tesseract's MIN_*INT, MAX_*INT* by POSIX *INT*_MIN, *INT*_MAX
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* dict: Replace Tesseract's MIN_*INT, MAX_*INT* by POSIX *INT*_MIN, *INT*_MAX
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* lstm: Replace Tesseract's MIN_*INT, MAX_*INT* by POSIX *INT*_MIN, *INT*_MAX
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* textord: Replace Tesseract's MIN_*INT, MAX_*INT* by POSIX *INT*_MIN, *INT*_MAX
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* wordrec: Replace Tesseract's MIN_*INT, MAX_*INT* by POSIX *INT*_MIN, *INT*_MAX
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* ccutil: Replace Tesseract's MIN_*INT, MAX_*INT* by POSIX *INT*_MIN, *INT*_MAX
Remove the macros which are now unused from ccutil/host.h.
Remove also the obsolete history comments.
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* Fix build error caused by ambiguous ClipToRange
Error message vom Appveyor CI:
C:\projects\tesseract\ccstruct\coutln.cpp(818): error C2672: 'ClipToRange': no matching overloaded function found [C:\projects\tesseract\build\libtesseract.vcxproj]
C:\projects\tesseract\ccstruct\coutln.cpp(818): error C2782: 'T ClipToRange(const T &,const T &,const T &)': template parameter 'T' is ambiguous [C:\projects\tesseract\build\libtesseract.vcxproj]
c:\projects\tesseract\ccutil\helpers.h(122): note: see declaration of 'ClipToRange'
C:\projects\tesseract\ccstruct\coutln.cpp(818): note: could be 'char'
C:\projects\tesseract\ccstruct\coutln.cpp(818): note: or 'int'
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* unittest: Replace Tesseract's MAX_INT8 by POSIX INT8_MAX
Signed-off-by: Stefan Weil <sw@weilnetz.de>
* arch: Replace Tesseract's MAX_INT8 by POSIX INT8_MAX
Signed-off-by: Stefan Weil <sw@weilnetz.de>
2018-03-14 04:36:30 +08:00
|
|
|
void Wordrec::program_editdown(int32_t elasped_time) {
|
2010-11-24 02:34:14 +08:00
|
|
|
EndAdaptiveClassifier();
|
|
|
|
getDict().End();
|
2007-03-08 04:03:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-07-27 21:23:23 +08:00
|
|
|
/**
|
|
|
|
* @name set_pass1
|
2007-03-08 04:03:40 +08:00
|
|
|
*
|
|
|
|
* Get ready to do some pass 1 stuff.
|
2010-07-27 21:23:23 +08:00
|
|
|
*/
|
2009-07-11 10:46:01 +08:00
|
|
|
void Wordrec::set_pass1() {
|
|
|
|
chop_ok_split.set_value(70.0);
|
2013-09-23 23:26:50 +08:00
|
|
|
language_model_->getParamsModel().SetPass(ParamsModel::PTRAIN_PASS1);
|
2007-03-08 04:03:40 +08:00
|
|
|
SettupPass1();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-07-27 21:23:23 +08:00
|
|
|
/**
|
|
|
|
* @name set_pass2
|
2007-03-08 04:03:40 +08:00
|
|
|
*
|
|
|
|
* Get ready to do some pass 2 stuff.
|
2010-07-27 21:23:23 +08:00
|
|
|
*/
|
2009-07-11 10:46:01 +08:00
|
|
|
void Wordrec::set_pass2() {
|
|
|
|
chop_ok_split.set_value(pass2_ok_split);
|
2013-09-23 23:26:50 +08:00
|
|
|
language_model_->getParamsModel().SetPass(ParamsModel::PTRAIN_PASS2);
|
2007-03-08 04:03:40 +08:00
|
|
|
SettupPass2();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-07-27 21:23:23 +08:00
|
|
|
/**
|
|
|
|
* @name cc_recog
|
2007-03-08 04:03:40 +08:00
|
|
|
*
|
|
|
|
* Recognize a word.
|
2010-07-27 21:23:23 +08:00
|
|
|
*/
|
2013-09-23 23:26:50 +08:00
|
|
|
void Wordrec::cc_recog(WERD_RES *word) {
|
2010-11-24 02:34:14 +08:00
|
|
|
getDict().reset_hyphen_vars(word->word->flag(W_EOL));
|
2013-09-23 23:26:50 +08:00
|
|
|
chop_word_main(word);
|
|
|
|
word->DebugWordChoices(getDict().stopper_debug_level >= 1,
|
|
|
|
getDict().word_to_debug.string());
|
|
|
|
ASSERT_HOST(word->StatesAllValid());
|
2007-03-08 04:03:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-07-27 21:23:23 +08:00
|
|
|
/**
|
|
|
|
* @name dict_word()
|
2007-03-08 04:03:40 +08:00
|
|
|
*
|
2009-07-11 10:46:01 +08:00
|
|
|
* Test the dictionaries, returning NO_PERM (0) if not found, or one
|
|
|
|
* of the PermuterType values if found, according to the dictionary.
|
2010-07-27 21:23:23 +08:00
|
|
|
*/
|
2009-07-11 10:46:01 +08:00
|
|
|
int Wordrec::dict_word(const WERD_CHOICE &word) {
|
|
|
|
return getDict().valid_word(word);
|
|
|
|
}
|
|
|
|
|
2010-07-27 21:23:23 +08:00
|
|
|
/**
|
|
|
|
* @name call_matcher
|
2009-07-11 10:46:01 +08:00
|
|
|
*
|
|
|
|
* Called from Tess with a blob in tess form.
|
2010-11-24 02:34:14 +08:00
|
|
|
* The blob may need rotating to the correct orientation for classification.
|
2010-07-27 21:23:23 +08:00
|
|
|
*/
|
2013-09-23 23:26:50 +08:00
|
|
|
BLOB_CHOICE_LIST *Wordrec::call_matcher(TBLOB *tessblob) {
|
2012-02-02 11:01:38 +08:00
|
|
|
// Rotate the blob for classification if necessary.
|
2013-09-23 23:26:50 +08:00
|
|
|
TBLOB* rotated_blob = tessblob->ClassifyNormalizeIfNeeded();
|
2012-02-02 11:01:38 +08:00
|
|
|
if (rotated_blob == NULL) {
|
|
|
|
rotated_blob = tessblob;
|
2009-07-11 10:46:01 +08:00
|
|
|
}
|
2010-11-24 02:34:14 +08:00
|
|
|
BLOB_CHOICE_LIST *ratings = new BLOB_CHOICE_LIST(); // matcher result
|
2014-01-25 05:17:43 +08:00
|
|
|
AdaptiveClassifier(rotated_blob, ratings);
|
2012-02-02 11:01:38 +08:00
|
|
|
if (rotated_blob != tessblob) {
|
2010-11-24 02:34:14 +08:00
|
|
|
delete rotated_blob;
|
2012-02-02 11:01:38 +08:00
|
|
|
}
|
2010-11-24 02:34:14 +08:00
|
|
|
return ratings;
|
2009-07-11 10:46:01 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
} // namespace tesseract
|