cv_bridge链接到自己的opencv

找到CV_Bridge的库位置 应该在/opt/ros/kinetic/share/cv_bridge/

$ cd /opt/ros/kinetic/share/cv_bridge/cmake
$ sudo cp cv_bridgeConfig.cmake cv_bridgeConfig.cmake.bak #备份
$ sudo cp cv_bridgeConfig.cmake ~/cv_bridgeConfig.cmake #因为这是只读文件,所以拷贝出去修改
$ sudo gedit ~/cv_bridgeConfig.cmake 

打开一个新终端,复制输出内容

$ cd /usr/local/lib
$ ls libopencv_*.3.4.2 |xargs |sed 's/ /;/g'
###先将输出的内容复制

在cv_bridgeConfig.cmake 大约119行左右(不一定准确),找到set(libraries从“cv_bridge;后替换已复制内容

"cv_bridge;libopencv_aruco.so.3.4.6;libopencv_bgsegm.so.3.4.6;libopencv_bioinspired.so.3.4.6;libopencv_calib3d.so.3.4.6;libopencv_ccalib.so.3.4.6;libopencv_core.so.3.4.6;libopencv_cudaarithm.so.3.4.6;libopencv_cudabgsegm.so.3.4.6;libopencv_cudacodec.so.3.4.6;libopencv_cudafeatures2d.so.3.4.6;libopencv_cudafilters.so.3.4.6;libopencv_cudaimgproc.so.3.4.6;libopencv_cudalegacy.so.3.4.6;libopencv_cudaobjdetect.so.3.4.6;libopencv_cudaoptflow.so.3.4.6;libopencv_cudastereo.so.3.4.6;libopencv_cudawarping.so.3.4.6;libopencv_cudev.so.3.4.6;libopencv_datasets.so.3.4.6;libopencv_dnn_objdetect.so.3.4.6;libopencv_dnn.so.3.4.6;libopencv_dpm.so.3.4.6;libopencv_face.so.3.4.6;libopencv_features2d.so.3.4.6;libopencv_flann.so.3.4.6;libopencv_freetype.so.3.4.6;libopencv_fuzzy.so.3.4.6;libopencv_hdf.so.3.4.6;libopencv_hfs.so.3.4.6;libopencv_highgui.so.3.4.6;libopencv_imgcodecs.so.3.4.6;libopencv_img_hash.so.3.4.6;libopencv_imgproc.so.3.4.6;libopencv_line_descriptor.so.3.4.6;libopencv_ml.so.3.4.6;libopencv_objdetect.so.3.4.6;libopencv_optflow.so.3.4.6;libopencv_phase_unwrapping.so.3.4.6;libopencv_photo.so.3.4.6;libopencv_plot.so.3.4.6;libopencv_reg.so.3.4.6;libopencv_rgbd.so.3.4.6;libopencv_saliency.so.3.4.6;libopencv_sfm.so.3.4.6;libopencv_shape.so.3.4.6;libopencv_stereo.so.3.4.6;libopencv_stitching.so.3.4.6;libopencv_structured_light.so.3.4.6;libopencv_superres.so.3.4.6;libopencv_surface_matching.so.3.4.6;libopencv_text.so.3.4.6;libopencv_tracking.so.3.4.6;libopencv_videoio.so.3.4.6;libopencv_video.so.3.4.6;libopencv_videostab.so.3.4.6;libopencv_viz.so.3.4.6;libopencv_xfeatures2d.so.3.4.6;libopencv_ximgproc.so.3.4.6;libopencv_xobjdetect.so.3.4.6;libopencv_xphoto.so.3.4.6")

定位cv_bridgeConfig.cmake 94行, 将路径替换为“/usr/local/include/opencv”,修改后如下:

if(NOT "include;/usr/local/include/opencv;/usr/local/include " STREQUAL " ")
  set(cv_bridge_INCLUDE_DIRS "")
  set(_include_dirs "include;/usr/local/include/opencv;/usr/local/include")