Ubuntu18源码编译OpenCV4.3
参考资料
过程
- 首先更新包
# Install the newest versions of all packages currently installed
sudo apt-get -y upgrade
# Handles changing dependencies with new versions of packages
sudo apt-get -y dist-upgrade
# Remove packages that are now no longer needed
sudo apt-get -y autoremove
- 安装OpenCV所需依赖
# Build tools:
sudo apt-get install -y build-essential cmake
# GUI (if you want to use GTK instead of Qt, replace 'qt5-default' with 'libgtkglext1-dev' and remove '-DWITH_QT=ON' option in CMake):
sudo apt-get install -y qt5-default libvtk6-dev
# Media I/O:
sudo apt-get install -y zlib1g-dev libjpeg-dev libwebp-dev libpng-dev libtiff5-dev libjasper-dev libopenexr-dev libgdal-dev
# Video I/O:
sudo apt-get install -y libdc1394-22-dev libavcodec-dev libavformat-dev libswscale-dev libtheora-dev libvorbis-dev libxvidcore-dev libx264-dev yasm libopencore-amrnb-dev libopencore-amrwb-dev libv4l-dev libxine2-dev
# Parallelism and linear algebra libraries:
sudo apt-get install -y libtbb-dev libeigen3-dev
# Python:
sudo apt-get install -y python-dev python-tk python-numpy python3-dev python3-tk python3-numpy
# Java:
sudo apt-get install -y ant default-jdk
# Documentation:
sudo apt-get install -y doxygen
- 安装过程
mkdir build & cd build
sudo cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local -D WITH_TBB=ON -D WITH_EIGEN=ON ..
sudo make # compile
sudo make install # install
sudo ldconfig # load config
错误及解决
make过程中报错,查资料后发现是虚拟机的虚拟内存过小,关机后重新调整即可。
c++: internal compiler error: Killed (program cc1plus)
- 检查是否成功安装OpenCV库
在/samples/cpp/example_cmake
下有个工程,编译后,如果成功运行并且显示"Hello OpenCV",则安装成功
且在/usr/local/includes/
下有opencv4的库
最后还有个多版本的问题,查资料后,看到网上很多多版本并存的解决方案,先这样,有空再试。