环境搭建
安装依赖环境
sudo apt install libgtk2.0-dev sudo apt install pkg-config
源码编译
- 下载opencv源码
git clone https://github.com/opencv/opencv.git git clone https://github.com/opencv/opencv_contrib.git
- opencv代码目录创建build文件夹,进入build文件夹
- cmake编译配置
cmake ../ -D CMAKE_BUILD_TYPE=RELEASE \ -D CMAKE_INSTALL_PREFIX=/usr/local \ -D INSTALL_PYTHON_EXAMPLES=ON \ -D WITH_GSTREAMER=ON \ -D WITH_GSTREAMER_0_10=OFF \ -D OPENCV_GENERATE_PKGCONFIG=ON \ -D OPENCV_EXTRA_MODULES_PATH=/opencv_git/opencv_contrib/modules \ -D PYTHON_NUMPY_INCLUDE_DIRS=/usr/local/lib/python3.8/dist-packages/numpy/core/include/ \ -D BUILD_EXAMPLES=ON
- 说明
WITH_GSTREAMER打开,WITH_GSTREAMER_0_10关闭,配置gstreamer使能
OPENCV_EXTRA_MODULES_PATH需要用绝对路径 - 编译安装
make -j 8 sudo make install
- 修改环境变量
gedit ~/.bashrc export PYTHONPATH=/usr/local/lib/python3.8/site-packages:$PYTHONPATH source ~/.bashrc