ubuntu18.04安装opencv3.4.4过程:
步骤:
安装依赖包:
sudo apt-get update
sudo apt-get upgrade
//依赖包
sudo apt-get install build-essential
sudo apt-get install cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev
sudo apt-get install python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc1394-22-dev
sudo apt-get install qt5-default ccache libv4l-dev libavresample-dev libgphoto2-dev libopenblas-base libopenblas-dev doxygen openjdk-8-jdk pylint libvtk6-dev
sudo apt-get install pkg-config
解压opencv压缩包,编译安装:
cd opencv
mkdir build
cd build
cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local ..
make
sudo make install
配置环境:
sudo /bin/bash -c 'echo "/usr/local/lib" > /etc/ld.so.conf.d/opencv.conf'
sudo ldconfig
配置 bash:
sudo gedit /etc/bash.bashrc
在文件最末尾添加
PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig
export PKG_CONFIG_PATH
保存,执行如下命令使得配置生效source /etc/bash.bashrc
然后更新sudo updatedb
参照https://blog.csdn.net/qq_33728095/article/details/104256301
1.错误: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
2.错误: fatal error: linux/videodev.h: not found
解决:sudo apt-get install libv4l-dev*
sudo ln -s /usr/include/libv4l1-videodev.h /usr/include/linux/videodev.h
cv_bridge编译过程:
1.错误:
CMake Error at /usr/share/cmake-3.10/Modules/FindBoost.cmake:1947 (message):
Unable to find the requested Boost libraries.
Boost version: 1.65.1
Boost include path: /usr/include
Could not find the following Boost libraries:
boost_python37
No Boost libraries were found. You may need to set BOOST_LIBRARYDIR to the
directory containing Boost libraries or BOOST_ROOT to the location of
Boost.
解决:ubuntu18.04自带了python3.6,用python3可以找到。在/home/yy/cv_bridge/src/vision_opencv/cmakelists.txt中,把第8行find_package(Boost REQUIRED python37)改为find_package(Boost REQUIRED python3).
2.错误:【未解决】
/usr/include/python2.7/numpy/__multiarray_api.h:1537:144: error: return-statement with no value, in function returning ‘void*’ [-fpermissive]
tring(PyExc_ImportError, "numpy.core.multiarray failed to import"); return NUMPY_IMPORT_ARRAY_RETVAL; } }
解决:看编译过程输出系统找pythonlibs是找到了2.7的,用set设置了python3的路径还是不行。于是考虑把python3.6设置成了系统默认版本。
设置系统默认版本python:这里使用的是优先级设置,后面的数字越大,优先级越高。
sudo update-alternatives --install /usr/bin/python python /usr/bin/python2.7 1
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.6 2
在终端中直接输入python,可以看到默认版本。
还是不行 ,因为catkin依赖的是python2.7,修改了python默认版本catkin_make会报错无法进行。
最终解决:删掉原来的包,用源码编译!参照https://gitee.com/bingobinlw/cv_bridge/blob/master/README.md
cv_bridge步骤:
mkdir -p cv_bridge_ws/src cd cv_bridge_ws/src git clone https://gitee.com/bingobinlw/cv_bridge cd ..
将opencv编译生成的build文件路径加入到CMakeLists.txt(详见此文件目录下的CMakeLists.txt文件)
set(OpenCV_DIR "your-path/opencv-x.x.x/build")
最后catkin_make,终于成功了!!!