Giter Site home page Giter Site logo

zhenshenglee / ros2_v4l2_camera Goto Github PK

View Code? Open in Web Editor NEW
11.0 4.0 3.0 284 KB

ros2_v4l2_camera with shm_msg based zero-copy and more!

License: Apache License 2.0

CMake 3.54% C++ 42.78% C 1.09% Python 0.98% Jupyter Notebook 51.61%
camera v4l2 zero-copy ros2

ros2_v4l2_camera's Introduction

github repo of v4l2_camera with zero-copy support

this is not the official repo of ros2_v4l2_camera, please goto the gitlab

introduction

in this repo, the camera node can publish shm_msgs::msg::Imagexm based on ros2_shm_msgs

With shm_msgs msg types, zero copy(during the IPC communication period) can be achieved, and transport latency and cpu usage can be reduced.

You must select the msg type according the size of data, for example, shm_msgs::msg::Image1m for the 640X480 RBG8 image transport.

This is because in most of ddses, the constraints of zero-copy transport is the bounded size of data.

usage of zero-copy transport

select rmw

the dds config files canbe checked in ros2_shm_msgs

for rmw_cyclonedds

export RMW_IMPLEMENTATION=rmw_cyclonedds_cpp
export CYCLONEDDS_URI=file:///$HOME/shm_cyclonedds.xml

# t0
iox-roudi

for rmw_fastrtps_cpp

export RMW_IMPLEMENTATION=rmw_fastrtps_cpp
export FASTRTPS_DEFAULT_PROFILES_FILE=$HOME/shm_fastdds.xml
export RMW_FASTRTPS_USE_QOS_FROM_XML=1

build

cd src
git clone https://github.com/ZhenshengLee/ros2_shm_msgs.git
# the added work of zero-copy support is hosted in the `outdoor/rolling` branch.
git clone -b outdoor/rolling https://github.com/ZhenshengLee/ros2_v4l2_camera.git
colcon build

run

driver(after a camera pluged in, in my case that's a logitech525 usbcam)

ros2 run v4l2_camera v4l2_camera_shm1m_node --ros-args --log-level info
# ros2 run v4l2_camera v4l2_camera_shm1m_node --ros-args --log-level debug

image1m_subscriber

cd install/v4l2_camera/lib/v4l2_camera
./v4l2_camera_image1m_subscriber

[INFO] [1654154565.559710174] [shm_image1m_subscriber]: Received...
[INFO] [1654154565.559730953] [shm_image1m_subscriber]: get-image1m-transport-time: 0.253

image1m_rviz_bridge

# config topic remapping
ros2 launch v4l2_camera shm_image1m_bridge.launch.py

rviz2

rviz2
# add topic of image

see rqt_graph rqt_graph

performance

run normal(basically shm) image tranport

# t1
ros2 run v4l2_camera v4l2_camera_node --ros-args --log-level info
# ros2 run v4l2_camera v4l2_camera_node --ros-args --log-level debug

# t2
cd install/v4l2_camera/lib/v4l2_camera
./v4l2_camera_image_subscriber

in my pc of dell 3630, the zero-copy transport of a shm_msgs::msg::Image1m can save about 80% of transport time, from 1.4ms to 0.3ms

v4l2_camera

A ROS 2 camera driver using Video4Linux2 (V4L2).

Features

  • Lists and exposes all user-settable controls of your camera as ROS 2 parameters.
  • Uses cv_bridge to convert raw frames to ROS 2 messages, so supports a wide range of encoding conversions.
  • Supports image_transport to enable compression.
  • Supports composing the camera node and using ROS 2 intra-process commmunication with zero-copy messaging.

Installation

This article details how to build and run this package. It focuses on Raspberry Pi OS with the Raspberry Pi Camera Module V2 but should generalise for most systems.

ROS package install

This package is available from the ROS package repositories and can therefore be installed with the following command and your ROS version name:

sudo apt-get install ros-${ROS_DISTRO}-v4l2-camera

Building from source

If you need to modify the code or ensure that you have the latest updates you will need to clone this repository, and then build the package.

git clone --branch ${ROS_DISTRO} https://gitlab.com/boldhearts/ros2_v4l2_camera.git src/v4l2_camera
rosdep install --from-paths src/v4l2_camera --ignore-src -r -y
colcon build

Most users will also want to set up compressed transport using the dependencies below.

Basic Usage

Run the camera node to publish camera images, using the default parameters:

ros2 run v4l2_camera v4l2_camera_node

You can use rqt-image-view to preview the images (open another terminal):

sudo apt-get install ros-${ROS_DISTRO}-rqt-image-view
ros2 run rqt_image_view rqt_image_view

See further below for information about enabling compression.

Nodes

v4l2_camera_node

The v4l2_camera_node interfaces with standard V4L2 devices and publishes images as sensor_msgs/Image messages.

Published Topics

  • /image_raw - sensor_msgs/Image

    The image.

Parameters

  • video_device - string, default: "/dev/video0"

    The device the camera is on.

  • pixel_format - string, default: "YUYV"

    The pixel format to request from the camera. Must be a valid four character 'FOURCC' code supported by V4L2 and by your camera. The node outputs the available formats supported by your camera when started. Currently supported: "YUYV" or "GREY"

  • output_encoding - string, default: "rgb8"

    The encoding to use for the output image. Can be any supported by cv_bridge given the input pixel format. Currently these are for "YUYV": " yuv422_yuy2" (no conversion), or "mono8", "rgb8", "bgr8", "rgba8" and "bgra8", plus their 16 bit variants, and for "GREY" these are "mono8" (no conversion), "rgb8", "bgr8", "rgba8" and "bgra8", plus their 16 bit variants.

  • image_size - integer_array, default: [640, 480]

    Width and height of the image.

  • Camera Control Parameters

    Camera controls, such as brightness, contrast, white balance, etc, are automatically made available as parameters. The driver node enumerates all controls, and creates a parameter for each, with the corresponding value type. The parameter name is derived from the control name reported by the camera driver, made lower case, commas removed, and spaces replaced by underscores. So Brightness becomes brightness, and White Balance, Automatic becomes white_balance_automatic.

Compressed Transport

This package uses image_transport to publish images and make compression possible. However, by default it only supports raw transfer, plugins are required to enable compression. These need to be installed separately:

sudo apt-get install ros-${ROS_DISTRO}-image-transport-plugins

Once installed, they will be automatically used by the driver and additional topics will be available, including /image_raw/compressed.

ros2_v4l2_camera's People

Contributors

christianrauch avatar clalancette avatar ijnek avatar jacobperron avatar nuclearsandwich avatar scheunemann avatar sgvandijk avatar sgvandijkpp avatar zhenshenglee avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

ros2_v4l2_camera's Issues

CMake Error "libusb::libusb" not found

Hi,

I am trying to build v4l2_camera on Ubuntu 22.04 and ROS Humble but getting cmake errors Boost, VTX and libusb. I was able to add Boost and VTK to CMake and it worked but unable to add libusb via Cmake.

CMake Error at CMakeLists.txt:30 (add_library):
Target "v4l2_camera" links to target "libusb::libusb" but the target was
not found. Perhaps a find_package() call is missing for an IMPORTED
target, or an ALIAS target is missing?

Please help

register node

template
void V4L2Camera::convert_shm(Topic & img) const
{
auto tracked_object = std::shared_ptr{};
auto cvImg = shm_msgs::toCvShare(img, tracked_object);
auto cvConvertedImg = shm_msgs::cvtColor(cvImg, output_encoding_);
cvConvertedImg->toImageMsg(img);
}

template
bool V4L2Camera::checkCameraInfo(
sensor_msgs::msg::Image const & img,
sensor_msgs::msg::CameraInfo const & ci)
{
return ci.width == img.width && ci.height == img.height;
}

template
bool V4L2Camera::checkCameraInfo_shm(
Topic const & img,
sensor_msgs::msg::CameraInfo const & ci)
{
return ci.width == img.width && ci.height == img.height;
}

} // namespace v4l2_camera

// #include "rclcpp_components/register_node_macro.hpp"
// RCLCPP_COMPONENTS_REGISTER_NODE(v4l2_camera::V4L2Camera)
您好,上边这段代码去掉了 COMPONENT_NODE的宏定义,请问这种使用模块的node类是否有啥办法使用这种node注册的宏吗?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.