diff --git a/modules/text/CMakeLists.txt b/modules/text/CMakeLists.txt index 173e87f06..39e4d8c84 100644 --- a/modules/text/CMakeLists.txt +++ b/modules/text/CMakeLists.txt @@ -1,25 +1,20 @@ set(the_description "Text Detection and Recognition") -ocv_define_module(text opencv_ml opencv_highgui opencv_imgproc opencv_core opencv_features2d WRAP python) +ocv_define_module(text opencv_ml opencv_imgproc opencv_core opencv_features2d OPTIONAL opencv_highgui WRAP python) -set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}) - -find_package(Tesseract) -if(Tesseract_FOUND) +if(NOT CMAKE_CROSSCOMPILING OR OPENCV_FIND_TESSERACT) + set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake) + find_package(Tesseract QUIET) + if(Tesseract_FOUND) message(STATUS "Tesseract: YES") set(HAVE_TESSERACT 1) -else() + ocv_include_directories(${Tesseract_INCLUDE_DIR}) + ocv_target_link_libraries(${the_module} ${Tesseract_LIBRARIES}) + else() message(STATUS "Tesseract: NO") + endif() endif() configure_file(${CMAKE_CURRENT_SOURCE_DIR}/text_config.hpp.in ${CMAKE_BINARY_DIR}/text_config.hpp @ONLY) -include_directories(${CMAKE_CURRENT_BINARY_DIR}) - -if(${Tesseract_FOUND}) -include_directories(${Tesseract_INCLUDE_DIR}) -endif() - -if(${Tesseract_FOUND}) - target_link_libraries(opencv_text ${Tesseract_LIBS}) -endif() +ocv_include_directories(${CMAKE_CURRENT_BINARY_DIR}) diff --git a/modules/text/FindTesseract.cmake b/modules/text/FindTesseract.cmake deleted file mode 100644 index 54c4a4929..000000000 --- a/modules/text/FindTesseract.cmake +++ /dev/null @@ -1,24 +0,0 @@ -# Tesseract OCR -unset(Tesseract_FOUND) - -find_path(Tesseract_INCLUDE_DIR tesseract/baseapi.h - HINTS - /usr/include - /usr/local/include) - -find_library(Tesseract_LIBRARY NAMES tesseract - HINTS - /usr/lib - /usr/local/lib) - -find_library(Lept_LIBRARY NAMES lept - HINTS - /usr/lib - /usr/local/lib) - -set(Tesseract_LIBS ${Tesseract_LIBRARY} ${Lept_LIBRARY}) -if(Tesseract_LIBS AND Tesseract_INCLUDE_DIR) - set(Tesseract_FOUND 1) -endif() - - diff --git a/modules/text/cmake/FindTesseract.cmake b/modules/text/cmake/FindTesseract.cmake new file mode 100644 index 000000000..2a5d868f9 --- /dev/null +++ b/modules/text/cmake/FindTesseract.cmake @@ -0,0 +1,23 @@ +# Tesseract OCR +if(COMMAND pkg_check_modules) + pkg_check_modules(Tesseract tesseract lept) +endif() +if(NOT Tesseract_FOUND) + find_path(Tesseract_INCLUDE_DIR tesseract/baseapi.h + HINTS + /usr/local/include) + + find_library(Tesseract_LIBRARY NAMES tesseract + HINTS + /usr/local/lib) + + find_library(Lept_LIBRARY NAMES lept + HINTS + /usr/local/lib) + + if(Tesseract_INCLUDE_DIR AND Tesseract_LIBRARY AND Lept_LIBRARY) + set(Tesseract_INCLUDE_DIRS ${Tesseract_INCLUDE_DIR}) + set(Tesseract_LIBRARIES ${Tesseract_LIBRARY} ${Lept_LIBRARY}) + set(Tesseract_FOUND 1) + endif() +endif()