【问题标题】:CMake for Tesseract and OpenCV用于 Tesseract 和 OpenCV 的 CMake
【发布时间】:2013-12-04 17:59:54
【问题描述】:

我是 Linux 编程新手,我正在尝试使用 TesseractOpenCVUbuntu 12.10 上创建 OCR 应用程序。到目前为止,我已经在 linux 上设置了 tesseractOpenCV,我也遵循了这个 tutorial,在本教程中,我发现创建一个文件 CMakeList.txt 并在其中链接 OpenCV 非常容易。

现在我正在尝试用this code 编译tesseract-ocr 库。据我所知,我没有在tesseract-ocr 和我的代码之间建立链接,这就是我遇到错误的原因。

我想要和搜索的只是我是否可以在一个文件中使用CMake 链接TesseractOpenCV,如果可能的话。一个教程会很好,因为我对 Linux 完全陌生。提前致谢

【问题讨论】:

    标签: c++ linux opencv cmake tesseract


    【解决方案1】:

    我写了一个像这样的CMakeLists.txt

    cmake_minimum_required (VERSION 2.6)
    project (test-ocr)
    
    # Add the including directory of the tesseract 
    # and please replace with your dir.
    include_directories (/home/ytxie/include)
    # Add the search directory for the tesseract library 
    # and please replace with your dir.
    link_directories (/home/ytxie/lib)
    
    add_executable (test-ocr test.cpp)
    
    # link the leptonica library and the tesseract library
    target_link_libraries (test-ocr lept tesseract)
    

    我已经添加了 cmets,它似乎很容易理解。 test.cpp 就是that example code

    如果你想将 OpenCV 相关设置添加到这个 cmake 文件中,只需添加它们。如果有一些令人困惑的事情,请阅读CMake's document

    注意:要使 test-ocr 成功运行,您应该下载 English data 并将其内容复制到 /share/tessdata

    【讨论】:

    • 感谢您的回答,我有两个问题。我是否需要为 "tesseract" 和 "lept" 包含和链接目录?我正在尝试使用命令pkg-config --cflags tesseractpkg-config --cflags lept 查找库,它给我带来了错误。我不知道这些库到底在哪里,因为我已经安装了很多次了
    • @MuhammadMaaz ldconfig 定义了链接搜索目录,您可以谷歌它以查找更多信息。在我的计算机中,lept 安装在 ldconfig 定义的搜索集中的 /usr/lib 上,所以我没有添加它具体来说。但是我在我的主目录中安装了 tesseract,它不在上面提到的搜索集中,我必须告诉 CMake 如何找到这个库。
    • @MuhammadMaaz 对不起,我不知道为什么 pkg-config --cflags lept 返回错误。 pkg-config 通过在 /usr/lib/pkgconfig/ 等目录中找到它对应的 pc 文件来查找库的信息usr/local/lib/pkgconfig 等。但我不知道为什么没有 liblept.pc 文件。
    猜你喜欢
    • 2023-03-16
    • 2018-12-02
    • 2014-04-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多