Assertion failed in text module with OCRHMMDecoder (Bug #4373)


Added by Lukas Stehr almost 10 years ago. Updated over 9 years ago.


Status:Done Start date:2015-06-02
Priority:Normal Due date:
Assignee:- % Done:

0%

Category:contrib/text
Target version:-
Affected version:branch 'master' (3.0-dev) Operating System:Mac OSX
Difficulty: HW Platform:x86
Pull request:

Description

I think I encountered a bug in the text module of opencv_contrib. OCRHMMDecoder::run works fine for most images, but there is the case that an assertion inside OCRHMMDecoder fails for some images.

Sample Code:

#include <iostream>

#include "opencv2/opencv.hpp" 
#include "opencv2/text.hpp" 

int main(int argc, char* argv[]) {

    cv::Mat image = cv::imread("./bad.jpg");
    cv::cvtColor(image, image, cv::COLOR_BGR2GRAY);

    cv::Mat transitionProbabilities;
    cv::FileStorage fs("./OCRHMM_transitions_table.xml", cv::FileStorage::READ);
    fs["transition_probabilities"] >> transitionProbabilities;
    fs.release();

    std::string charWhitelist = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
    cv::Mat emissionProbabilities = cv::Mat::eye((int)charWhitelist.size(), (int)charWhitelist.size(), CV_64FC1);

    cv::Ptr<cv::text::OCRHMMDecoder> ocr = cv::text::OCRHMMDecoder::create(cv::text::loadOCRHMMClassifierNM("./OCRHMM_knn_model_data.xml.gz"), charWhitelist, transitionProbabilities, emissionProbabilities);

    std::string output = "";
    ocr->run(image, output);

    std::cout << output << std::endl;
}

Executing this code with the default classifier files and the attached bad.jpg gives:

OpenCV Error: Assertion failed (dsize.area() > 0 || (inv_scale_x > 0 && inv_scale_y > 0)) in resize, file /Users/lukasstehr/Lukas/Code/opencv/modules/imgproc/src/imgwarp.cpp, line 3209
libc++abi.dylib: terminating with uncaught exception of type cv::Exception: /Users/lukasstehr/Lukas/Code/opencv/modules/imgproc/src/imgwarp.cpp:3209: error: (-215) dsize.area() > 0 || (inv_scale_x > 0 && inv_scale_y > 0) in function resize

The code works fine with most other images, for example the attached good.jpg.


bad.jpg (2.8 kB) Lukas Stehr, 2015-06-02 05:00 pm

good.jpg (2.2 kB) Lukas Stehr, 2015-06-02 05:00 pm


History

Updated by Vadim Pisarevsky over 9 years ago

  • Category set to contrib/text

Updated by Lluis Gomez over 9 years ago

This bug is fixed in PR #308. The problem was when trying to recognize very elongated contours. Since every contour is resized to a normalized size, that would give a destination width/height of zero pixels for elongated contours and this causes the assertion failed error.

https://github.com/Itseez/opencv_contrib/pull/308

Thanks!

  • Status changed from New to Done

Also available in: Atom PDF