分析:因为安装的ubuntu版本是20.04,对应安的noetic包里自带的是Opencv4.2,因此需要更改ros编译时使用的opencv版本。
解决:打开/opt/ros/noetic/share/cv_bridge/cmake/cv_bridgeConfig.cmake文件,做以下更改:(注释掉的是源代码,后边是更改后的)
#if(NOT “include;/usr/include/opencv4 ” STREQUAL ” “)
if(NOT “include;/usr/local/include/opencv; /usr/local/include/opencv2 “ STREQUAL ” “)
set(cv_bridge_INCLUDE_DIRS “”)
#set(_include_dirs “include;/usr/include/opencv4”)
set(_include_dirs “include;/usr/local/lib;/usr/local/include/opencv;/usr/local/include/opencv2;/usr/local/include;/usr/include”)
之后再安装一个Opencv 3.x的版本即可。(可参考链接安装:https://blog.csdn.net/qq_36351159/article/details/108255033)