0

I'm trying to write simple program to recognize some simple patterns. It works fine with tesseract, but for some reason it doesn't work with Hmm. Here is sample code:

std::string image_path = "assets/ubuntu.png";
std::string filename = "assets/OCRHMM_transitions_table.xml";
auto image_source = cv::imread(image_path);
cv::Mat image;
cv::cvtColor(image_source, image, 6);
cv::Mat transition_p;
cv::FileStorage fs(filename, cv::FileStorage::READ);
fs["transition_probabilities"] >> transition_p;
fs.release();
cv::Mat emission_p = cv::Mat::eye(62,62,CV_64FC1);
std::string voc = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
auto classifier = cv::text::loadOCRHMMClassifierNM("assets/OCRHMM_knn_model_data.xml.gz");
auto ocr = cv::text::OCRHMMDecoder::create(classifier, voc, transition_p, emission_p);

std::string output;
std::vector<cv::Rect> boxes;
std::vector<std::string> words;
std::vector<float> confidences;
ocr.get()->run(image, output, &boxes, &words, &confidences);
std::cout << output;

and sample image:

enter image description here

Expected output: uBuntu

Actual output: m

What's wrong with this code? I just tried to adopt demo sample.

Here is OCRHMM_transitions_table.xml and OCRHMM_knn_model_data.xml.gz which was used (I actually took them from this sample too).

OpenCV version 3.4.0

Alex Zhukovskiy
  • 9,565
  • 11
  • 75
  • 151

1 Answers1

0

Cascade classfier look like not trained enough.Why don't you use another classfier?It detects u half of m

enter image description here

my-lord
  • 2,453
  • 3
  • 12
  • 26
  • 1
    Good theory. However, it's not true because it returns `m` for all images I tried till now, for example image with single letter `x` is recognised as `m`. It may be very bad trained model, but I don't believe so beacuse I took it from official example which couldn't be this bad on that easy font. – Alex Zhukovskiy Feb 13 '18 at 17:01