Opencv_contrib: cv2.error: OpenCV(4.1.1) /io/opencv_contrib/modules/text/src/text_detectorCNN.cpp:38: error: (-2:Unspecified error)

Created on 1 Oct 2019  Â·  17Comments  Â·  Source: opencv/opencv_contrib

System information (version)
  • OpenCV => 4.1.1
  • Operating System / Platform => Ubuntu 18.04 amd64
  • Compiler => g++ 7.4.0
Detailed description

I get an assertion in textDetectorCNN using both C++ and Python.
The error is the same (please note all I've done is copy-paste example code):

Traceback (most recent call last):
  File "extractor.py", line 11, in <module>
    rects, probs = det.detect(image)
cv2.error: OpenCV(4.1.1) /io/opencv_contrib/modules/text/src/text_detectorCNN.cpp:38: error: (-2:Unspecified error) in function 'void cv::text::TextDetectorCNNImpl::getOutputs(const float*, int, int, std::vector<cv::Rect_<int> >&, std::vector<float>&, cv::Size)'
>  (expected: 'x_min < x_max'), where
>     'x_min' is 0
> must be less than
>     'x_max' is 0

And in C++:

terminate called after throwing an instance of 'cv::Exception'
  what():  OpenCV(4.1.1) opencv_4.1.1/opencv_contrib-4.1.1/modules/text/src/text_detectorCNN.cpp:38: error: (-2:Unspecified error) in function 'void cv::text::TextDetectorCNNImpl::getOutputs(const float*, int, int, std::vector<cv::Rect_<int> >&, std::vector<float>&, cv::Size)'
>  (expected: 'x_min < x_max'), where
>     'x_min' is 0
> must be less than
>     'x_max' is 0

Aborted (core dumped)
Steps to reproduce

in C++ I just tried the example found in text_demo.cpp and with python I tried the following:

import argparse
import cv2

ap = argparse.ArgumentParser()
ap.add_argument("-i", "--image", required = True, help = "Path to the image")
args = vars(ap.parse_args())

image = cv2.imread(args["image"])
det = cv2.text.TextDetectorCNN_create("../config/textbox.prototxt",
                                      "../config/TextBoxes_icdar13.caffemodel")
rects, probs = det.detect(image)
print(rects, probs)
cv2.imshow("image", image)
cv2.waitKey(0)

Stepping through the debugger is very clear:

Thread 1 "evidence_verifi" received signal SIGABRT, Aborted.
__GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:51
51      ../sysdeps/unix/sysv/linux/raise.c: No such file or directory.
(gdb) bt
#0  0x00007ffff4057e97 in __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:51
#1  0x00007ffff4059801 in __GI_abort () at abort.c:79
#2  0x00007ffff46ae957 in  () at /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#3  0x00007ffff46b4ab6 in  () at /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#4  0x00007ffff46b4af1 in  () at /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#5  0x00007ffff46b4d24 in  () at /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#6  0x00007ffff4d1da86 in cv::error(cv::Exception const&) () at /usr/local/lib/libopencv_core.so.4.1
#7  0x00007ffff4d233d2 in cv::error(int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, char const*, char const*, int) () at /usr/local/lib/libopencv_core.so.4.1
#8  0x00007ffff4b02bb2 in void cv::detail::check_failed_auto_<float>(float const&, float const&, cv::detail::CheckContext const&) () at /usr/local/lib/libopencv_core.so.4.1
#9  0x00007ffff4b03a22 in  () at /usr/local/lib/libopencv_core.so.4.1
#10 0x00007ffff745a677 in cv::text::TextDetectorCNNImpl::detect(cv::_InputArray const&, std::vector<cv::Rect_<int>, std::allocator<cv::Rect_<int> > >&, std::vector<float, std::allocator<float> >&) () at /usr/local/lib/libopencv_text.so.4.1
#11 0x00005555555572d6 in main ()
(gdb) 

I took a look in the source code and can find the trigger of the assertion. Has anyone run into this before? I've even tried with different sizes to see if that would affect it, but to no avail. I'm re-building OpenCV with debug symbols to see if I can step into it.

bug text

All 17 comments

I ran into exactly the same error today ..

  • OpenCV 4.1.2
  • Ubuntu 18.04.2 LTS
  • gcc 7.4.0

I'm using webcam frames as input obtained with cv2.VideoCapture(0) in python 3.6

Please provide reproducer data (input image).

see my edited comment above -> webcam input

I see no problem with saving of captured frame before passing to text detector:

  • cv::imwrite("frame.png", frame);
  • cv.imwrite("frame.png", frame)

Thanks for looking into this. I'm not sure I understand your reply, however, the error is thrown after

det = cv2.text.TextDetectorCNN_create("../config/textbox.prototxt",
                                      "../config/TextBoxes_icdar13.caffemodel")
rects, probs = det.detect(image)

where - in my case - image is the output of cv2.VideoCapture(0) ... I'm not concerned with saving the image, I just need the output of the detector ...

Please provide reproducer data (input image).

Bug report should contain complete minimal reproducer ("complete" includes input data).

Sorry for the confusion - here's the saved frame

frame

In my case it is a PNG form attached below.

1CDFC_XPR16150-0_otsu

Thank you for images!

Could you please try this patch #2315 ?

BTW, You may be interested in model from this demo: https://github.com/opencv/open_model_zoo/pull/327

Hi @alalek
I'm getting a compilation error now:

opencv_4.1.1/opencv-4.1.1/modules/imgcodecs/include/opencv2/imgcodecs/imgcodecs_c.h:1:2: error: #error "This header with legacy C API declarations has been removed from OpenCV. Legacy contants are available from legacy/constants_c.h file."
 #error "This header with legacy C API declarations has been removed from OpenCV. Legacy contants are available from legacy/constants_c.h file."

All I did was clone the contrib repo and checkout your commit, then tried to rebuild it.
Any way to circumvent it for now?

Mentioned patch is built on top of "3.4" branch. So you need OpenCV 3.4 or rebased patch onto master.

Hi @alalek sadly it still fails to compile. I've cloned opencv-3.4 and tried again, this time I get:

[ 78%] Building CXX object modules/xfeatures2d/CMakeFiles/opencv_xfeatures2d.dir/src/fast.cpp.o
opencv_3.4./opencv_contrib/modules/xfeatures2d/src/fast.cpp: In function ‘void cv::xfeatures2d::FASTForPointSet(cv::InputArray, std::vector<cv::KeyPoint>&, int, bool, int)’:
opencv_3.4./opencv_contrib/modules/xfeatures2d/src/fast.cpp:462:74: error: invalid conversion from ‘int’ to ‘cv::FastFeatureDetector::DetectorType’ [-fpermissive]
                 FAST(_img, keypoints, threshold, nonmax_suppression, type);
                                                                          ^
In file included from opencv_3.4./opencv_contrib/modules/xfeatures2d/include/opencv2/xfeatures2d.hpp:42:0,
                 from opencv_3.4./opencv_contrib/modules/xfeatures2d/src/fast.cpp:5:
opencv_3.4./modules/features2d/include/opencv2/features2d.hpp:499:17: note:   initializing argument 5 of ‘void cv::FAST(cv::InputArray, std::vector<cv::KeyPoint>&, int, bool, cv::FastFeatureDetector::DetectorType)’
 CV_EXPORTS void FAST( InputArray image, CV_OUT std::vector<KeyPoint>& keypoints,
                 ^~~~
modules/xfeatures2d/CMakeFiles/opencv_xfeatures2d.dir/build.make:187: recipe for target 'modules/xfeatures2d/CMakeFiles/opencv_xfeatures2d.dir/src/fast.cpp.o' failed
make[2]: *** [modules/xfeatures2d/CMakeFiles/opencv_xfeatures2d.dir/src/fast.cpp.o] Error 1
make[2]: *** Waiting for unfinished jobs....

modules/features2d/include/opencv2/features2d.hpp:499:17: note: initializing argument 5 of ‘void cv::FAST(cv::InputArray, std::vector&, int, bool, cv::FastFeatureDetector::DetectorType)

There is no line with such content in OpenCV 3.4.
Your line is from "master" branch.

git checkout 3.4 or git checkout upstream/3.4 in opencv-3.4 dir may help.

Sorry I forgot to check out 3.4.
It compiles now, and I've tested the C++ code (not the python wrapper).
I am however a bit confused, because I've seen the contribution docs of text detection under opencv 4.1.
Don't get me wrong, I am not complaining (I tried the C++ code) just wondering what's the case with newer OpenCV versions?

Bug fixes are pushed onto lowest applicable maintenable version first. After that bug fixes are merged into latest versions (#2315 is targeted onto 3.4 branch, #2317 is merging onto master/4.x).
Current policy: https://github.com/opencv/opencv/wiki/Branches

Excuse me, have you solved the problem?

@1996leo yes, alalek's latest commit fixed it

Was this page helpful?
0 / 5 - 0 ratings