OpenCV
OpenCV
Basic Vision Algorithm - OpenCV Implementation
CV_Bridge
cv_bridge Wikipedia Introduction:
https://wiki.ros.org/cv_bridge
https://index.ros.org/p/cv_bridge/
ROS2 Humble's cv_bridge repository link (be sure to select the corresponding version branch):
https://github.com/ros-perception/vision_opencv/tree/humble


Install
Pre-compile OpenCV4 with CUDA in advance. See Electrical Control Team Environment Setup Guide for details.
- apt installation (not recommended)
Since ROS's built-in cv_bridge automatically links to ROS's own OpenCV version, we generally do not use the cv_bridge that comes with ROS2. Instead, we typically need to manually compile a custom 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
- Source code compilation and installation (recommended)
This tutorial uses Jazzy as an example.
First, clone the repository. You can clone the jazzy, humble, or rolling branches — any ROS2 version should work without major changes. However, since the official jazzy branch hasn't been released yet, I'll just clone the default rolling branch.

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 the CMakeLists of cv_bridge

Change the original find_package(OpenCV 4 QUIET) to an exact match version, and add the EXACT parameter:
EXACT means that if an exact version is not found, CMake will report an error and abort 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 image below, I have successfully linked to version 411, which is OpenCV 4.11.

Next, configure the environment:
vim ~/.bashrc
Add the following sentence to the line below source /opt/ros/jazzy/setup.bash:
source ~/ros2_ws/install/setup.bash
:wq saved
Installation and environment setup complete.