diff --git a/image_view/README.md b/image_view/README.md new file mode 100644 index 000000000..f29bec66a --- /dev/null +++ b/image_view/README.md @@ -0,0 +1,30 @@ +# image_view + +`image_view` provides simple tools to look at image topics and to save them to files. + +```console +ros2 run image_view image_view --ros-args -r image:=/camera/image_raw +``` + +| Executable | What it does | +| --- | --- | +| `image_view` | Shows an image topic in a window. Right-click to save the image. | +| `stereo_view` | Shows the left and right images of a stereo camera and their disparity image. | +| `disparity_view` | Shows a `stereo_msgs/msg/DisparityImage`, color-mapped. | +| `image_saver` | Saves images to files: all of them, or on request with the `save` service. | +| `video_recorder` | Records an image topic to a video file. | +| `extract_images`, `extract_images_sync` | Save images to files (currently broken, see the documentation). | + +Each tool is also available as a component, for example `image_view::ImageViewNode`. + +## Documentation + +The full documentation, including all the parameters, tutorials and known issues, is in the [doc](https://github.com/ros-perception/image_pipeline/blob/rolling/image_view/doc/index.rst) directory and it is published at [docs.ros.org](https://docs.ros.org/en/rolling/p/image_view/). + +To build it locally, [install rosdoc2](https://github.com/ros-infrastructure/rosdoc2#installation) and run: + +```console +rosdoc2 build --package-path . +``` + +The result is written to `docs_output/image_view/index.html`. diff --git a/image_view/doc/components.rst b/image_view/doc/components.rst index ef7f26e1e..6dfc166fa 100644 --- a/image_view/doc/components.rst +++ b/image_view/doc/components.rst @@ -1,161 +1,178 @@ Nodes and Components ==================== -image_view::DisparityViewNode ------------------------------ -Simple image viewer for ROS stereo_msgs/DisparityImage topics. -Color-maps the disparity image for visualization. -Node name is ``disparity_view``. +Each tool is available as an executable, for example ``ros2 run image_view image_view``, and as a component. +All of them subscribe to ``image``: remap it to the topic you want. + +The tools that use ``image_transport`` have an ``image_transport`` parameter (string, default: ``raw``), the transport used to subscribe to the image, for example ``compressed``. + +.. _ImageViewNode: + +image_view::ImageViewNode +------------------------- + +Shows an image topic in a window. +Right-click on the window to save the displayed image. +Closing the window stops the node. +Executable: ``image_view``. Default node name: ``image_view_node``. Subscribed Topics ^^^^^^^^^^^^^^^^^ - * **image** (sensor_msgs/DisparityImage): The disparity image topic. +* **image** (sensor_msgs/msg/Image): The image to show. Subscribed with the sensor data QoS (best effort). + +Published Topics +^^^^^^^^^^^^^^^^ +* **output** (sensor_msgs/msg/Image): The received images, unchanged. Parameters ^^^^^^^^^^ - * **autosize** (bool, default: false): Whether the window should autosize - itself to the image or be resizeable by the user. - * **window_name** (string, default: name of the image topic): - The name of the display window. +* **image_transport** (string, default: ``raw``): Transport used to subscribe to ``image``. +* **window_name** (string, default: the resolved name of ``image``): Title of the window. +* **gui** (bool, default: true): If false, no window is opened. +* **autosize** (bool, default: false): If true, the window has the size of the image and cannot be resized. +* **width** (int, default: -1) and **height** (int, default: -1): Initial size of the window, if both are set and ``autosize`` is false. +* **filename_format** (string, default: ``frame{:04}.jpg``): Name of the saved images, in `std::format `_ syntax; ``{:04}`` is replaced by the image number. + The extension selects the format, for example ``.png``. +* **colormap** (int, default: -1): Colormap for depth and floating point images: -1 for none, or a ``cv::ColormapTypes`` value from 0 (``AUTUMN``) to 11 (``HOT``), for example 2 for ``JET``. Can be changed at runtime. +* **min_image_value** (int, default: 0) and **max_image_value** (int, default: 0): Range of values shown for depth and floating point images. Can be changed at runtime. + If both are equal, the range is 0 to 10 m: 0 to 10 for ``32FC1`` images (in meters) and 0 to 10000 for ``16UC1`` images (in millimeters). -image_view::ExtractImagesNode ------------------------------ -This tool also allows you to save images as jpg/png file from -streaming (ROS sensor_msgs/Image topic) to a file. -``image_saver`` node provide very similar functionalities, -such as providing service call to trigger the node to save -images, save images other than JPEG format, etc. +.. note:: + + Depth images cannot currently be shown, so ``colormap``, ``min_image_value`` and ``max_image_value`` have no visible effect. See :ref:`known-issues`. + +.. _StereoViewNode: + +image_view::StereoViewNode +-------------------------- -This tool allows you to save images as jpg/png file from streaming -(ROS sensor_msgs/Image topic) to a file. From command line, you -can run with: +Shows the left and right images of a stereo camera and their disparity image, in three windows called ``left``, ``right`` and ``disparity``. +The three images must have the same timestamp, or close timestamps with ``approximate_sync``. +Right-click on any window to save the three images, as ``left0000.jpg``, ``right0000.jpg``, ``disp0000.jpg``, ... +Executable: ``stereo_view``. Default node name: ``stereo_view_node``. -.. code-block:: bash - - ros2 run image_view image_saver --ros-args -r image:=[your topic] +The topics are built from two names, ``stereo`` (the namespace of the stereo camera) and ``image`` (the name of the image), which must be remapped. +For example, with ``-r stereo:=/my_stereo_cam -r image:=image_rect_color``, it subscribes to ``/my_stereo_cam/left/image_rect_color``, ``/my_stereo_cam/right/image_rect_color`` and ``/my_stereo_cam/disparity``. -or see this answer to control the timing of capture. +Every 15 seconds, it logs a warning if few synchronized triplets were received. Subscribed Topics ^^^^^^^^^^^^^^^^^ - * **image** (sensor_msgs/Image): Image topic to visualize. +* **/left/** (sensor_msgs/msg/Image): The left image. +* **/right/** (sensor_msgs/msg/Image): The right image. +* **/disparity** (stereo_msgs/msg/DisparityImage): The disparity image computed from the left and right images, for example by ``stereo_image_proc``. Parameters ----------- - * **filename_format** (string, default: "frame%04i.jpg"): File name for - saved images, you must add use '%04i' for sequence number. - * **image_transport** (string, default: raw): Image transport to use. - * **sec_per_frame** (double, default: 0.1): Seconds between saved frames. +^^^^^^^^^^ +* **image_transport** (string, default: ``raw``): Transport used to subscribe to the left and right images. +* **approximate_sync** (bool, default: false): Use approximate synchronization. Set to true if the three images do not have exactly the same timestamp. +* **queue_size** (int, default: 5): Size of the synchronization queue of each topic. Raise it if the disparity image takes long to compute, or if the network is slow. +* **autosize** (bool, default: true): If true, the windows have the size of the images and cannot be resized. +* **filename_format** (string, default: ``{}{:04}.jpg``): Name of the saved images, in ``std::format`` syntax. ``{}`` is replaced by ``left``, ``right`` or ``disp``, and ``{:04}`` by the image number. -image_view::ImageViewNode -------------------------- -Simple image viewer for ROS sensor_msgs/Image topics. Node name -is ``image_view``. +.. _DisparityViewNode: + +image_view::DisparityViewNode +----------------------------- + +Shows a disparity image, color-mapped between its ``min_disparity`` and ``max_disparity``: the largest disparities, the closest points, are red. +The disparity image must be ``32FC1``, and its ``min_disparity`` and ``max_disparity`` fields must be set. +Executable: ``disparity_view``. Default node name: ``disparity_view_node``. Subscribed Topics ^^^^^^^^^^^^^^^^^ - * **image** (sensor_msgs/Image): Image topic to visualize. +* **image** (stereo_msgs/msg/DisparityImage): The disparity image. Subscribed with a reliable QoS, without ``image_transport``. Parameters ^^^^^^^^^^ - * **autosize** (bool, default: false): Whether the window should autosize - itself to the image or be resizeable by the user. - * **filename_format** (string, default: "frame%04i.jpg"): printf-style - format for saved image names. Use to control name, location and format - of saved images. - * **image_transport** (string, default: raw): Image transport to use. - * **window_name** (string, default: name of the image topic): - The name of the display window. +* **window_name** (string, default: the resolved name of ``image``): Title of the window. +* **autosize** (bool, default: false): If true, the window has the size of the image and cannot be resized. + +.. _ImageSaverNode: image_view::ImageSaverNode -------------------------- -This tool allows you to save images as jpg/png file from streaming -(ROS sensor_msgs/Image topic) to a file. From command line, you -can run with: - -.. code-block:: bash - - ros2 run image_view image_saver --ros-args -r image:=[your topic] -or see this answer to control the timing of capture. +Saves images to files: all of them, on request, or between a start and an end (see :ref:`known-issues`). +If a ``camera_info`` topic is published next to the image, the calibration is also saved, in a ``.ini`` file with the same name as the image. +Executable: ``image_saver``. Default node name: ``image_saver_node``. Subscribed Topics ^^^^^^^^^^^^^^^^^ - * **image** (sensor_msgs/Image): Image topic to visualize. +* **image** (sensor_msgs/msg/Image): The images to save. +* **camera_info** (sensor_msgs/msg/CameraInfo): Optional. The calibration of the camera, in the same namespace as ``image``. Services ^^^^^^^^ - * **save** (std_srvs/Empty): Save images, you need to set - the ``save_all_images`` parameter to false. - * **start** (std_srvs/Trigger): Start saving images. - * **end** (std_srvs/Trigger): Stop saving images. +* **save** (std_srvs/srv/Empty): Save the next image. Only useful with ``save_all_image:=false``. +* **start** (std_srvs/srv/Trigger): Start saving images. Only with ``request_start_end:=true``. +* **end** (std_srvs/srv/Trigger): Stop saving images. Only with ``request_start_end:=true``. Parameters ----------- - * **encoding** (string, default:"bgr8"): Encoding type of input image topic. - * **filename_format** (string, default: "left%04i.jpg"): File name for - saved images, you can use '%04i' for sequence number, and '%s' for default - file format, you can use 'jpg' ,'png', 'pgm' as filename suffixes. - * **image_transport** (string, default: raw): Image transport to use. - * **save_all_images** (bool, default: true): If set to false, images - are only saved when 'save' service is called. - * **stamped_filename** (bool, default: false): If set to true, a timestamp - is appended to each filename. - * **request_start_end** (bool, default: false): If set to true, the start - and end services will be advertised and can be used to start and Stop - saving images. NOTE: ``save_all_images`` must be set to true, or these - services won't do anything. - -image_view::StereoImageViewNode -------------------------------- -Viewer for stereo images. Shows the synchronized left/right image pair -and the disparity image (color-mapped) computed from them. -Node name is ``stereo_image_view``. - -It is expected that ```` and ```` will be remapped to the -appropriate names (as show in :ref:`Viewing Stereo Images`). +^^^^^^^^^^ +* **image_transport** (string, default: ``raw``): Transport used to subscribe to ``image``. +* **filename_format** (string, default: ``left{:04}.{}``): Name of the saved images, in ``std::format`` syntax. ``{:04}`` is replaced by the image number and ``{}`` by ``jpg``. + To save in another format, write the extension, for example ``image{:04}.png``. +* **encoding** (string, default: ``bgr8``): Encoding to which the images are converted before being saved. +* **save_all_image** (bool, default: true): If true, every image is saved. If false, an image is saved only when the ``save`` service is called. +* **request_start_end** (bool, default: false): If true, the ``start`` and ``end`` services are advertised and only the images received between them are saved. ``save_all_image`` must be true. +* **stamped_filename** (bool, default: false): If true, the current time, in nanoseconds, is added at the beginning of the file names. + +.. _VideoRecorderNode: + +image_view::VideoRecorderNode +----------------------------- + +Records an image topic to a video file, with OpenCV's ``cv::VideoWriter``. +By default it records an MJPEG video in an AVI container at 15 frames per second, to ``output.avi`` in the current directory. +The file is closed when the node is stopped, for example with ``Ctrl+C``. +Executable: ``video_recorder``. Default node name: ``video_recorder_node``. Subscribed Topics ^^^^^^^^^^^^^^^^^ - * **/left/** (sensor_msgs/Image): The left image topic. - * **/right/** (sensor_msgs/Image): The right image topic. - * **/disparity** (stereo_msgs/DisparityImage): The disparity image - computed from the left/right stereo pair. +* **image** (sensor_msgs/msg/Image): The images to record. They must have a timestamp. Parameters ^^^^^^^^^^ - * **approximate_sync** (bool, default: false): Whether to use approximate - synchronization. Set to true if the left and right cameras do not - produce exactly synced timestamps. - * **autosize** (bool, default: false): Whether the window should autosize - itself to the image or be resizeable by the user. - * **filename_format** (string, default: "%s%04i.jpg"): printf-style - format for saved image names. Use to control name, location and format - of saved images. The string argument is "left" or "right". - * **image_transport** (string, default: raw): Image transport to use. - * **queue_size** (int, default: 5): Size of message queue for each - synchronized topic. You may need to raise this if disparity processing - takes too long, or if there are significant network delays. +* **image_transport** (string, default: ``raw``): Transport used to subscribe to ``image``. +* **filename** (string, default: ``output.avi``): Path and name of the video file. +* **stamped_filename** (bool, default: false): If true, the current time, in nanoseconds, is added at the beginning of the file name. +* **fps** (double, default: 15.0): Frame rate of the video. Images closer than ``1 / fps`` seconds to the previous recorded one are skipped. +* **codec** (string, default: ``MJPG``): The `FOURCC `_ code of the codec, 4 characters. It must be supported by your OpenCV build. +* **encoding** (string, default: ``bgr8``): Encoding to which the images are converted before being recorded. +* **colormap** (int, default: -1): Colormap for depth images: -1 for none, or a ``cv::ColormapTypes`` value, for example 2 for ``JET``. +* **min_depth_range** (double, default: 0.0) and **max_depth_range** (double, default: 0.0): Range of depths recorded, for depth images. +* **use_dynamic_depth_range** (bool, default: false): If true, the range of depths is computed from each image. + +.. _ExtractImagesNode: -image_view::VideoRecorderNode +image_view::ExtractImagesNode ----------------------------- -This tool allows you to record a video stream (ROS sensor_msgs/Image topic) -to a file. It relies on OpenCV's VideoWriter class. With the default options, -it encodes the video as MPG, encapsulated in a AVI container at 15 fps, -and produces a file called output.avi in the current directory. + +Saves images to files, at most one every ``sec_per_frame`` seconds. +It currently stops at startup, see :ref:`known-issues`; use ``image_saver`` instead. +Executable: ``extract_images``. Default node name: ``extract_images_node``. Subscribed Topics ^^^^^^^^^^^^^^^^^ - * **image** (sensor_msgs/Image): Image topic to save to file. +* **image** (sensor_msgs/msg/Image): The images to save. + +Parameters +^^^^^^^^^^ +* **image_transport** (string, default: ``raw``): Transport used to subscribe to ``image``. +* **filename_format** (string, default: ``frame{:04}.jpg``): Name of the saved images, in ``std::format`` syntax. +* **sec_per_frame** (double, default: 0.1): Minimum time between two saved images, in seconds. + +extract_images_sync +------------------- + +Python script that saves the images of several topics, synchronized by timestamp, as ``frame0000_0.jpg``, ``frame0000_1.jpg``, ... +It currently stops at startup, see :ref:`known-issues`. Parameters ^^^^^^^^^^ - * **codec** (string, default: MJPG): The FOURCC identifier of the codec. - * **encoding** (string, default:"bgr8"): Encoding type of input image topic. - * **filename** (string, default: output.avi): Path and name of the - output video. - * **fps** (int, default: 15): Framerate of the video. - * **image_transport** (string, default: raw): Image transport to use. - * **queue_size** (int, default: 5): Size of message queue for each - synchronized topic. You may need to raise this if disparity processing - takes too long, or if there are significant network delays. +* **inputs** (string array): The image topics to save. +* **filename_format** (string, default: ``frame%04i_%i.jpg``): Name of the saved images, in ``printf`` syntax: the first number is the image number, the second the index of the topic in ``inputs``. +* **sec_per_frame** (double, default: 0.0): Minimum time between two saved sets of images, in seconds. ``0`` saves all of them. +* **approximate_sync** (bool, default: false): Use approximate synchronization, with a tolerance of 0.1 seconds. +* **do_dynamic_scaling** (bool, default: false): Scale the values of depth and floating point images to the full range. diff --git a/image_view/doc/conf.py b/image_view/doc/conf.py index 065619e02..a1e1cbdcb 100644 --- a/image_view/doc/conf.py +++ b/image_view/doc/conf.py @@ -12,182 +12,39 @@ # See the License for the specific language governing permissions and # limitations under the License. -# -*- coding: utf-8 -*- + +# Sphinx configuration for the image_view package documentation. # -# Configuration file for the Sphinx documentation builder. +# This file is not used directly: rosdoc2 exec()s it from a generated conf.py +# and then adds (or overrides) settings such as the project name, the version +# (both taken from package.xml), the theme and the breathe/exhale configuration +# used for the C++ API. Build the documentation with: # -# This file does only contain a selection of the most common options. For a -# full list see the documentation: -# http://www.sphinx-doc.org/en/master/config - -# -- Path setup -------------------------------------------------------------- - -# If extensions (or modules to document with autodoc) are in another directory, -# add these directories to sys.path here. If the directory is relative to the -# documentation root, use os.path.abspath to make it absolute, like shown here. -import os -import sys -sys.path.insert(0, os.path.abspath('.')) - - -# -- Project information ----------------------------------------------------- - -project = 'image_view' -copyright = '2008-2024, Open Source Robotics Foundation, Inc.' # noqa -author = 'Open Source Robotics Foundation, Inc.' - -# The short X.Y version -version = '' -# The full version, including alpha/beta/rc tags -release = '3.2.1' - +# rosdoc2 build --package-path # -- General configuration --------------------------------------------------- -# If your documentation needs a minimal Sphinx version, state it here. -# -# needs_sphinx = '1.0' - -# Add any Sphinx extension module names here, as strings. They can be -# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom -# ones. extensions = [ - 'sphinx.ext.autodoc', - 'sphinx.ext.autosummary', - 'sphinx.ext.doctest', - 'sphinx.ext.coverage', 'sphinx_rtd_theme', ] -# Add any paths that contain templates here, relative to this directory. -templates_path = ['_templates'] - -# The suffix(es) of source filenames. -# You can specify multiple suffix as a list of string: -# -# source_suffix = ['.rst', '.md'] source_suffix = '.rst' - -# The master toctree document. master_doc = 'index' -# The language for content autogenerated by Sphinx. Refer to documentation -# for a list of supported languages. -# -# This is also used if you do content translation via gettext catalogs. -# Usually you set "language" from the command line for these cases. -language = None - -# List of patterns, relative to source directory, that match files and -# directories to ignore when looking for source files. -# This pattern also affects html_static_path and html_extra_path. -exclude_patterns = [] +# rosdoc2 copies this directory a second time under 'user_docs/' and generates +# 'user_docs.rst' / '__readme_include.rst' wrappers for packages that do not +# ship their own index. This one does, and index.rst already links the +# tutorials and the API reference, so exclude the duplicate tree. +exclude_patterns = ['user_docs', 'user_docs.rst', 'user_docs_tutorials.rst', + '__readme_include.rst'] -# The name of the Pygments (syntax highlighting) style to use. -pygments_style = None +project = 'image_view' +copyright = '2008-2024, Open Source Robotics Foundation, Inc.' # noqa: A001 +author = 'Open Source Robotics Foundation, Inc.' +pygments_style = 'sphinx' # -- Options for HTML output ------------------------------------------------- -# The theme to use for HTML and HTML Help pages. See the documentation for -# a list of builtin themes. -# html_theme = 'sphinx_rtd_theme' - -# Theme options are theme-specific and customize the look and feel of a theme -# further. For a list of options available for each theme, see the -# documentation. -# -# html_theme_options = {} - -# Add any paths that contain custom static files (such as style sheets) here, -# relative to this directory. They are copied after the builtin static files, -# so a file named "default.css" will overwrite the builtin "default.css". -html_static_path = [] - -# Custom sidebar templates, must be a dictionary that maps document names -# to template names. -# -# The default sidebars (for documents that don't match any pattern) are -# defined by theme itself. Builtin themes are using these templates by -# default: ``['localtoc.html', 'relations.html', 'sourcelink.html', -# 'searchbox.html']``. -# -# html_sidebars = {} - - -# -- Options for HTMLHelp output --------------------------------------------- - -# Output file base name for HTML help builder. htmlhelp_basename = 'image_view_doc' - - -# -- Options for LaTeX output ------------------------------------------------ - -latex_elements = { - # The paper size ('letterpaper' or 'a4paper'). - # - # 'papersize': 'letterpaper', - - # The font size ('10pt', '11pt' or '12pt'). - # - # 'pointsize': '10pt', - - # Additional stuff for the LaTeX preamble. - # - # 'preamble': '', - - # Latex figure (float) alignment - # - # 'figure_align': 'htbp', -} - - -# -- Options for manual page output ------------------------------------------ - -# One entry per manual page. List of tuples -# (source start file, name, description, authors, manual section). -man_pages = [ - (master_doc, 'image_view', 'image_view Documentation', - [author], 1) -] - - -# -- Options for Texinfo output ---------------------------------------------- - -# Grouping the document tree into Texinfo files. List of tuples -# (source start file, target name, title, author, -# dir menu entry, description, category) -texinfo_documents = [ - (master_doc, 'image_view', 'image_view Documentation', - author, 'image_view', 'ROS 2 components for visualising images.', - 'Miscellaneous'), -] - - -# -- Options for Epub output ------------------------------------------------- - -# Bibliographic Dublin Core info. -epub_title = project - -# The unique identifier of the text. This can be a ISBN number -# or the project homepage. -# -# epub_identifier = '' - -# A unique identification for the text. -# -# epub_uid = '' - -# A list of files that should not be packed into the epub file. -epub_exclude_files = ['search.html'] - - -# -- Extension configuration ------------------------------------------------- - -autoclass_content = 'both' - -autodoc_default_options = { - 'members': True, # document members - 'undoc-members': True, # also document members without documentation -} diff --git a/image_view/doc/docutils.conf b/image_view/doc/docutils.conf new file mode 100644 index 000000000..fe7028b08 --- /dev/null +++ b/image_view/doc/docutils.conf @@ -0,0 +1,4 @@ +[restructuredtext parser] +# rosdoc2/exhale emits the generated class hierarchy as a single very long line, +# which can exceed docutils' 10000-character default. +line_length_limit: 200000 diff --git a/image_view/doc/images/image_view.png b/image_view/doc/images/image_view.png new file mode 100644 index 000000000..8bcefda7e Binary files /dev/null and b/image_view/doc/images/image_view.png differ diff --git a/image_view/doc/index.rst b/image_view/doc/index.rst index ddbc0b9d3..7f659706a 100644 --- a/image_view/doc/index.rst +++ b/image_view/doc/index.rst @@ -1,68 +1,130 @@ -Overview -======== +image_view +========== -This package contains a number of ROS 2 components and nodes for viewing image topics. +``image_view`` provides simple tools to look at image topics and to save them to files: a viewer for images, a viewer for stereo pairs and disparity images, and tools to save images and record videos. -Viewing a Single Image Topic ----------------------------- +.. image:: images/image_view.png + :width: 400px -.. code-block:: bash +.. code-block:: console - ros 2 run image_view image_view --ros-args -r image:= + $ ros2 run image_view image_view --ros-args -r image:=/camera/image_raw -For example, to view raw images on the topic ``/camera/image``, use: - -.. code-block:: bash - - ros2 run image_view image_view --ros-args -r image:=/camera/image - -You may save the current image by right-clicking on the display window. By default, -images will be saved as ``frame0000.jpg``, ``frame0001.jpg``, .... - -If you want to view a compressed image stream (usually a good idea over wireless!) -using the capabilities of ``image_transport``, specify the transport type as a -command-line parameter. For example, if ``theora_image_transport`` is built on the -publisher's side, you can use theora transport: - -.. code-block:: bash - - ros2 run image_view image_view --ros-args -r image:=/camera/image -p image_transport:=theora - -.. _`Viewing Stereo Images`: - -Viewing Stereo Images ---------------------- - -.. code-block:: bash - - ros2 run image_view stereo_view --ros-args -p stereo:= -p image:= - -For example, to view stereo image pairs on topics -``/my_stereo_cam/left/image_rect_color`` and ``/my_stereo_cam/right/image_rect_color``, -use: - -.. code-block:: bash - - ros2 run image_view stereo_view --ros-args -r stereo:=/my_stereo_cam -r image:=image_rect_color - -``stereo_view`` also shows the disparity image computed from the stereo pair - color-mapped for clarity. - -You may save the current image pair by right-clicking on any display window. -By default, images will be saved as ``left0000.jpg``, ``right0000.jpg``, ``disp0000.jpg``, -``left0001.jpg``, ``right0001.jpg``, ``disp0001.jpg``.... As with ``image_view``, -you can specify an image transport to use for the left and right image as an optional -parameter. +For a more complete image viewer, see also `rqt_image_view `_. +See :doc:`components` for the topics and parameters of each tool, and :doc:`tutorials` to get started. .. toctree:: :maxdepth: 2 self components - image_view - -Indices and tables -================== - -* :ref:`genindex` -* :ref:`search` + tutorials + references + Package information + +1. Tools +-------- + +Each tool is an executable, and also a component that can be loaded in a container. + +.. list-table:: + :header-rows: 1 + :widths: 22 33 45 + + * - Executable + - Component + - Description + * - ``image_view`` + - :ref:`image_view::ImageViewNode ` + - Shows an image topic in a window. Right-click to save the image. + * - ``stereo_view`` + - :ref:`image_view::StereoViewNode ` + - Shows the left and right images of a stereo camera and their disparity image, synchronized. + * - ``disparity_view`` + - :ref:`image_view::DisparityViewNode ` + - Shows a ``stereo_msgs/msg/DisparityImage``, color-mapped. + * - ``image_saver`` + - :ref:`image_view::ImageSaverNode ` + - Saves images to files: all of them, on request with a service, or between a start and an end. + * - ``video_recorder`` + - :ref:`image_view::VideoRecorderNode ` + - Records an image topic to a video file. + * - ``extract_images`` + - :ref:`image_view::ExtractImagesNode ` + - Saves images to files, at most one every ``sec_per_frame`` seconds. Currently broken, see :ref:`known-issues`. + * - ``extract_images_sync`` + - (Python script) + - Saves synchronized images of several topics. Currently broken, see :ref:`known-issues`. + +All the tools subscribe to a topic called ``image``: remap it to the topic you want, for example ``-r image:=/camera/image_raw``. + +2. Viewing images +----------------- + +``image_view`` converts the images for display: + +* Color and monochrome images are shown as they are; ``rgb8`` and ``yuv422`` images are converted to ``bgr8``. +* Bayer images are shown as raw monochrome images, without debayering. + To see them in color, debayer them with `image_proc `_. + +To use less bandwidth, for example over WiFi, subscribe to a compressed transport with the ``image_transport`` parameter. +Remap ``image`` to the base topic, not to the ``compressed`` sub-topic: + +.. code-block:: console + + $ ros2 run image_view image_view --ros-args -r image:=/camera/image_raw -p image_transport:=compressed + +The ``compressed`` transport is provided by `image_transport_plugins `_, which must be installed on both computers. + +``image_view`` subscribes with the sensor data QoS (best effort), so it receives images from both reliable and best effort publishers. +With large images or over a lossy network, a best effort subscription can lose many images, and the image is then updated only from time to time. + +Right-click on the window to save the displayed image, as ``frame0000.jpg``, ``frame0001.jpg``, ... in the current directory; the ``filename_format`` parameter changes the name, the directory and the format. +Closing the window stops ``image_view``. + +``image_view`` also republishes each image it receives on ``output``. +With ``gui:=false``, it opens no window. + +3. Saving images and videos +--------------------------- + +``image_saver`` saves images to files, by default all of them, as ``left0000.jpg``, ``left0001.jpg``, ... in the current directory. +If a ``camera_info`` topic is published next to the image, it also saves the calibration in a ``.ini`` file with the same name, for example ``left0001.ini``. + +It has three modes: + +* **All images** (the default): every image received is saved. +* **On request**: with ``save_all_image:=false``, the next image is saved each time the ``save`` service (``std_srvs/srv/Empty``) is called. +* **Between a start and an end**: with ``request_start_end:=true``, the images whose timestamp is between the calls to the ``start`` and ``end`` services (``std_srvs/srv/Trigger``) are saved. + This mode is currently broken, see :ref:`known-issues`. + +``video_recorder`` records an image topic to a video file, by default ``output.avi``, an MJPEG video at 15 frames per second. +The file is closed when ``video_recorder`` is stopped with ``Ctrl+C``. + +* The video always plays at ``fps`` frames per second, whatever the rate of the images. + If the images arrive faster, ``video_recorder`` uses their timestamps to keep one image every ``1 / fps`` seconds. + If they arrive slower, the video plays faster than real time. +* Images with a zero timestamp are never recorded. +* Depth images (``16UC1`` or ``32FC1``) are converted to color: set ``max_depth_range`` to the farthest depth to show (in millimeters for ``16UC1``, in meters for ``32FC1``) or ``use_dynamic_depth_range:=true``, and optionally a ``colormap``. + Without them, depth images are recorded almost black. + +.. _known-issues: + +4. Known issues +--------------- + +* **image_view cannot show depth images.** + ``16UC1`` and ``32FC1`` images are not displayed, and the log shows ``Unable to convert '32FC1' image for display: 'cv_bridge.cvtColorForDisplay() does not have an output encoding that is color or mono ...'``, at most once every 30 seconds. + The ``colormap``, ``min_image_value`` and ``max_image_value`` parameters, which are meant for depth images, have no visible effect. + Use ``rqt_image_view`` to view depth images. +* **The min_image_value and max_image_value parameters of image_view are integers.** + Their description says double, but ``-p max_image_value:=5.0`` stops ``image_view`` with an ``InvalidParameterTypeException``. + Give integer values, for example ``-p max_image_value:=5``. +* **extract_images stops at startup** with a ``ParameterNotDeclaredException`` (``transport``). + Use ``image_saver`` instead. +* **extract_images_sync stops at startup** with ``TypeError: when declaring parameter named 'inputs' ...``. +* **image_saver stops with request_start_end:=true** when the first image arrives after a call to ``start``, with ``can't compare times with different time sources``. +* **stamped_filename of image_saver does not work with a directory.** + The timestamp is added in front of the whole ``filename_format``: ``images/left0000.jpg`` becomes ``images/left0000.jpg``. + The image is not saved, but the ``.ini`` calibration is, in a new ``images`` directory. + Use ``stamped_filename`` only with a ``filename_format`` without a directory. diff --git a/image_view/doc/references.rst b/image_view/doc/references.rst new file mode 100644 index 000000000..b1c9293da --- /dev/null +++ b/image_view/doc/references.rst @@ -0,0 +1,7 @@ +References +========== + +.. toctree:: + :maxdepth: 1 + + C++ API diff --git a/image_view/doc/tutorials.rst b/image_view/doc/tutorials.rst new file mode 100644 index 000000000..694e851c0 --- /dev/null +++ b/image_view/doc/tutorials.rst @@ -0,0 +1,110 @@ +Tutorials +========= + +These tutorials use `image_publisher `_ to publish a picture as if it came from a camera, so they can be done without a camera. +With a camera, skip the first step and use the topic of your camera instead of ``/camera/image_raw``. + +Install ``image_publisher`` if needed: + +.. code-block:: console + + $ sudo apt install ros-rolling-image-publisher + +Viewing and saving an image +--------------------------- + +1. In a terminal, publish a picture on ``/camera/image_raw``, 10 times per second: + + .. code-block:: console + + $ ros2 run image_publisher image_publisher_node \ + $(ros2 pkg prefix --share image_publisher)/launch/splash.png \ + --ros-args -r __ns:=/camera + +2. In another terminal, show it: + + .. code-block:: console + + $ ros2 run image_view image_view --ros-args -r image:=/camera/image_raw + + A window called ``/camera/image_raw`` opens and shows the picture. + +3. Right-click on the window to save the image. + ``image_view`` logs the name of the file, in the directory where it was started: + + .. code-block:: console + + [INFO] [image_view_node]: Saved image frame0000.jpg + + To save in another format or directory, start ``image_view`` with a ``filename_format``, for example ``-p filename_format:=/tmp/camera_{:04}.png``. + +4. Close the window to stop ``image_view``. + +Saving images on request +------------------------ + +``image_saver`` can save an image only when a service is called, for example to take a snapshot from a script. + +1. Publish a picture on ``/camera/image_raw``, as in the previous tutorial: + + .. code-block:: console + + $ ros2 run image_publisher image_publisher_node \ + $(ros2 pkg prefix --share image_publisher)/launch/splash.png \ + --ros-args -r __ns:=/camera + +2. In another terminal, in an empty directory, start ``image_saver`` with ``save_all_image`` set to false, so that it only saves images on request: + + .. code-block:: console + + $ mkdir snapshots && cd snapshots + $ ros2 run image_view image_saver --ros-args \ + -r image:=/camera/image_raw \ + -p save_all_image:=false \ + -p filename_format:=snapshot{:04}.png + +3. In a third terminal, call the ``save`` service twice: + + .. code-block:: console + + $ ros2 service call /save std_srvs/srv/Empty + $ ros2 service call /save std_srvs/srv/Empty + + Each call saves the next image: + + .. code-block:: console + + $ ls snapshots + snapshot0000.ini snapshot0000.png snapshot0001.ini snapshot0001.png + + ``image_publisher`` also publishes ``/camera/camera_info``, so ``image_saver`` saves the calibration next to each image, in ``.ini`` files. + +Recording a video +----------------- + +1. Publish a picture on ``/camera/image_raw``, as in the first tutorial: + + .. code-block:: console + + $ ros2 run image_publisher image_publisher_node \ + $(ros2 pkg prefix --share image_publisher)/launch/splash.png \ + --ros-args -r __ns:=/camera + +2. In another terminal, record it. + ``image_publisher`` publishes 10 images per second, so set ``fps`` to 10 to get a video that plays in real time: + + .. code-block:: console + + $ ros2 run image_view video_recorder --ros-args \ + -r image:=/camera/image_raw \ + -p fps:=10.0 -p filename:=camera.avi + [INFO] [video_recorder_node]: Waiting for topic /camera/image_raw... + [INFO] [video_recorder_node]: Starting to record MJPG video at 260x400@10.00 fps. Press Ctrl+C to stop recording. + +3. After a few seconds, press ``Ctrl+C`` to stop recording: + + .. code-block:: console + + Video saved as: camera.avi + + Open ``camera.avi`` with any video player. diff --git a/image_view/include/image_view/disparity_view_node.hpp b/image_view/include/image_view/disparity_view_node.hpp index d8ab8bc34..f29630e91 100644 --- a/image_view/include/image_view/disparity_view_node.hpp +++ b/image_view/include/image_view/disparity_view_node.hpp @@ -25,10 +25,15 @@ namespace image_view { +/// Displays a ``stereo_msgs/msg/DisparityImage`` topic, color-mapped, in a window. +/** + * Also available as the ``disparity_view`` executable. + */ class DisparityViewNode : public rclcpp::Node { public: + /// Declare the parameters and subscribe to the input topics. explicit DisparityViewNode(const rclcpp::NodeOptions & options); explicit DisparityViewNode(const DisparityViewNode &) = default; explicit DisparityViewNode(DisparityViewNode &&) = default; diff --git a/image_view/include/image_view/extract_images_node.hpp b/image_view/include/image_view/extract_images_node.hpp index 37d07ffbe..5dbc3df42 100644 --- a/image_view/include/image_view/extract_images_node.hpp +++ b/image_view/include/image_view/extract_images_node.hpp @@ -59,10 +59,15 @@ namespace image_view { +/// Saves the images of a topic to files, at most one every ``sec_per_frame`` seconds. +/** + * Also available as the ``extract_images`` executable. + */ class ExtractImagesNode : public rclcpp::Node { public: + /// Declare the parameters and subscribe to the input topics. explicit ExtractImagesNode(const rclcpp::NodeOptions & options); private: diff --git a/image_view/include/image_view/image_saver_node.hpp b/image_view/include/image_view/image_saver_node.hpp index 5d8c76b2b..8f854ef61 100644 --- a/image_view/include/image_view/image_saver_node.hpp +++ b/image_view/include/image_view/image_saver_node.hpp @@ -60,10 +60,15 @@ namespace image_view { +/// Saves the images of a topic to files, all of them or on request. +/** + * Also available as the ``image_saver`` executable. + */ class ImageSaverNode : public rclcpp::Node { public: + /// Declare the parameters and subscribe to the input topics. explicit ImageSaverNode(const rclcpp::NodeOptions & options); private: diff --git a/image_view/include/image_view/image_view_node.hpp b/image_view/include/image_view/image_view_node.hpp index a98290840..6c5afb473 100644 --- a/image_view/include/image_view/image_view_node.hpp +++ b/image_view/include/image_view/image_view_node.hpp @@ -43,10 +43,16 @@ class ThreadSafeImage cv_bridge::CvImageConstPtr pop(); }; +/// Displays an image topic in a window. +/** + * Subscribes to ``image``, shows it in an OpenCV window and saves the displayed image on a + * right-click. Also available as the ``image_view`` executable. + */ class ImageViewNode : public rclcpp::Node { public: + /// Declare the parameters and subscribe to the input topics. explicit ImageViewNode(const rclcpp::NodeOptions & options); explicit ImageViewNode(const ImageViewNode &) = default; explicit ImageViewNode(ImageViewNode &&) = default; diff --git a/image_view/include/image_view/stereo_view_node.hpp b/image_view/include/image_view/stereo_view_node.hpp index 463ed1116..1c557449a 100644 --- a/image_view/include/image_view/stereo_view_node.hpp +++ b/image_view/include/image_view/stereo_view_node.hpp @@ -72,10 +72,15 @@ using stereo_msgs::msg::DisparityImage; using message_filters::sync_policies::ExactTime; using message_filters::sync_policies::ApproximateTime; +/// Displays the left and right images of a stereo camera and their disparity image. +/** + * Also available as the ``stereo_view`` executable. + */ class StereoViewNode : public rclcpp::Node { public: + /// Declare the parameters and subscribe to the input topics. explicit StereoViewNode(const rclcpp::NodeOptions & options); explicit StereoViewNode(const StereoViewNode &) = default; explicit StereoViewNode(StereoViewNode &&) = default; diff --git a/image_view/include/image_view/video_recorder_node.hpp b/image_view/include/image_view/video_recorder_node.hpp index 52d6b5bd7..36ca05d48 100644 --- a/image_view/include/image_view/video_recorder_node.hpp +++ b/image_view/include/image_view/video_recorder_node.hpp @@ -25,10 +25,15 @@ namespace image_view { +/// Records an image topic to a video file. +/** + * Also available as the ``video_recorder`` executable. + */ class VideoRecorderNode : public rclcpp::Node { public: + /// Declare the parameters and subscribe to the input topics. explicit VideoRecorderNode(const rclcpp::NodeOptions & options); explicit VideoRecorderNode(const VideoRecorderNode &) = default; explicit VideoRecorderNode(VideoRecorderNode &&) = default; diff --git a/image_view/mainpage.dox b/image_view/mainpage.dox deleted file mode 100644 index 87cfb37ed..000000000 --- a/image_view/mainpage.dox +++ /dev/null @@ -1,11 +0,0 @@ -/** -@mainpage image_view - -@htmlinclude manifest.html - -@b image_view is a simple utility for viewing an image topic. For usage see -http://www.ros.org/wiki/image_view. - -Currently this package has no public code API. - -*/ diff --git a/image_view/package.xml b/image_view/package.xml index e7f7208f7..8ff2143c8 100644 --- a/image_view/package.xml +++ b/image_view/package.xml @@ -13,7 +13,7 @@ Michael Ferguson BSD - https://index.ros.org/p/image_view/ + https://docs.ros.org/en/rolling/p/image_view/ https://github.com/ros-perception/image_pipeline/issues https://github.com/ros-perception/image_pipeline Patrick Mihelich @@ -37,6 +37,6 @@ ament_cmake - + rosdoc2.yaml diff --git a/image_view/rosdoc.yaml b/image_view/rosdoc.yaml deleted file mode 100644 index 976fdf0a6..000000000 --- a/image_view/rosdoc.yaml +++ /dev/null @@ -1,4 +0,0 @@ - - builder: doxygen - name: C++ API - output_dir: c++ - file_patterns: '*.c *.cpp *.h *.cc *.hh *.dox' diff --git a/image_view/rosdoc2.yaml b/image_view/rosdoc2.yaml new file mode 100644 index 000000000..83440b65b --- /dev/null +++ b/image_view/rosdoc2.yaml @@ -0,0 +1,26 @@ +## This 'attic section' self-documents this file's type and version. +type: 'rosdoc2 config' +version: 1 + +--- + +settings: + ## Generate the standard package index (package.xml metadata, README, CHANGELOG, ...). + generate_package_index: true + + ## The C++ API is documented because of the 'ament_cmake' build type. + always_run_doxygen: false + + ## There is no Python API to document. + always_run_sphinx_apidoc: false + +builders: + - doxygen: { + name: 'image_view Public C/C++ API', + output_dir: 'generated/doxygen' + } + - sphinx: { + name: 'image_view', + doxygen_xml_directory: 'generated/doxygen/xml', + output_dir: '' + }