NVIDIA Jetson TX2 根据OpenCV版本重新编译cv_bridge并配置CMakeLists.txt

参考:

  1. 解决 cv_bridge 与 opencv4 版本冲突问题(***)
  2. ROS学习:cv_bridge与opencv版本冲突三种解决方案(***)
  3. ROS配置中cv_bridge(***)

背景:

使用自己安装在局部的 3.4.9 的OpenCV,重新编译cv_bridge,生成动态库,以便Astro Camera 和ORB-SLAM3调用。

安装:

  1. 安装依赖
sudo apt-get install python-catkin-tools python3-dev python3-catkin-pkg-modules python3-numpy python3-yaml ros-melodic-cv-bridge

  1. 安装cv_bridge
$ mkdir cv349_brige
$ cd cv349_brige
$ catkin init

会有红色的文字显示 missing, 不是错误,没事

$ catkin config -DPYTHON_EXECUTABLE=/usr/bin/python3 -DPYTHON_INCLUDE_DIR=/usr/include/python3.6m -DPYTHON_LIBRARY=/usr/lib/aarch64-linux-gnu/libpython3.6m.so
$ catkin config --install
$ git clone https://github.com/ros-perception/vision_opencv.git src/vision_opencv
$ apt-cache show ros-melodic-cv-bridge | grep Version
Version: 1.13.0-0bionic.20220127.173353
$ cd src/vision_opencv/
$ git checkout 1.13.0
$ cd ../../
  1. 修改cv_bridge 的 CMakeLists
$ cd src/vision_opencv/cv_bridge
$ gedit CMakeLists.txt
set(OpenCV_DIR /home/wxf/newdisk/3rdparty/opencv_env/349/share/OpenCV)
find_package(OpenCV 3.4.9 REQUIRED
  COMPONENTS
    opencv_core
    opencv_imgproc
    opencv_imgcodecs
  CONFIG
)
$ cd ../../..
$ catkin build cv_bridge
  1. 将功能包加到扩展环境中
$ gedit ~/.bashrc

末尾写入下面内容:

#cv_brige
source /home/wxf/newdisk/ros/cv349_brige/install/setup.bash --extend
$ source ~/.bashrc
  1. 利用编译好的cv_bridge编译astrapro_ros
$ cd /xxx/ros/astrapro_ros/src/ros_astra_camera
$ gedit CMakeLists.txt

修改:

#添加这一行
set(cv_bridge_DIR /home/wxf/newdisk/ros/cv349_brige/devel/share/cv_bridge/cmake)
find_package(catkin REQUIRED
  camera_info_manager
  dynamic_reconfigure
  image_transport
  nodelet
  sensor_msgs
  roscpp
  message_generation
  cv_bridge
  )

find_package(Boost REQUIRED COMPONENTS system thread)
#添加这一行
set(OpenCV_DIR /home/wxf/newdisk/3rdparty/opencv_env/349/share/OpenCV)
find_package(OpenCV 3.4.9 REQUIRED)

然后编译

...
[100%] Built target astra_camera_node
[100%] Built target astra_camera_nodelet

编译成功!!!

你可能感兴趣的:(TX2,slam,opencv,计算机视觉)