问题1:
正常安装cv_briage会自动安装opencv4.2,但是实际我们的工程可能不是opencv4.2 且 未必安装在系统目录
sudo apt install ros-noetic-cv-bridge
https://community.bwbot.org/topic/16589/%E5%A6%82%E4%BD%95%E5%9C%A8ubuntu-22-04%E4%B8%8A%E4%BD%BF%E7%94%A8cv_bridge/4
正常安装
- 安装ROS Noetic
在终端中输入以下命令:
sudo apt update sudo apt install ros-noetic-desktop-full
- 安装依赖项
在终端中输入以下命令:
sudo apt install python3-catkin-pkg-modules python3-rospkg-modules python3-empy python3-nose python3-yaml python3-setuptools python3-rosdep python3-rosinstall python3-rosinstall-generator python3-wstool build-essential cmake
sudo apt-get install python3-rosdep python3-rosinstall python3-rospkg
conda install -c conda-forge rospkg
- 下载cv_bridge源码
在终端中输入以下命令:
注意需要使用其中的noetic分支,2024年9月网址进入默认是ros2版本的不是ros1的。
https://github.com/ros-perception/vision_opencv/branches
cd ~ mkdir -p catkin_ws_cv_bridge/src cd catkin_ws/src git clone https://github.com/ros-perception/vision_opencv.git -b noetic
如果修改oepncv依赖版本:
opencv安装目录
确保系统添加
# opencv版本制定 # opencv3.4.9 OpenCVConfig位置 export OpenCV_DIR=/home/dongdong/1sorftware/1work/opencv/opencv349/install/share/OpenCV export LD_LIBRARY_PATH=/home/dongdong/1sorftware/1work/opencv/opencv349/install/lib:$LD_LIBRARY_PATH export CPLUS_INCLUDE_PATH=/home/dongdong/1sorftware/1work/opencv/opencv349/install/include/opencv2:$CPLUS_INCLUDE_PATH # opencv4.5 OpenCVConfig位置 #export OpenCV_DIR=/home/dongdong/1sorftware/1work/opencv/opencv455/install/lib/cmake/opencv4 #export LD_LIBRARY_PATH=/home/dongdong/1sorftware/1work/opencv/opencv455/install/lib:$LD_LIBRARY_PATH #export CPLUS_INCLUDE_PATH=/home/dongdong/1sorftware/1work/opencv/opencv455/install/include/opencv4:$CPLUS_INCLUDE_PATH
修改cv_bridge
修改前
修改后
# 设置 OpenCV 的路径 set(OpenCV_DIR "/home/dongdong/1sorftware/1work/opencv/opencv349/install/share/OpenCV") # 适配openvslam #set(OpenCV_DIR "/home/dongdong/1sorftware/1work/opencv/opencv455/install/lib/cmake/opencv4") find_package(OpenCV REQUIRED)
修改image_geometry
- 编译cv_bridge
在终端中输入以下命令:
cd ~/catkin_ws_cv_bridge catkin_make
- 设置ROS环境变量
在终端中输入以下命令:
echo "source /home/dongdong/1sorftware/1work/opencv/catkin_ws_cv_bridge/devel/setup.bash" >> ~/.bashrc source ~/.bashrc
这里将cv_briage自动添加到系统变量 每次都能自动找到。
(实用脚本需要单独加上这个语句,不然节点不知道去哪里找到这个cv_briage包)
6 也可以单独把这个包加入到自己的工程中作为一个独立的包编译。
拷贝到自己的ros工程src下面,作为一个独立的包被自己同工程其他调用包