Assertion failed in text module with OCRHMMDecoder (Bug #4373)
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
.
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