我正在尝试编写简单的程序来识别一些简单的模式。它适用于tesseract,但由于某种原因它不适用于Hmm
。以下是示例代码:
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;
和样本图片:
预期输出:uBuntu
实际输出:m
这段代码有什么问题?我刚刚尝试采用demo sample。
这里使用的是OCRHMM_transitions_table.xml和OCRHMM_knn_model_data.xml.gz(我实际上也从这个样本中获取了它们)。
OpenCV版本3.4.0