mirror of
https://github.com/kerberos-io/openalpr-base.git
synced 2025-10-08 04:50:06 +08:00
Simplifying build process for Windows.
Added cmake find script for Tesseract.
This commit is contained in:
@@ -13,36 +13,17 @@ add_definitions( -DOPENALPR_MAJOR_VERSION=${OPENALPR_MAJOR_VERSION})
|
|||||||
add_definitions( -DOPENALPR_MINOR_VERSION=${OPENALPR_MINOR_VERSION})
|
add_definitions( -DOPENALPR_MINOR_VERSION=${OPENALPR_MINOR_VERSION})
|
||||||
add_definitions( -DOPENALPR_PATCH_VERSION=${OPENALPR_PATCH_VERSION})
|
add_definitions( -DOPENALPR_PATCH_VERSION=${OPENALPR_PATCH_VERSION})
|
||||||
|
|
||||||
|
SET(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake_modules/")
|
||||||
|
|
||||||
SET(OpenCV_DIR "${CMAKE_SOURCE_DIR}/../libraries/opencv/")
|
|
||||||
#SET(Tesseract_DIR "${CMAKE_SOURCE_DIR}/../libraries/tesseract-ocr")
|
|
||||||
|
|
||||||
include_directories(
|
FIND_PACKAGE( Tesseract REQUIRED )
|
||||||
${Tesseract_DIR}/api
|
|
||||||
${Tesseract_DIR}/ccutil/
|
|
||||||
${Tesseract_DIR}/ccstruct/
|
|
||||||
${Tesseract_DIR}/ccmain/
|
|
||||||
)
|
|
||||||
|
|
||||||
IF (WIN32)
|
include_directories(${Tesseract_INCLUDE_DIRS})
|
||||||
add_definitions( -DWINDOWS)
|
|
||||||
add_definitions( -DNOMINMAX)
|
|
||||||
|
|
||||||
link_directories( ${Tesseract_DIR}/lib/ )
|
|
||||||
include_directories(${Tesseract_DIR}/include/ )
|
|
||||||
|
|
||||||
# Extra linker dependencies for Windows
|
|
||||||
SET(Tesseract_LIBS
|
|
||||||
libtesseract303-static
|
|
||||||
liblept170
|
|
||||||
ws2_32.lib)
|
|
||||||
ELSE()
|
|
||||||
|
|
||||||
link_directories( ${Tesseract_DIR}/api/.libs/ )
|
|
||||||
|
|
||||||
SET(Tesseract_LIBS tesseract)
|
|
||||||
ENDIF()
|
|
||||||
|
|
||||||
|
# Discover OpenCV directory automatically
|
||||||
|
find_path(OpenCV_DIR
|
||||||
|
NAMES OpenCVConfig.cmake
|
||||||
|
HINTS ${CMAKE_SOURCE_DIR}/../libraries/opencv/)
|
||||||
|
|
||||||
# Opencv Package
|
# Opencv Package
|
||||||
FIND_PACKAGE( OpenCV REQUIRED )
|
FIND_PACKAGE( OpenCV REQUIRED )
|
||||||
@@ -50,9 +31,20 @@ IF (${OpenCV_VERSION} VERSION_LESS 2.4.8)
|
|||||||
MESSAGE(FATAL_ERROR "OpenCV version is not compatible : ${OpenCV_VERSION}")
|
MESSAGE(FATAL_ERROR "OpenCV version is not compatible : ${OpenCV_VERSION}")
|
||||||
ENDIF()
|
ENDIF()
|
||||||
|
|
||||||
|
|
||||||
include_directories(./openalpr )
|
include_directories(./openalpr )
|
||||||
|
|
||||||
|
IF (WIN32)
|
||||||
|
add_definitions( -DWINDOWS)
|
||||||
|
add_definitions( -DNOMINMAX)
|
||||||
|
|
||||||
|
# Extra linker dependencies for Windows
|
||||||
|
SET (Tesseract_LIBRARIES
|
||||||
|
${Tesseract_LIBRARIES}
|
||||||
|
ws2_32.lib
|
||||||
|
)
|
||||||
|
|
||||||
|
ENDIF()
|
||||||
|
|
||||||
|
|
||||||
set(CMAKE_CSS_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -Wall ")
|
set(CMAKE_CSS_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -Wall ")
|
||||||
ADD_EXECUTABLE( alpr main.cpp )
|
ADD_EXECUTABLE( alpr main.cpp )
|
||||||
@@ -60,9 +52,9 @@ ADD_EXECUTABLE( alpr main.cpp )
|
|||||||
TARGET_LINK_LIBRARIES(alpr
|
TARGET_LINK_LIBRARIES(alpr
|
||||||
openalpr-static
|
openalpr-static
|
||||||
support
|
support
|
||||||
video
|
video
|
||||||
${OpenCV_LIBS}
|
${OpenCV_LIBS}
|
||||||
${Tesseract_LIBS}
|
${Tesseract_LIBRARIES}
|
||||||
)
|
)
|
||||||
|
|
||||||
# Compile the alprd library on Unix-based OS
|
# Compile the alprd library on Unix-based OS
|
||||||
@@ -72,13 +64,16 @@ IF (NOT WIN32)
|
|||||||
TARGET_LINK_LIBRARIES(alprd
|
TARGET_LINK_LIBRARIES(alprd
|
||||||
openalpr
|
openalpr
|
||||||
support
|
support
|
||||||
video
|
video
|
||||||
uuid
|
uuid
|
||||||
curl
|
curl
|
||||||
log4cplus
|
log4cplus
|
||||||
${OpenCV_LIBS}
|
${OpenCV_LIBS}
|
||||||
${Tesseract_LIBS}
|
${Tesseract_LIBRARIES}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Don't include misc utilities for Windows
|
||||||
|
add_subdirectory(misc_utilities)
|
||||||
ENDIF()
|
ENDIF()
|
||||||
|
|
||||||
|
|
||||||
@@ -87,12 +82,6 @@ ENDIF()
|
|||||||
add_subdirectory(openalpr)
|
add_subdirectory(openalpr)
|
||||||
add_subdirectory(video)
|
add_subdirectory(video)
|
||||||
|
|
||||||
IF (NOT WIN32)
|
|
||||||
# Don't include misc utilities for Windows
|
|
||||||
add_subdirectory(misc_utilities)
|
|
||||||
ENDIF()
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
install (TARGETS alpr DESTINATION bin)
|
install (TARGETS alpr DESTINATION bin)
|
||||||
install (FILES ${CMAKE_SOURCE_DIR}/../doc/man/alpr.1 DESTINATION share/man/man1 COMPONENT doc)
|
install (FILES ${CMAKE_SOURCE_DIR}/../doc/man/alpr.1 DESTINATION share/man/man1 COMPONENT doc)
|
||||||
|
72
src/cmake_modules/FindTesseract.cmake
Normal file
72
src/cmake_modules/FindTesseract.cmake
Normal file
@@ -0,0 +1,72 @@
|
|||||||
|
# - Try to find Tesseract-OCR
|
||||||
|
# Once done, this will define
|
||||||
|
#
|
||||||
|
# Tesseract_FOUND - system has Tesseract
|
||||||
|
# Tesseract_INCLUDE_DIRS - the Tesseract include directories
|
||||||
|
# Tesseract_LIBRARIES - link these to use Tesseract
|
||||||
|
|
||||||
|
include(LibFindMacros)
|
||||||
|
|
||||||
|
# Use pkg-config to get hints about paths
|
||||||
|
#libfind_pkg_check_modules(Tesseract_PKGCONF Tesseract)
|
||||||
|
|
||||||
|
# Include dir
|
||||||
|
find_path(Tesseract_INCLUDE_BASEAPI_DIR
|
||||||
|
NAMES tesseract/baseapi.h
|
||||||
|
HINTS "/usr/include"
|
||||||
|
"/usr/local/include"
|
||||||
|
${Tesseract_PKGCONF_INCLUDE_DIRS}
|
||||||
|
${CMAKE_SOURCE_DIR}/../libraries/tesseract-ocr/api/
|
||||||
|
)
|
||||||
|
find_path(Tesseract_INCLUDE_CCSTRUCT_DIR
|
||||||
|
NAMES publictypes.h
|
||||||
|
HINTS "/usr/include"
|
||||||
|
"/usr/local/include"
|
||||||
|
${Tesseract_PKGCONF_INCLUDE_DIRS}
|
||||||
|
${CMAKE_SOURCE_DIR}/../libraries/tesseract-ocr/ccstruct/
|
||||||
|
)
|
||||||
|
find_path(Tesseract_INCLUDE_CCMAIN_DIR
|
||||||
|
NAMES thresholder.h
|
||||||
|
HINTS "/usr/include"
|
||||||
|
"/usr/local/include"
|
||||||
|
${Tesseract_PKGCONF_INCLUDE_DIRS}
|
||||||
|
${CMAKE_SOURCE_DIR}/../libraries/tesseract-ocr/ccmain/
|
||||||
|
)
|
||||||
|
find_path(Tesseract_INCLUDE_CCUTIL_DIR
|
||||||
|
NAMES platform.h
|
||||||
|
HINTS "/usr/include"
|
||||||
|
"/usr/local/include"
|
||||||
|
${Tesseract_PKGCONF_INCLUDE_DIRS}
|
||||||
|
${CMAKE_SOURCE_DIR}/../libraries/tesseract-ocr/ccutil/
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
# Finally the library itself
|
||||||
|
find_library(Tesseract_LIB
|
||||||
|
NAMES tesseract tesseract-static libtesseract303-static
|
||||||
|
HINTS "/usr/lib"
|
||||||
|
"/usr/local/lib"
|
||||||
|
${Tesseract_PKGCONF_LIBRARY_DIRS}
|
||||||
|
${CMAKE_SOURCE_DIR}/../libraries/tesseract-ocr/api/.libs
|
||||||
|
${CMAKE_SOURCE_DIR}/../libraries/tesseract-ocr/vs2010/LIB_Release
|
||||||
|
)
|
||||||
|
|
||||||
|
find_library(Leptonica_LIB
|
||||||
|
NAMES liblept170 liblept
|
||||||
|
HINTS "/usr/lib"
|
||||||
|
"/usr/local/lib"
|
||||||
|
${Tesseract_PKGCONF_LIBRARY_DIRS}
|
||||||
|
${CMAKE_SOURCE_DIR}/../libraries/tesseract-ocr/api/.libs
|
||||||
|
${CMAKE_SOURCE_DIR}/../libraries/tesseract-ocr/vs2010/LIB_Release
|
||||||
|
)
|
||||||
|
|
||||||
|
# Set the include dir variables and the libraries and let libfind_process do the rest.
|
||||||
|
# NOTE: Singular variables for this library, plural for libraries this this lib depends on.
|
||||||
|
set(Tesseract_PROCESS_INCLUDES
|
||||||
|
Tesseract_INCLUDE_BASEAPI_DIR
|
||||||
|
Tesseract_INCLUDE_CCSTRUCT_DIR
|
||||||
|
Tesseract_INCLUDE_CCMAIN_DIR
|
||||||
|
Tesseract_INCLUDE_CCUTIL_DIR
|
||||||
|
Tesseract_INCLUDE_DIRS)
|
||||||
|
set(Tesseract_PROCESS_LIBS Tesseract_LIB Leptonica_LIB Tesseract_LIBRARIES)
|
||||||
|
libfind_process(Tesseract)
|
98
src/cmake_modules/LibFindMacros.cmake
Normal file
98
src/cmake_modules/LibFindMacros.cmake
Normal file
@@ -0,0 +1,98 @@
|
|||||||
|
# Works the same as find_package, but forwards the "REQUIRED" and "QUIET" arguments
|
||||||
|
# used for the current package. For this to work, the first parameter must be the
|
||||||
|
# prefix of the current package, then the prefix of the new package etc, which are
|
||||||
|
# passed to find_package.
|
||||||
|
macro (libfind_package PREFIX)
|
||||||
|
set (LIBFIND_PACKAGE_ARGS ${ARGN})
|
||||||
|
if (${PREFIX}_FIND_QUIETLY)
|
||||||
|
set (LIBFIND_PACKAGE_ARGS ${LIBFIND_PACKAGE_ARGS} QUIET)
|
||||||
|
endif (${PREFIX}_FIND_QUIETLY)
|
||||||
|
if (${PREFIX}_FIND_REQUIRED)
|
||||||
|
set (LIBFIND_PACKAGE_ARGS ${LIBFIND_PACKAGE_ARGS} REQUIRED)
|
||||||
|
endif (${PREFIX}_FIND_REQUIRED)
|
||||||
|
find_package(${LIBFIND_PACKAGE_ARGS})
|
||||||
|
endmacro (libfind_package)
|
||||||
|
|
||||||
|
# CMake developers made the UsePkgConfig system deprecated in the same release (2.6)
|
||||||
|
# where they added pkg_check_modules. Consequently I need to support both in my scripts
|
||||||
|
# to avoid those deprecated warnings. Here's a helper that does just that.
|
||||||
|
# Works identically to pkg_check_modules, except that no checks are needed prior to use.
|
||||||
|
macro (libfind_pkg_check_modules PREFIX PKGNAME)
|
||||||
|
if (${CMAKE_MAJOR_VERSION} EQUAL 2 AND ${CMAKE_MINOR_VERSION} EQUAL 4)
|
||||||
|
include(UsePkgConfig)
|
||||||
|
pkgconfig(${PKGNAME} ${PREFIX}_INCLUDE_DIRS ${PREFIX}_LIBRARY_DIRS ${PREFIX}_LDFLAGS ${PREFIX}_CFLAGS)
|
||||||
|
else (${CMAKE_MAJOR_VERSION} EQUAL 2 AND ${CMAKE_MINOR_VERSION} EQUAL 4)
|
||||||
|
find_package(PkgConfig)
|
||||||
|
if (PKG_CONFIG_FOUND)
|
||||||
|
pkg_check_modules(${PREFIX} ${PKGNAME})
|
||||||
|
endif (PKG_CONFIG_FOUND)
|
||||||
|
endif (${CMAKE_MAJOR_VERSION} EQUAL 2 AND ${CMAKE_MINOR_VERSION} EQUAL 4)
|
||||||
|
endmacro (libfind_pkg_check_modules)
|
||||||
|
|
||||||
|
# Do the final processing once the paths have been detected.
|
||||||
|
# If include dirs are needed, ${PREFIX}_PROCESS_INCLUDES should be set to contain
|
||||||
|
# all the variables, each of which contain one include directory.
|
||||||
|
# Ditto for ${PREFIX}_PROCESS_LIBS and library files.
|
||||||
|
# Will set ${PREFIX}_FOUND, ${PREFIX}_INCLUDE_DIRS and ${PREFIX}_LIBRARIES.
|
||||||
|
# Also handles errors in case library detection was required, etc.
|
||||||
|
macro (libfind_process PREFIX)
|
||||||
|
# Skip processing if already processed during this run
|
||||||
|
if (NOT ${PREFIX}_FOUND)
|
||||||
|
# Start with the assumption that the library was found
|
||||||
|
set (${PREFIX}_FOUND TRUE)
|
||||||
|
|
||||||
|
# Process all includes and set _FOUND to false if any are missing
|
||||||
|
foreach (i ${${PREFIX}_PROCESS_INCLUDES})
|
||||||
|
if (${i})
|
||||||
|
set (${PREFIX}_INCLUDE_DIRS ${${PREFIX}_INCLUDE_DIRS} ${${i}})
|
||||||
|
mark_as_advanced(${i})
|
||||||
|
else (${i})
|
||||||
|
set (${PREFIX}_FOUND FALSE)
|
||||||
|
endif (${i})
|
||||||
|
endforeach (i)
|
||||||
|
|
||||||
|
# Process all libraries and set _FOUND to false if any are missing
|
||||||
|
foreach (i ${${PREFIX}_PROCESS_LIBS})
|
||||||
|
if (${i})
|
||||||
|
set (${PREFIX}_LIBRARIES ${${PREFIX}_LIBRARIES} ${${i}})
|
||||||
|
mark_as_advanced(${i})
|
||||||
|
else (${i})
|
||||||
|
set (${PREFIX}_FOUND FALSE)
|
||||||
|
endif (${i})
|
||||||
|
endforeach (i)
|
||||||
|
|
||||||
|
# Print message and/or exit on fatal error
|
||||||
|
if (${PREFIX}_FOUND)
|
||||||
|
if (NOT ${PREFIX}_FIND_QUIETLY)
|
||||||
|
message (STATUS "Found ${PREFIX} ${${PREFIX}_VERSION}")
|
||||||
|
endif (NOT ${PREFIX}_FIND_QUIETLY)
|
||||||
|
else (${PREFIX}_FOUND)
|
||||||
|
if (${PREFIX}_FIND_REQUIRED)
|
||||||
|
foreach (i ${${PREFIX}_PROCESS_INCLUDES} ${${PREFIX}_PROCESS_LIBS})
|
||||||
|
message("${i}=${${i}}")
|
||||||
|
endforeach (i)
|
||||||
|
message (FATAL_ERROR "Required library ${PREFIX} NOT FOUND.\nInstall the library (dev version) and try again. If the library is already installed, use ccmake to set the missing variables manually.")
|
||||||
|
endif (${PREFIX}_FIND_REQUIRED)
|
||||||
|
endif (${PREFIX}_FOUND)
|
||||||
|
endif (NOT ${PREFIX}_FOUND)
|
||||||
|
endmacro (libfind_process)
|
||||||
|
|
||||||
|
macro(libfind_library PREFIX basename)
|
||||||
|
set(TMP "")
|
||||||
|
if(MSVC80)
|
||||||
|
set(TMP -vc80)
|
||||||
|
endif(MSVC80)
|
||||||
|
if(MSVC90)
|
||||||
|
set(TMP -vc90)
|
||||||
|
endif(MSVC90)
|
||||||
|
set(${PREFIX}_LIBNAMES ${basename}${TMP})
|
||||||
|
if(${ARGC} GREATER 2)
|
||||||
|
set(${PREFIX}_LIBNAMES ${basename}${TMP}-${ARGV2})
|
||||||
|
string(REGEX REPLACE "\\." "_" TMP ${${PREFIX}_LIBNAMES})
|
||||||
|
set(${PREFIX}_LIBNAMES ${${PREFIX}_LIBNAMES} ${TMP})
|
||||||
|
endif(${ARGC} GREATER 2)
|
||||||
|
find_library(${PREFIX}_LIBRARY
|
||||||
|
NAMES ${${PREFIX}_LIBNAMES}
|
||||||
|
PATHS ${${PREFIX}_PKGCONF_LIBRARY_DIRS}
|
||||||
|
)
|
||||||
|
endmacro(libfind_library)
|
@@ -8,7 +8,7 @@ TARGET_LINK_LIBRARIES(sortstate
|
|||||||
openalpr-static
|
openalpr-static
|
||||||
support
|
support
|
||||||
${OpenCV_LIBS}
|
${OpenCV_LIBS}
|
||||||
${Tesseract_LIBS}
|
${Tesseract_LIBRARIES}
|
||||||
)
|
)
|
||||||
|
|
||||||
ADD_EXECUTABLE( classifychars EXCLUDE_FROM_ALL classifychars.cpp )
|
ADD_EXECUTABLE( classifychars EXCLUDE_FROM_ALL classifychars.cpp )
|
||||||
@@ -16,7 +16,7 @@ TARGET_LINK_LIBRARIES(classifychars
|
|||||||
openalpr-static
|
openalpr-static
|
||||||
support
|
support
|
||||||
${OpenCV_LIBS}
|
${OpenCV_LIBS}
|
||||||
${Tesseract_LIBS}
|
${Tesseract_LIBRARIES}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@@ -30,7 +30,7 @@ TARGET_LINK_LIBRARIES(benchmark
|
|||||||
support
|
support
|
||||||
pthread
|
pthread
|
||||||
${OpenCV_LIBS}
|
${OpenCV_LIBS}
|
||||||
${Tesseract_LIBS}
|
${Tesseract_LIBRARIES}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@@ -40,13 +40,12 @@ set_target_properties(openalpr PROPERTIES SOVERSION ${OPENALPR_MAJOR_VERSION})
|
|||||||
TARGET_LINK_LIBRARIES(openalpr
|
TARGET_LINK_LIBRARIES(openalpr
|
||||||
support
|
support
|
||||||
${OpenCV_LIBS}
|
${OpenCV_LIBS}
|
||||||
${Tesseract_LIBS}
|
${Tesseract_LIBRARIES}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
install (FILES alpr.h DESTINATION include)
|
install (FILES alpr.h DESTINATION include)
|
||||||
install (TARGETS openalpr DESTINATION lib)
|
install (TARGETS openalpr DESTINATION lib)
|
||||||
|
|
||||||
# Add definition for default runtime dir
|
# Add definition for default config file
|
||||||
#add_definitions(-DDEFAULT_RUNTIME_DIR="/usr/share/openalpr/runtime_data")
|
|
||||||
add_definitions(-DDEFAULT_CONFIG_FILE="/etc/openalpr/openalpr.conf")
|
add_definitions(-DDEFAULT_CONFIG_FILE="/etc/openalpr/openalpr.conf")
|
||||||
|
Reference in New Issue
Block a user