MCPcopy Create free account
hub / github.com/creatale/node-dv / Recognize

Method Recognize

deps/tesseract/cube/cube_object.cpp:94–166  ·  view source on GitHub ↗

* Actually do the recognition using the specified language mode. If none * is specified, the default language model in the CubeRecoContext is used. * @return the sorted list of alternate answers * @param word_mode determines whether recognition is done as a word or a phrase */

Source from the content-addressed store, hash-verified

92 * @param word_mode determines whether recognition is done as a word or a phrase
93 */
94WordAltList *CubeObject::Recognize(LangModel *lang_mod, bool word_mode) {
95 if (char_samp_ == NULL) {
96 return NULL;
97 }
98
99 // clear alt lists
100 Cleanup();
101
102 // no specified language model, use the one in the reco context
103 if (lang_mod == NULL) {
104 lang_mod = cntxt_->LangMod();
105 }
106
107 // normalize if necessary
108 if (cntxt_->SizeNormalization()) {
109 Normalize();
110 }
111
112 // assume not de-slanted by default
113 deslanted_ = false;
114
115 // create a beam search object
116 if (beam_obj_ == NULL) {
117 beam_obj_ = new BeamSearch(cntxt_, word_mode);
118 }
119
120 // create a cube search object
121 if (srch_obj_ == NULL) {
122 srch_obj_ = new CubeSearchObject(cntxt_, char_samp_);
123 }
124
125 // run a beam search against the tesslang model
126 alt_list_ = beam_obj_->Search(srch_obj_, lang_mod);
127
128 // deslant (if supported by language) and re-reco if probability is low enough
129 if (cntxt_->HasItalics() == true &&
130 (alt_list_ == NULL || alt_list_->AltCount() < 1 ||
131 alt_list_->AltCost(0) > CubeUtils::Prob2Cost(kMinProbSkipDeslanted))) {
132
133 if (deslanted_beam_obj_ == NULL) {
134 deslanted_beam_obj_ = new BeamSearch(cntxt_);
135 }
136
137 if (deslanted_srch_obj_ == NULL) {
138 deslanted_char_samp_ = char_samp_->Clone();
139 if (deslanted_char_samp_ == NULL) {
140 fprintf(stderr, "Cube ERROR (CubeObject::Recognize): could not "
141 "construct deslanted CharSamp\n");
142 return NULL;
143 }
144
145 if (deslanted_char_samp_->Deslant() == false) {
146 return NULL;
147 }
148
149 deslanted_srch_obj_ = new CubeSearchObject(cntxt_, deslanted_char_samp_);
150 }
151

Callers

nothing calls this directly

Calls 8

LangModMethod · 0.80
SizeNormalizationMethod · 0.80
HasItalicsMethod · 0.80
AltCountMethod · 0.80
AltCostMethod · 0.80
CloneMethod · 0.80
DeslantMethod · 0.80
SearchMethod · 0.45

Tested by

no test coverage detected