Skip to content

Instantly share code, notes, and snippets.

@axtstar
Last active October 23, 2021 09:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save axtstar/0f7628b05f403291e6079140587258a9 to your computer and use it in GitHub Desktop.
Save axtstar/0f7628b05f403291e6079140587258a9 to your computer and use it in GitHub Desktop.
opencv_contribのビルド shではなくbashでビルド
#move to paticular folder...
#Tesseractに必要なライブラリの導入
if [[ $(uname -a) = *"Ubuntu"* ]]; then
#Ubuntuの場合
sudo apt-get install libleptonica-dev
sudo apt install libpango1.0-dev
elif [[ $(uname -a) = *"Linux"* ]]; then
#WSLの場合
sudo apt-get install libleptonica-dev
sudo apt install libpango1.0-dev
else
#macの場合
brew install cmake
brew install leptonica
fi
#tesseract opencv opencv-contrib の階層は同じとする
git clone https://github.com/tesseract-ocr/tesseract.git
git clone --depth 1 https://github.com/opencv/opencv
git clone --depth 1 https://github.com/opencv/opencv_contrib.git
#tesseractのビルド・インストール
cd tesseract
git checkout tags/4.0.0
mkdir build
cd build
cmake ..
make -j4
sudo make install
#pythonラッパーインストール
pip3 install pytesseract
#元のディレクトリに戻る
cd ../../
#opencv + contribのビルド・インストール
cd opencv
mkdir build
cd build
#cmake
cmake -D BUILD_TIFF=ON \
-D BUILD_opencv_java=ON \
-D WITH_CUDA=OFF \
-D WITH_OPENGL=ON \
-D WITH_OPENCL=ON \
-D WITH_IPP=ON \
-D WITH_TBB=ON \
-D WITH_EIGEN=ON \
-D WITH_V4L=ON \
-D WITH_VTK=OFF \
-D CXXFLAGS=-std=c++14 \
-D CMAKE_CXX_FLAGS=-std=c++14 \
-D BUILD_TESTS=OFF \
-D BUILD_PERF_TESTS=OFF \
-D BUILD_NEW_PYTHON_SUPPORT=ON \
-D CMAKE_BUILD_TYPE=RELEASE \
-D BUILD_opencv_python2=OFF \
-D CMAKE_INSTALL_PREFIX=$(python3 -c "import sys; print(sys.prefix)") \
-D PYTHON3_EXECUTABLE=$(which python3) \
-D PYTHON3_INCLUDE_DIR=$(python3 -c "from distutils.sysconfig import get_python_inc; print(get_python_inc())") \
-D PYTHON3_LIBRARY=$(python -c "import site; print(site.getsitepackages()[0])") \
-D PYTHON3_PACKAGES_PATH=$(python3 -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())") \
-D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib/modules \
-D ENABLE_PRECOMPILED_HEADERS=OFF \
-D Tesseract_INCLUDE_DIR=../../tesseract/include \
-D Tesseract_LIBRARY=../../tesseract/lib ..
make -j4
sudo make install
#pythonラッパーインストール
pip3 install opencv-python
#pythonラッパーインストール
pip3 install opencv-contrib-python
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment