【问题标题】:opencv tesseract undefined reference erroropencv tesseract 未定义的引用错误
【发布时间】:2015-05-20 19:36:22
【问题描述】:

我正在尝试使用来自 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

这有帮助吗?

【问题讨论】:

  • 发布完整的错误跟踪。
  • 请检查更新@rayryeng​​span>

标签: c++ opencv tesseract opencv3.0


【解决方案1】:

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

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

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

【讨论】:

  • 这个错误略有不同,因为它是 opencv_contrib 的链接问题。如果我错了,请纠正我。我包含了额外的模块,然后重新编译。但是,额外模块的头文件没有添加到我手动添加的“/usr/include”或“/usr/local/include”中。编译说明请查看opencv3.0的opencv_contrib。
  • 从源代码编译库后,使用sudo ldconfig,然后发出g++命令进行编译。
【解决方案2】:

你应该使用库 -lopencv_text

LIBS += -lopencv_text

g++ -o output input.cpp -lopencv_text

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-04-23
    • 1970-01-01
    • 2015-01-30
    • 1970-01-01
    • 2014-09-22
    • 1970-01-01
    • 2015-12-08
    相关资源
    最近更新 更多