安装不同版本opencv及共存、切换并验证。

安装不同版本opencv共存

ubuntu18.04安装ROS后自带opencv3.2.0,现在需要更换为3.4.0

sudo apt install build-essential
sudo apt install cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev
sudo apt install python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc1394-22-dev
sudo apt install libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev

错误:E: 无法定位软件包 libjasper-dev
sudo add-apt-repository “deb http://security.ubuntu.com/ubuntu xenial-security main”
sudo apt update
sudo apt install libjasper1 libjasper-dev

  • 查看当前系统默认opencv版本 pkg-config --modversion opencv

  • 下载安装包 wget -q https://github.com/opencv/opencv/archive/3.4.0.zip

  • 安步骤编译,注意安装路径

mkdir build
cd build
cmake -D CMAKE_INSTALL_PREFIX=/usr/local/opencv-3.4.0 -D OPENCV_EXTRA_MODULES_PATH=../opencv_contrib/modules ..
make
sudo make install
  • 打开bashrc文件(~/.bashrc)主目录下 gedit ~/.bashrc ,并加入
#OpenCV 3.2.0
export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig
export LD_LIBRARY_PATH=/usr/local/lib

#opencv3.4.0
#export PKG_CONFIG_PATH=/usr/local/opencv-3.4.0/lib/pkgconfig
#export LD_LIBRARY_PATH=/usr/local/opencv-3.4.0/lib

用那个取消注释那个,可以使用pkg-config --modversion opencv 进行验证。

  • 注,关于OpenCV4.4.0缺少opencv.pc这个配置信息文件
    参考 https://blog.csdn.net/PecoHe/article/details/97476135 解决
    手动添加了opencv.pc

DOPENCV_EXTRA_MODULES_PATH

cd ..
rm -r build/
mkdir build/ && cd build
cmake -D CMAKE_INSTALL_PREFIX=/usr/local/opencv-3.4.0 -D OPENCV_EXTRA_MODULES_PATH=../opencv_contrib/modules -D BUILD_EXAMPLES=ON ..
sudo apt install libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev

opencv CMakeLists例子

使用opencv官方例程(opencv-3.4.0/samples/cpp/example_cmake),利用CMakeLists.txt,编译代码

cd opencv-3.4.0/samples/cpp/example_cmake
mkdir build
cd build
cmake ..
make
./opencv_example

安装不同版本opencv及共存、切换并验证。_第1张图片

你可能感兴趣的:(视觉SLAM,opencv,计算机视觉,人工智能)