当前位置:   article > 正文

UBuntu20.04安装自己的opencv以及cv_bridge_ubuntu20.04安装opencv4.2.0

ubuntu20.04安装opencv4.2.0

解决问题:

默认UBuntu20.04的ROS自带的opencv版本是4.2.0,但是在写代码或者跑别人的项目时,所需要的版本往往不同。而且如果代码中使用了cv_bridge,虽然ROS里面是自带cv_bridge的,但它链接的是ROS自带的opencv版本,即使将CMakeLists.txt更改为要求的opencv的路径并编译通过,还是会因为使用了cv_bridge而链接到自带的版本。于是应该重新安装cv_bridge并链接到自定义的opencv版本。

一、安装自定义版本opencv(这里安装4.5.0)

一般是放在usr/local下,这是参考博客:

建议在local下再建一个文件夹opencv450,这样如果以后要装更多版本的opencv就方便管理,具体可以参考这篇博客:

ubuntu16.04 install opencv、Sohpus、PCL、OctoMap、VTK_lutu.sohp-CSDN博客

二、安装对应ROS版本的cv_bridge并链接到指定的opencv

下载对应ROS版本的cv_bridge:

https://github.com/ros-perception/vision_opencv/tree/noetic

下载后将cv_bridge单独取出然后将CMakeLists.txt里面的opencv路径更改为自己的opencv路径再安装。以我的opencv4.5.0为例:

我把它放在了这个位置:

打开cv_bridge里的CMakeList.txt,设置成指定的opencv版本:

  1. set(OpenCV_DIR "/usr/local/share/opencv4")
  2. find_package(OpenCV 4.5.0 REQUIRED
  3. COMPONENTS
  4. opencv_core
  5. opencv_imgproc
  6. opencv_imgcodecs
  7. CONFIG
  8. )

set的opencv的路径就写指定的opencv下载路径对应的share文件夹下的opencv文件夹。我在安装Opencv4.5.0的时候把它装在usr/local下了,装的时候应该有一个指令是:

cmake -D CMAKE_INSTALL_PREFIX=/usr/local ..

这个 CMAKE_INSTALL_PREFIX就是安装的路径,建议在local下再建一个文件夹opencv4.5.0,这样方便管理。

然后安装:

这里的CMAKE_INSTALL_PREFIX和安装自定义的opencv安装位置意思是一样的,也可以在local下再建一个文件夹方便管理,比如CMAKE_INSTALL_PREFIX=/usr/local/cv_bridge450。

  1. cmake -D CMAKE_INSTALL_PREFIX=/usr/local -DCMAKE_BUILD_TYPE=Release -DSETUPTOOLS_DEB_LAYOUT=OFF ..
  2. sudo make -j8
  3. sudo make install

我这里写的还是usr/local。

参考博客:ROS工程不使用ROS自带的OpenCV_ros 不使用自带opencv-CSDN博客

不过因为报错“error: option --install-layout not recognized”所以把cmake那一句改了一下,参考解决办法:error: option --install-layout not recognized-CSDN博客,感谢评论的大佬。

如果install结束之后是这样就安装好了:

  1. q**@q**-*****-***:~/Packages/cv_bridge/build$ sudo make install
  2. [ 0%] Built target geometry_msgs_generate_messages_cpp
  3. [ 0%] Built target std_msgs_generate_messages_nodejs
  4. [ 0%] Built target std_msgs_generate_messages_cpp
  5. [ 0%] Built target std_msgs_generate_messages_eus
  6. [ 0%] Built target geometry_msgs_generate_messages_lisp
  7. [ 0%] Built target geometry_msgs_generate_messages_py
  8. [ 0%] Built target sensor_msgs_generate_messages_nodejs
  9. [ 0%] Built target sensor_msgs_generate_messages_lisp
  10. [ 0%] Built target geometry_msgs_generate_messages_eus
  11. [ 0%] Built target std_msgs_generate_messages_lisp
  12. [ 0%] Built target std_msgs_generate_messages_py
  13. [ 0%] Built target sensor_msgs_generate_messages_cpp
  14. [ 0%] Built target sensor_msgs_generate_messages_eus
  15. [ 0%] Built target geometry_msgs_generate_messages_nodejs
  16. [ 0%] Built target sensor_msgs_generate_messages_py
  17. [ 50%] Built target cv_bridge
  18. [100%] Built target cv_bridge_boost
  19. Install the project...
  20. -- Install configuration: "Release"
  21. -- Installing: /usr/local/_setup_util.py
  22. -- Up-to-date: /usr/local/env.sh
  23. -- Up-to-date: /usr/local/setup.bash
  24. -- Up-to-date: /usr/local/local_setup.bash
  25. -- Up-to-date: /usr/local/setup.sh
  26. -- Up-to-date: /usr/local/local_setup.sh
  27. -- Up-to-date: /usr/local/setup.zsh
  28. -- Up-to-date: /usr/local/local_setup.zsh
  29. -- Up-to-date: /usr/local/.rosinstall
  30. -- Installing: /usr/local/lib/pkgconfig/cv_bridge.pc
  31. -- Up-to-date: /usr/local/share/cv_bridge/cmake/cv_bridge-extras.cmake
  32. -- Up-to-date: /usr/local/share/cv_bridge/cmake/cv_bridgeConfig.cmake
  33. -- Up-to-date: /usr/local/share/cv_bridge/cmake/cv_bridgeConfig-version.cmake
  34. -- Up-to-date: /usr/local/share/cv_bridge/package.xml
  35. + cd /home/qly/Packages/cv_bridge
  36. + mkdir -p /usr/local/lib/python3.8/site-packages
  37. + /usr/bin/env PYTHONPATH=/usr/local/lib/python3.8/site-packages:/home/qly/Packages/cv_bridge/build/lib/python3.8/site-packages: CATKIN_BINARY_DIR=/home/qly/Packages/cv_bridge/build /usr/bin/python3 /home/qly/Packages/cv_bridge/setup.py egg_info --egg-base /home/qly/Packages/cv_bridge/build build --build-base /home/qly/Packages/cv_bridge/build install --root=/ --prefix=/usr/local --install-scripts=/usr/local/bin
  38. running egg_info
  39. creating /home/qly/Packages/cv_bridge/build/cv_bridge.egg-info
  40. writing /home/qly/Packages/cv_bridge/build/cv_bridge.egg-info/PKG-INFO
  41. writing dependency_links to /home/qly/Packages/cv_bridge/build/cv_bridge.egg-info/dependency_links.txt
  42. writing top-level names to /home/qly/Packages/cv_bridge/build/cv_bridge.egg-info/top_level.txt
  43. writing manifest file '/home/qly/Packages/cv_bridge/build/cv_bridge.egg-info/SOURCES.txt'
  44. reading manifest file '/home/qly/Packages/cv_bridge/build/cv_bridge.egg-info/SOURCES.txt'
  45. writing manifest file '/home/qly/Packages/cv_bridge/build/cv_bridge.egg-info/SOURCES.txt'
  46. running build
  47. running build_py
  48. creating /home/qly/Packages/cv_bridge/build/lib
  49. creating /home/qly/Packages/cv_bridge/build/lib/cv_bridge
  50. copying python/cv_bridge/__init__.py -> /home/qly/Packages/cv_bridge/build/lib/cv_bridge
  51. copying python/cv_bridge/core.py -> /home/qly/Packages/cv_bridge/build/lib/cv_bridge
  52. running install
  53. running install_lib
  54. creating /usr/local/lib/python3.8/site-packages/cv_bridge
  55. copying /home/qly/Packages/cv_bridge/build/lib/cv_bridge/__init__.py -> /usr/local/lib/python3.8/site-packages/cv_bridge
  56. copying /home/qly/Packages/cv_bridge/build/lib/cv_bridge/core.py -> /usr/local/lib/python3.8/site-packages/cv_bridge
  57. byte-compiling /usr/local/lib/python3.8/site-packages/cv_bridge/__init__.py to __init__.cpython-38.pyc
  58. byte-compiling /usr/local/lib/python3.8/site-packages/cv_bridge/core.py to core.cpython-38.pyc
  59. running install_egg_info
  60. Copying /home/qly/Packages/cv_bridge/build/cv_bridge.egg-info to /usr/local/lib/python3.8/site-packages/cv_bridge-1.16.2-py3.8.egg-info
  61. running install_scripts
  62. /usr/local/lib/python3.8/dist-packages/setuptools/_distutils/cmd.py:66: SetuptoolsDeprecationWarning: setup.py install is deprecated.
  63. !!
  64. ********************************************************************************
  65. Please avoid running ``setup.py`` directly.
  66. Instead, use pypa/build, pypa/installer or other
  67. standards-based tools.
  68. See https://blog.ganssle.io/articles/2021/10/setup-py-deprecated.html for details.
  69. ********************************************************************************
  70. !!
  71. self.initialize_options()
  72. -- Installing: /usr/local/include/cv_bridge
  73. -- Installing: /usr/local/include/cv_bridge/cv_bridge.h
  74. -- Installing: /usr/local/include/cv_bridge/rgb_colors.h
  75. -- Installing: /usr/local/lib/python3.8/site-packages/cv_bridge/boost/__init__.py
  76. -- Installing: /usr/local/lib/libcv_bridge.so
  77. -- Set runtime path of "/usr/local/lib/libcv_bridge.so" to ""

然后如果要在自己的项目里用opencv的话,继续按照这篇博客里接着走就行:ROS工程不使用ROS自带的OpenCV_ros 不使用自带opencv-CSDN博客

感谢各位大佬提供的资料!

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/知新_RL/article/detail/178413
推荐阅读
相关标签
  

闽ICP备14008679号