-
Notifications
You must be signed in to change notification settings - Fork 350
/
install_opencv_python.sh
executable file
·79 lines (63 loc) · 2.99 KB
/
install_opencv_python.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/usr/bin/env bash
# Author: Luigi Freda
#set -e
# ====================================================
# import the utils
. bash_utils.sh
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
STARTING_DIR=`pwd` # this should be the main folder directory of the repo
# ====================================================
print_blue '================================================'
print_blue "Installing opencv-python from source"
print_blue '================================================'
PYTHON_VERSION=$(python -c "import sys; print(f\"{sys.version_info.major}.{sys.version_info.minor}\")")
#pip install --upgrade pip
pip uninstall -y opencv-python
pip uninstall -y opencv-contrib-python
pip install --upgrade numpy
cd thirdparty
if [ ! -d opencv-python ]; then
git clone --recursive https://github.com/opencv/opencv-python.git
cd opencv-python
# This procedure worked on commit cce7c994d46406205eb39300bb7ca9c48d80185a that corresponds to opencv 4.10.0.84 -> https://github.com/opencv/opencv-python/releases/tag/84
git checkout cce7c994d46406205eb39300bb7ca9c48d80185a # uncomment this if you get some issues in building opencv_python!
cd ..
fi
cd opencv-python
MY_OPENCV_PYTHON_PATH=`pwd`
export MAKEFLAGS="-j$(nproc)"
export CPPFLAGS+=""
export CPATH+=""
export CPP_INCLUDE_PATH+=""
export C_INCLUDE_PATH+=""
if [ -z $USING_CONDA_PYSLAM ]; then
PYSLAM_VENV_PATH=$HOME/.python/venvs/pyslam
CPPFLAGS="-I$PYSLAM_VENV_PATH/lib/python$PYTHON_VERSION/site-packages/numpy/core/include/:$CPPFLAGS"
CPATH="$PYSLAM_VENV_PATH/lib/python$PYTHON_VERSION/site-packages/numpy/core/include/":$CPATH
C_INCLUDE_PATH="$PYSLAM_VENV_PATH/lib/python$PYTHON_VERSION/site-packages/numpy/core/include/":$C_INCLUDE_PATH
CPP_INCLUDE_PATH="$PYSLAM_VENV_PATH/lib/python$PYTHON_VERSION/site-packages/numpy/core/include/":$CPP_INCLUDE_PATH
else
echo "Using conda pyslam..."
# we want to use conda environment
CONDA_BASE_FOLDER="$(conda info --base)"
CPPFLAGS="-I$CONDA_BASE_FOLDER/envs/pyslam/lib/python$PYTHON_VERSION/site-packages/numpy/core/include/:$CPPFLAGS"
CPATH="$CONDA_BASE_FOLDER/envs/pyslam/lib/python$PYTHON_VERSION/site-packages/numpy/core/include/":$CPATH
C_INCLUDE_PATH="$CONDA_BASE_FOLDER/envs/pyslam/lib/python$PYTHON_VERSION/site-packages/numpy/core/include/":$C_INCLUDE_PATH
CPP_INCLUDE_PATH="$CONDA_BASE_FOLDER/envs/pyslam/lib/python$PYTHON_VERSION/site-packages/numpy/core/include/":$CPP_INCLUDE_PATH
fi
export CMAKE_ARGS="-DOPENCV_ENABLE_NONFREE=ON \
-DOPENCV_EXTRA_MODULES_PATH=$MY_OPENCV_PYTHON_PATH/opencv_contrib/modules \
-DBUILD_SHARED_LIBS=OFF \
-DBUILD_TESTS=OFF -DBUILD_PERF_TESTS=OFF -DBUILD_EXAMPLES=OFF \
-DCMAKE_CXX_FLAGS=$CPPFLAGS
$MY_OPENCV_PYTHON_PATH"
# build opencv_python
pip wheel . --verbose
# install built packages
pip install opencv*.whl --force-reinstall
# build opencv_contrib_python
export ENABLE_CONTRIB=1
pip wheel . --verbose
# install built packages
pip install opencv*.whl --force-reinstall
cd $STARTING_DIR