OPENCV_VER="master"
TMPDIR=$(mktemp -d) #可更换为mkdir XXX
# Build and install OpenCV from source.
cd "${TMPDIR}" #cd XXX
git clone --branch ${OPENCV_VER} --depth 1 --recurse-submodules --shallow-submodules https://github.com/opencv/opencv-python.git opencv-python-${OPENCV_VER}
cd opencv-python-${OPENCV_VER}
export ENABLE_CONTRIB=0
export ENABLE_HEADLESS=1
# We want GStreamer support enabled.
export CMAKE_ARGS="-DWITH_GSTREAMER=ON"
python3 -m pip wheel . --verbose
# Install OpenCV
python3 -m pip install opencv_python*.whl
注意:一定要使用git,否则在编译的时候会出现一些问题,注意科学上网
对应链接:https://github.com/opencv/opencv-python/issues/530