opencv tesseract undefined reference error

时间:2015-05-20 19:36:23

标签: c++ opencv tesseract opencv3.0

我正在尝试使用here中的测试代码测试opencv 3.0中的tesseract

但是,当我尝试编译它时,我收到以下错误

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

知道如何解决这个问题吗?非常感谢您的帮助。

更新1

完整的错误是

    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

这有帮助吗?

2 个答案:

答案 0 :(得分:1)

这是链接器错误。查看现有答案here

如果您使用的是Linux,则需要将其编译为g++ -o output input.cpp pkg-config opencv --cflags --libs

但是,如果您已在Linux上从源代码编译OpenCV,请使用ldconfig以避免链接问题。

答案 1 :(得分:0)

您应该使用库-lopencv_text

LIBS += -lopencv_text

OR

g++ -o output input.cpp -lopencv_text