OpenCV  3.4.1
Open Source Computer Vision
Tesseract (master) installation by using git-bash (version>=2.14.1) and cmake (version >=3.9.1)
  1. We assume you installed opencv and opencv_contrib in c:/lib using [this tutorials](http://docs.opencv.org/master/d3/d52/tutorial_windows_install.html#tutorial_windows_gitbash_build]
  2. You must download png lib and zlib. Uncompress lpngx.y.zz in folder lpng and zlib in folder zlib. lpng and zlib must be in same folder as opencv and opencv_contrib. save this script with name installpngzlib.sh in c:/lib
    1 #!/bin/bash
    2 myRepo=$(pwd)
    3 CMAKE_CONFIG_GENERATOR="Visual Studio 14 2015 Win64"
    4 RepoSource=zlib
    5 mkdir Build/$RepoSource
    6 pushd Build/$RepoSource
    7 cmake . -G"Visual Studio 14 2015 Win64" \
    8 -DCMAKE_INSTALL_PREFIX:PATH="$myRepo"/install/zlib -DINSTALL_BIN_DIR:PATH="$myRepo"/install/zlib/bin \
    9 -DINSTALL_INC_DIR:PATH="$myRepo"/install/zlib/include -DINSTALL_LIB_DIR:PATH="$myRepo"/install/zlib/lib "$myRepo"/"$RepoSource"
    10 cmake --build . --config release
    11 cmake --build . --target install --config release
    12 cmake --build . --config debug
    13 cmake --build . --target install --config debug
    14 popd
    15 RepoSource=lpng
    16 mkdir Build/$RepoSource
    17 pushd Build/$RepoSource
    18 cp "$myRepo"/"$RepoSource"/scripts/pnglibconf.h.prebuilt "$myRepo"/"$RepoSource"/pnglibconf.h
    19 cmake . -G"Visual Studio 14 2015 Win64" \
    20 -DZLIB_INCLUDE_DIR:PATH="$myRepo"/install/zlib/include -DZLIB_LIBRARY_DEBUG:FILE="$myRepo"/install/zlib/lib/zlibstaticd.lib \
    21 -Dld-version-script:BOOL=OFF -DPNG_TESTS:BOOL=OFF -DAWK:STRING= \
    22 -DZLIB_LIBRARY_RELEASE:FILE="$myRepo"/install/zlib/lib/zlibstatic.lib -DCMAKE_INSTALL_PREFIX="$myRepo"/Install/"$RepoSource" \
    23 "$myRepo"/"$RepoSource"
    24 cmake --build . --config release
    25 cmake --build . --target install --config release
    26 cmake --build . --config debug
    27 cmake --build . --target install --config debug
    28 popd
  3. In git command line enter the following command :
    1 ./installpngzlib.sh
  4. save this script with name installTesseract.sh in c:/lib
    1 #!/bin/bash
    2 function MAJGitRepo
    3 {
    4 if [ ! -d "$myRepo/$1" ]; then
    5  echo "clonning ${1}"
    6  git clone $2
    7  mkdir Build/$1
    8 else
    9  echo "update $1"
    10  cd $1
    11  git pull --rebase
    12  cd ..
    13 fi
    14 }
    15 echo "Installing leptonica and tesseract"
    16 myRepo=$(pwd)
    17 CMAKE_CONFIG_GENERATOR="Visual Studio 14 2015 Win64"
    18 
    19 MAJGitRepo leptonica https://github.com/DanBloomberg/leptonica.git
    20 RepoSource=leptonica
    21 pushd Build/$RepoSource
    22 cmake -G"$CMAKE_CONFIG_GENERATOR" -DCMAKE_INSTALL_PREFIX="$myRepo"/Install/leptonica "$myRepo/$RepoSource"
    23 echo "************************* $Source_DIR -->debug"
    24 cmake --build . --config release
    25 cmake --build $RepoSource --target install --config release
    26 popd
    27 
    28 RepoSource=tesseract
    29 MAJGitRepo $RepoSource https://github.com/tesseract-ocr/tesseract.git
    30 pushd Build/$RepoSource
    31 cmake -G"$CMAKE_CONFIG_GENERATOR" -DBUILD_TRAINING_TOOLS:BOOL=OFF -DCMAKE_INSTALL_PREFIX="$myRepo"/Install/tesseract -DLeptonica_DIR:PATH="$myRepo"/Install/leptonica/cmake -DPKG_CONFIG_EXECUTABLE:BOOL=OFF "$myRepo"/"$RepoSource"
    32 echo "************************* $Source_DIR -->release"
    33 cmake --build . --config release
    34 cmake --build . --target install --config release
    35 
    36 popd
    37 RepoSource=opencv
    38 pushd Build/$RepoSource
    39 CMAKE_OPTIONS='-DBUILD_PERF_TESTS:BOOL=OFF -DBUILD_TESTS:BOOL=OFF -DBUILD_DOCS:BOOL=OFF -DWITH_CUDA:BOOL=OFF'
    40 cmake -G"$CMAKE_CONFIG_GENERATOR" \
    41 -DTesseract_INCLUDE_DIR:PATH="${myRepo}"/Install/tesseract/include -DTesseract_LIBRARY="${myRepo}"/Install/tesseract/lib/tesseract400.lib -DLept_LIBRARY="${myRepo}"/Install/leptonica/lib/leptonica-1.74.4.lib \
    42 $CMAKE_OPTIONS -DOPENCV_EXTRA_MODULES_PATH=../../opencv_contrib/modules \
    43 -DINSTALL_CREATE_DISTRIB=ON -DCMAKE_INSTALL_PREFIX="$myRepo"/install/"$RepoSource" "$myRepo/$RepoSource"
    44 echo "************************* $Source_DIR -->devenv debug"
    45 cmake --build . --config debug
    46 echo "************************* $Source_DIR -->devenv release"
    47 cmake --build . --config release
    48 cmake --build . --target install --config release
    49 cmake --build . --target install --config debug
    50 popd
    In this script I suppose you use VS 2015 in 64 bits
    1 CMAKE_CONFIG_GENERATOR="Visual Studio 14 2015 Win64"
    and leptonica, tesseract will be installed in c:/lib/install
    1 -DCMAKE_INSTALL_PREFIX="$myRepo"/install/"$RepoSource" "$myRepo/$RepoSource"
    with no Perf tests, no tests, no doc, no CUDA and no example
    1 CMAKE_OPTIONS='-DBUILD_PERF_TESTS:BOOL=OFF -DBUILD_TESTS:BOOL=OFF -DBUILD_DOCS:BOOL=OFF -DWITH_CUDA:BOOL=OFF -DBUILD_EXAMPLES:BOOL=OFF'
  5. In git command line enter the following command :
    1 ./installTesseract.sh
  6. now we need the language files from tesseract. either clone https://github.com/tesseract-ocr/tessdata, or copy only those language files you need to a folder (example c:\lib\install\tesseract\tessdata). If you don't want to add a new folder you must copy language file in same folder than your executable
  7. if you created a new folder, then you must add a new variable, TESSDATA_PREFIX with the value c:\lib\install\tessdata to your system's environment
  8. add c:\Lib\install\leptonica\bin and c:\Lib\install\tesseract\bin to your PATH environment. If you don't want to modify the PATH then copy tesseract400.dll and leptonica-1.74.4.dll to the same folder than your exe file.