Adds two more examples of croped word recognition, and show how to set the beam size parameter for small lexicon.

pull/350/head
Lluis Gomez-Bigorda 9 years ago
parent cc43177675
commit 7cd6dbb0c9
  1. 9
      modules/text/samples/cropped_word_recognition.cpp
  2. BIN
      modules/text/samples/scenetext_word03.jpg
  3. BIN
      modules/text/samples/scenetext_word04.jpg

@ -39,12 +39,13 @@ int main(int argc, char* argv[])
string vocabulary = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; // must have the same order as the clasifier output classes
vector<string> lexicon; // a list of words expected to be found on the input image
lexicon.push_back(string("abb"));
lexicon.push_back(string("patata"));
lexicon.push_back(string("riser"));
lexicon.push_back(string("CHINA"));
lexicon.push_back(string("HERE"));
lexicon.push_back(string("President"));
lexicon.push_back(string("smash"));
lexicon.push_back(string("KUALA"));
lexicon.push_back(string("Produkt"));
lexicon.push_back(string("NINTENDO"));
// Create tailored language model a small given lexicon
@ -54,16 +55,18 @@ int main(int argc, char* argv[])
// An alternative would be to load the default generic language model
// (created from ispell 42869 english words list)
/*Mat transition_p;
string filename = "OCRHMM_transitions_table.xml"; // TODO use same order for voc
string filename = "OCRHMM_transitions_table.xml";
FileStorage fs(filename, FileStorage::READ);
fs["transition_probabilities"] >> transition_p;
fs.release();*/
Mat emission_p = Mat::eye(62,62,CV_64FC1);
// Notice we set here a beam size of 50. This is much faster than using the default value (500).
// 50 works well with our tiny lexicon example, but may not with larger dictionaries.
Ptr<OCRBeamSearchDecoder> ocr = OCRBeamSearchDecoder::create(
loadOCRBeamSearchClassifierCNN("OCRBeamSearch_CNN_model_data.xml.gz"),
vocabulary, transition_p, emission_p);
vocabulary, transition_p, emission_p, OCR_DECODER_VITERBI, 50);
double t_r = (double)getTickCount();
string output;

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 46 KiB

Loading…
Cancel
Save