Lakshmi Narayanan
Lakshmi Narayanan

Reputation: 5342

opencv tesseract undefined reference error

I am trying to test tesseract from opencv 3.0 using the test code from here

However, when I try to compile it, I get the following error

     undefined reference to `cv::text::loadClassifierNM1(std::string const&)'

Any idea how I can fix this? Your help is much appreciated.

UPDATE 1

The complete error is

    CMakeFiles/text_recog.dir/text_recog.o: In function `main':
    text_recog.cpp:(.text+0x37b): undefined reference to `cv::text::loadClassifierNM1(std::string const&)'
    text_recog.cpp:(.text+0x3bb): undefined reference to `cv::text::createERFilterNM1(cv::Ptr<cv::text::ERFilter::Callback> const&, int, float, float, float, bool, float)'
    text_recog.cpp:(.text+0x42b): undefined reference to `cv::text::loadClassifierNM2(std::string const&)'
    text_recog.cpp:(.text+0x44c): undefined reference to `cv::text::createERFilterNM2(cv::Ptr<cv::text::ERFilter::Callback> const&, float)'
    text_recog.cpp:(.text+0x9c1): undefined reference to `cv::text::erGrouping(cv::_InputArray const&, cv::_InputArray const&, std::vector<std::vector<cv::text::ERStat, std::allocator<cv::text::ERStat> >, std::allocator<std::vector<cv::text::ERStat, std::allocator<cv::text::ERStat> > > >&, std::vector<std::vector<cv::Vec<int, 2>, std::allocator<cv::Vec<int, 2> > >, std::allocator<std::vector<cv::Vec<int, 2>, std::allocator<cv::Vec<int, 2> > > > >&, std::vector<cv::Rect_<int>, std::allocator<cv::Rect_<int> > >&, int, std::string const&, float)'
    text_recog.cpp:(.text+0xa95): undefined reference to `cv::text::OCRTesseract::create(char const*, char const*, char const*, int, int)'
    collect2: error: ld returned 1 exit status
    make[2]: *** [text_recog] Error 1
    make[1]: *** [CMakeFiles/text_recog.dir/all] Error 2
    make: *** [all] Error 2

Does this help ?

Upvotes: 0

Views: 1238

Answers (2)

Baltazor
Baltazor

Reputation: 13

You should use library -lopencv_text

LIBS += -lopencv_text

OR

g++ -o output input.cpp -lopencv_text

Upvotes: 0

a_pradhan
a_pradhan

Reputation: 3295

It is a linker error. Look at an existing answer here

You need to compile it as g++ -o output input.cpp pkg-config opencv --cflags --libs if you are on Linux.

However if you have compiled OpenCV from source on Linux, use ldconfig to avoid linking issues.

Upvotes: 1

Related Questions