Skip to content

OCRHMMDecoder can't recognize text #1557

@Pzixel

Description

@Pzixel
  • OpenCV => 3.4.0
  • Operating System / Platform => Windows 10 64 Bit
  • Compiler => mingw 7.2.0

I'm trying to adopt code from the webcam_demo

I also used OCRHMM_transitions_table.xml and OCRHMM_knn_model_data.xml.gz from webcam_demo. And here is adopted 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 it returns nothing but m for every image that I have. For example, this image:

enter image description here

Expected output: uBuntu

Actual output: m

It's either bug in implementation or invalid transition_p and emission_p in example, because OCRTesseract is working fine with same parameters and images.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions