作者:大姑娘不再回_402 | 来源:互联网 | 2023-08-06 15:03
相关依赖库的安装:aptinstallpython-pippython3-pippip2installnumpy pip3installnumpy【上面两步可以apt安装更快apt
相关依赖库的安装:
apt install python-pip python3-pip
pip2 install numpy
pip3 install numpy 【上面两步可以apt安装更快 apt install python-numpy python3-numpy】
apt-get install libpython2.7-dev libpython3.5-dev
apt-get install libgtk2.0-dev (GTK+)
(可选先编译安装 ffmpeg-3.4.2, 这是一定要安装pkg-config)
【apt-get install libavcodec-dev libavformat-dev libswscale-dev libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc1394-22-dev】
OpenCV 3.4编译:
x86_64版:
cmake -D CMAKE_BUILD_TYPE=RELEASE \
-D INSTALL_C_EXAMPLES=OFF \
-D INSTALL_PYTHON_EXAMPLES=ON \
-D BUILD_EXAMPLES=OFF \
-DENABLE_CXX11=ON \
-D BUILD_opencv_python3=ON \
-D BUILD_opencv_python2=ON \
-D BUILD_opencv_java=OFF \
-D PYTHON3_EXECUTABLE=$(which python3)\
-D PYTHON3_INCLUDE_DIR=/usr/include/python3.5m \
-D PYTHON3_LIBRARY=/usr/lib/x86_64-linux-gnu/libpython3.5m.so.1 \
-D PYTHON3_NUMPY_PATH=/usr/local/lib/python3.5/dist-packages \
-D PYTHON2_EXECUTABLE=$(which python2)\
-D PYTHON2_INCLUDE_DIR=/usr/include/python2.7 \
-D PYTHON2_LIBRARY=/usr/lib/x86_64-linux-gnu/libpython2.7.so.1 \
-D PYTHON2_NUMPY_PATH=/usr/local/lib/python2.7/dist-packages ..
ARM版:
cmake -D CMAKE_BUILD_TYPE=RELEASE \
-D INSTALL_C_EXAMPLES=OFF \
-D ENABLE_NEON=ON \
-D ENABLE_VFPV3=ON \
-D ENABLE_CXX11=ON \
-D INSTALL_PYTHON_EXAMPLES=ON \
-D BUILD_EXAMPLES=OFF \
-D BUILD_opencv_python3=ON \
-D BUILD_opencv_python2=ON \
-D BUILD_opencv_java=OFF \
-D PYTHON3_EXECUTABLE=$(which python3)\
-D PYTHON3_INCLUDE_DIR=/usr/include/python3.5m \
-D PYTHON3_LIBRARY=/usr/lib/arm-linux-gnueabihf/libpython3.5m.so.1 \
-D PYTHON3_NUMPY_PATH=/usr/lib/python3/dist-packages \
-D PYTHON2_EXECUTABLE=$(which python2)\
-D PYTHON2_INCLUDE_DIR=/usr/include/python2.7 \
-D PYTHON2_LIBRARY=/usr/lib/arm-linux-gnueabihf/libpython2.7.so.1 \
-D WITH_LIBV4L=ON \
-D PYTHON2_NUMPY_PATH=/usr/lib/python2.7/dist-packages ..
ARM64版:
cmake -D CMAKE_BUILD_TYPE=RELEASE \
-D INSTALL_C_EXAMPLES=OFF \
-D ENABLE_CXX11=ON \
-D INSTALL_PYTHON_EXAMPLES=OFF \
-D BUILD_EXAMPLES=OFF \
-D BUILD_opencv_python3=ON \
-D BUILD_opencv_python2=ON \
-D BUILD_opencv_java=OFF \
-D PYTHON3_EXECUTABLE=$(which python3)\
-D PYTHON3_INCLUDE_DIR=/usr/include/python3.5m \
-D PYTHON3_LIBRARY=/usr/lib/aarch64-linux-gnu/libpython3.5m.so.1 \
-D PYTHON3_NUMPY_PATH=/usr/lib/python3/dist-packages \
-D PYTHON2_EXECUTABLE=$(which python2)\
-D PYTHON2_INCLUDE_DIR=/usr/include/python2.7 \
-D PYTHON2_LIBRARY=/usr/lib/aarch64-linux-gnu/libpython2.7.so.1 \
-D WITH_LIBV4L=ON \
-D PYTHON2_NUMPY_PATH=/usr/lib/python2.7/dist-packages ..
最后make install
安装后验证:
python
root@houxn-OptiPlex-7040:#python
Python 2.7.12 (default, Dec 4 2017, 14:50:18)
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
>>> cv2.__version__
'3.4.0'
root@houxn-OptiPlex-7040:#python3
Python 3.5.2 (default, Nov 23 2017, 16:37:01)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
>>> cv2.__version__
'3.4.0'
C++
g++ 时最后需要添加 `pkg-config opencv –cflags –libs`