Wiki
OpenCV
Existing English translations were reused. 2 current source blocks remain in Simplified Chinese, without triggering paid translation.
1.OpenCV
Basic Vision Algorithms - OpenCV Implementation
2.CV_Bridge
cv_bridge维基百科介绍:
https://wiki.ros.org/cv_bridge
https://index.ros.org/p/cv_bridge/
ROS2Humble's cv_bridge repository link (note: select the corresponding version branch):
https://github.com/ros-perception/vision_opencv/tree/humble


2.1.Install
Compile OpenCV4 with CUDA beforehand yourself; for details, seeElectronics Control Group Environment Setup Guide
- apt installation (not recommended)
由于ros自带的cv_bridge自动链接ros自带的oepncv版本,所以我们一般不会用ros2自带的cv_bridge,一般都需要自己手动编译一个cv_bridge.
# 通用命令
sudo apt install ros-<ros2-distro>-vision-opencv
# ROS2 Humble
sudo apt install ros-humble-vision-opencv
# ROS2 Jazzy
sudo apt install ros-jazzy-vision-opencv
- Compile and install from source (recommended)
This tutorial uses jazzy as an example.
First, clone the repository. You can clone jazzy, humble, or rolling; as long as it is ROS2, there won't be much change. However, the official version for jazzy has not been released yet, so I just cloned the default rolling.

Create a new folder
mkdir ~/ros2_ws/src
cd ~/ros2_ws/src
# 克隆源码
git clone https://github.com/ros-perception/vision_opencv.git
cd vision_opencv
# 如果是humble建议:
git checkout humble
Install dependencies:
sudo apt install python3-numpy
sudo apt install libboost-python-dev
Modify cv_bridge's CMakeLists

Change the originalfind_package(OpenCV 4 QUIET)to the exact match version, and add theEXACTparameter:
EXACT means that when no exact version is found, CMake reports an error and terminates the build.

find_package(OpenCV 4.11 EXACT QUIET
COMPONENTS
opencv_core
opencv_imgproc
opencv_imgcodecs
CONFIG
)
cd ~/ros2_ws
# 下面这三个根据情况三选一,一般是第一个colcon build --symlink-install
# 如果你曾经没编译过
colcon build --symlink-install
# 如果你只想编译cv_bridge
colcon build --symlink-install --packages-select cv_bridge
# 如果你曾经编译过一遍,则需要下列命令
colcon build --symlink-install --packages-select cv_bridge --allow-overriding cv_bridge
Verification:
# 列出cv_bridge链接的opencv版本
ldd ./install/cv_bridge/lib/libcv_bridge.so | grep opencv
As shown in the figure below, I successfully connected to 411, that is, opencv4.11 version.

Next, configure the environment:
vim ~/.bashrc
Atsource /opt/ros/jazzy/setup.bashadd the following sentence on the next line
source ~/ros2_ws/install/setup.bash
Input:wqSave
Installation and environment configuration are complete.