Skip to content

Commit 4e80764

Browse files
authored
Merge pull request #3 from ctu-vras/refactor-filter-bag
cras_bag_tools: filter_bag: Refactor filter_bag
2 parents 84023ca + 54dd56f commit 4e80764

26 files changed

+1971
-644
lines changed

cras_bag_tools/README.md

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,99 @@ Print total cumulative serialized message size per topic.
3838
- `-c`, `--csv`: Output as CSV.
3939
- `-a`, `--sort-alphabetical`: Sort by topic names (default is by topic sizes).
4040

41+
### extract_images
42+
43+
Extract image topics from bag file to image or video files.
44+
45+
#### Usage
46+
47+
rosrun cras_bag_tools extract_images [-h] [--out-format OUT_FORMAT] [--verbose] bag_file output_dir [image_topics [image_topics ...]]
48+
49+
* `bag_file`: The bag to read.
50+
* `output_dir`: Directory where all generated files should be stored.
51+
* `image_topics`: Zero or more topics to convert. If zero, all image topics are converted. Each image topic can be
52+
followed by additional configuration in the form
53+
`TOPIC:OUT_FORMAT:COMPRESSION:ENCODING:IN_FPS:OUT_FPS:PIX_FMT` (only `TOPIC` is required)
54+
* `OUT_FORMAT`: Format of the exported images/video (e.g. `jpg`, `mp4` etc.). Defaults to `--out-format`.
55+
* `COMPRESSION`: Compression level. The meaning depends on `OUT_FORMAT`. JPG has 0-100, PNG 0-9, MP4 0-51 (CRF).
56+
* `ENCODING`: Pixel format to convert the images to. E.g. `bgr8` or `mono8`. `passthrough` means keeping the format.
57+
Empty string retains the format for raw images and converts compressed images to the recorded raw format
58+
in their `.format` field if it is available. Defaults to `passthrough`.
59+
* Following options are for video formats only.
60+
* `IN_FPS`: Framerate of the topic images. If not set, it is estimated from the frequency of the messages in the bag.
61+
You can set the FPS higher than the original, effectively speeding up the video.
62+
* `OUT_FPS`: Output framerate. Defaults to `IN_FPS`.
63+
* `PIX_FMT`: The `-pix_fmt` output option for ffmpeg, i.e. the pixel format of the video stream. Defaults to
64+
`yuvj420p`.
65+
* `-h`: Shows help.
66+
* `--out-format`: Default format for all topics (e.g. `jpg`, `mp4` etc.). Defaults to `jpg`.
67+
* `--verbose`: Print various details during execution.
68+
69+
#### Example command
70+
71+
```bash
72+
# Convert all image topics in the bag to a series of JPEG images in folder imgs/
73+
rosrun cras_bag_tools extract_images spot_2022-10-27-10-35-46.video.bag imgs
74+
75+
# Convert topic /rviz/fixed_image/compressed to an MP4 video
76+
rosrun cras_bag_tools extract_images spot_2022-10-27-10-35-46.video.bag . /rviz/fixed_image/compressed:mp4:23:passthrough:25
77+
```
78+
79+
### filter_bag
80+
81+
Process bag files with a configured set of filters.
82+
83+
#### Usage
84+
85+
usage: filter_bag [-h] [-c CONFIG [CONFIG ...]] [-o OUT_FORMAT] [--lz4] [--bz2] [--no-copy-params] [--list-yaml-keys] [--list-filters] [--merge-initial-static-tf [DURATION]]
86+
[--throttle TOPIC RATE [TOPIC RATE ...]] [-i INCLUDE_TOPICS [INCLUDE_TOPICS ...]] [-e EXCLUDE_TOPICS [EXCLUDE_TOPICS ...]] [--include-types INCLUDE_TYPES [INCLUDE_TYPES ...]]
87+
[--exclude-types EXCLUDE_TYPES [EXCLUDE_TYPES ...]] [--include-tf-parents INCLUDE_TF_PARENTS [INCLUDE_TF_PARENTS ...]]
88+
[--exclude-tf-parents EXCLUDE_TF_PARENTS [EXCLUDE_TF_PARENTS ...]] [--include-tf-children INCLUDE_TF_CHILDREN [INCLUDE_TF_CHILDREN ...]]
89+
[--exclude-tf-children EXCLUDE_TF_CHILDREN [EXCLUDE_TF_CHILDREN ...]] [--decompress-images] [--max-message-size MAX_MESSAGE_SIZE]
90+
[bags [bags ...]]
91+
92+
93+
Positional arguments:
94+
95+
* `bags`: The list of bags to process.
96+
97+
Optional arguments:
98+
* `--list-yaml-keys`: Print a list of all available YAML top-level keys provided by filters.
99+
* `--list-filters`: Print a list of all available filters.
100+
* `--no-copy-params`: If set, no .params file will be copied
101+
* `-i INCLUDE_TOPICS [INCLUDE_TOPICS ...]`, `--include-topics INCLUDE_TOPICS [INCLUDE_TOPICS ...]`: Retain only
102+
these topics
103+
* `-e EXCLUDE_TOPICS [EXCLUDE_TOPICS ...]`, `--exclude-topics EXCLUDE_TOPICS [EXCLUDE_TOPICS ...]`: Remove these topics
104+
* `--include-types INCLUDE_TYPES [INCLUDE_TYPES ...]`: Retain only messages of these types
105+
* `--exclude-types EXCLUDE_TYPES [EXCLUDE_TYPES ...]`: Remove messages of these types
106+
* `--throttle TOPIC RATE [TOPIC RATE ...], --hz TOPIC RATE [TOPIC RATE ...]`: Throttle messages. This argument should be
107+
an even-sized list of pairs `[TOPIC RATE]`.
108+
* `--include-tf-parents INCLUDE_TF_PARENTS [INCLUDE_TF_PARENTS ...]`: Retain only TFs with these frames as parents
109+
* `--exclude-tf-parents EXCLUDE_TF_PARENTS [EXCLUDE_TF_PARENTS ...]`: Remove TFs with these frames as parents
110+
* `--include-tf-children INCLUDE_TF_CHILDREN [INCLUDE_TF_CHILDREN ...]`: Retain only TFs with these frames as children
111+
* `--exclude-tf-children EXCLUDE_TF_CHILDREN [EXCLUDE_TF_CHILDREN ...]`: Remove TFs with these frames as children
112+
* `--max-message-size MAX_MESSAGE_SIZE`: Remove all messages larger than this size `[B]`
113+
* `--merge-initial-static-tf [DURATION]`: Merge a few initial static TFs into one. DURATION specifies the duration of
114+
the initial bag section to be considered for the merging. DURATION defaults to 5 secs.
115+
* `--decompress-images`: Decompress all images
116+
* `-c CONFIG [CONFIG ...]`, `--config CONFIG [CONFIG ...]`: YAML configs of filters
117+
* `-o OUT_FORMAT`, `--out-format OUT_FORMAT`: Template for naming the output bag. Defaults to `{name}.proc{ext}`.
118+
Relative paths will put the bag relative to current directory (not relative to the location of the source bag).
119+
The format string can utilize variables `dirname` (directory of the source bag), `name` (name of the source bag
120+
without extension), `ext` (extension of the source bag (should be `.bag`)).
121+
* `--lz4`: Compress the bag using LZ4 compression.
122+
* `--bz2`: Compress the bag using BZ2 compression (warning: this compression is very slow).
123+
124+
The YAML config files can contain the same keys as the optional CLI arguments (list all of them via `--list-yaml-keys`.
125+
Additionally, YAML configs can contain key `filters` which is a list of additional filters. Each filter is defined as a
126+
dict with the filter class as key and filter configuration as value. See the `config/` folder for examples. List all
127+
available filters via `--list-filters`.
128+
129+
Other filters can be defined by 3rd-party packages via pluginlib. The package has to
130+
`<exec_depend>cras_bag_tools</exec_depend>` and it has to put this line in its `<export>` tag in package.xml:
131+
`<cras_bag_tools filters="$PACKAGE.$MODULE" />`. With this in place, `filter_bag` will search the specified module
132+
for all classes that subclass `cras_bag_tools.MessageFilter` and it will provide these as additional filters.
133+
41134
### fix_msg_defs
42135

43136
Sometimes it can happen that wrong textual definitions of messages are stored in bag files (although the MD5 sums are correct).

cras_bag_tools/config/compress_cams.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# SPDX-License-Identifier: BSD-3-Clause
2+
# SPDX-FileCopyrightText: Czech Technical University in Prague
3+
14
out_format: '{name}.cams_compressed{ext}'
25
compression: lz4
36
filters:

cras_bag_tools/config/decompress_cams.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# SPDX-License-Identifier: BSD-3-Clause
2+
# SPDX-FileCopyrightText: Czech Technical University in Prague
3+
14
out_format: '{name}.cams_decompressed{ext}'
25
compression: lz4
36
filters:
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# SPDX-License-Identifier: BSD-3-Clause
2+
# SPDX-FileCopyrightText: Czech Technical University in Prague
3+
4+
out_format: '{name}.preview{ext}'
5+
compression: lz4
6+
filters:
7+
- DepthImagePreview:
8+
normalize: True
9+
# num_normalization_samples: 0.03

cras_bag_tools/config/fix_spot_cams.yaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1+
# SPDX-License-Identifier: BSD-3-Clause
2+
# SPDX-FileCopyrightText: Czech Technical University in Prague
3+
14
out_format: '{name}.cams_fixed{ext}'
25
compression: lz4
36
filters:
47
- FixSpotCams:
5-
include:
8+
include_topics:
69
- /spot/camera/back/image/compressed
710
- /spot/camera/frontleft/image/compressed
811
- /spot/camera/frontright/image/compressed
Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,21 @@
1-
# Removes topics that contain large sensory outputs (camera images and pointclouds).
1+
# SPDX-License-Identifier: BSD-3-Clause
2+
# SPDX-FileCopyrightText: Czech Technical University in Prague
3+
4+
# Removes topics that contain large sensory outputs (camera images, pointclouds and messages over 100 kB).
25
out_format: '{name}.no_sensors{ext}'
36
compression: lz4
47
filters:
58
- TopicTypes:
6-
exclude:
9+
exclude_types:
710
- sensor_msgs/CompressedImage
811
- sensor_msgs/Image
12+
- sensor_msgs/LaserScan
913
- sensor_msgs/PointCloud
1014
- sensor_msgs/PointCloud2
15+
- Topics:
16+
exclude_topics:
17+
- /os_node/lidar_packets
18+
- /rosout
19+
- /rosout_agg
20+
- MaxMessageSize:
21+
size_limit: 100000
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# SPDX-License-Identifier: BSD-3-Clause
2+
# SPDX-FileCopyrightText: Czech Technical University in Prague
3+
4+
# Removes topics that contain large sensory outputs (camera images, pointclouds and messages over 100 kB).
5+
out_format: '{name}.no_sensors{ext}'
6+
compression: lz4
7+
exclude_types:
8+
- sensor_msgs/CompressedImage
9+
- sensor_msgs/Image
10+
- sensor_msgs/LaserScan
11+
- sensor_msgs/PointCloud
12+
- sensor_msgs/PointCloud2
13+
exclude_topics:
14+
- /os_node/lidar_packets
15+
- /rosout
16+
- /rosout_agg
17+
max_message_size: 100000
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# SPDX-License-Identifier: BSD-3-Clause
2+
# SPDX-FileCopyrightText: Czech Technical University in Prague
3+
4+
out_format: '{name}.cams_recompressed{ext}'
5+
compression: lz4
6+
bags:
7+
- "/media/data/bags/spot_arm_visual_data.bag"
8+
filters:
9+
- DecompressImages: []
10+
- CompressImages:
11+
transport_params:
12+
compressed:
13+
jpeg_quality: 50
14+
png_level: 9
15+
compressedDepth:
16+
format: rvl

cras_bag_tools/config/tf.yaml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1-
out_format: '{dirname}/tf/{name}{ext}'
1+
# SPDX-License-Identifier: BSD-3-Clause
2+
# SPDX-FileCopyrightText: Czech Technical University in Prague
3+
4+
out_format: '{name}.tf{ext}'
25
compression: lz4
6+
merge_initial_static_tf: True
37
filters:
48
- Topics:
5-
include:
9+
include_topics:
610
- /tf
7-
- /tf_static
11+
- /tf_static

cras_bag_tools/doc/conf.py

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,10 @@
11
# Configuration file for the Sphinx documentation builder.
22

33
import os
4-
import time
5-
import catkin_pkg.package
6-
catkin_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
7-
catkin_package = catkin_pkg.package.parse_package(os.path.join(catkin_dir, catkin_pkg.package.PACKAGE_MANIFEST_FILENAME))
4+
os.environ['CRAS_DOCS_COMMON_SPHINX_PACKAGE_PATH'] = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
85

9-
project = catkin_package.name
10-
copyright = time.strftime("%Y") + ', Czech Technical University in Prague'
11-
author = ", ".join([a.name for a in catkin_package.authors])
12-
version = catkin_package.version
13-
release = catkin_package.version
6+
# By default, the ctu-vras theme will be used. To use your custom theme, set
7+
# CRAS_DOCS_COMMON_SPHINX_THEME_PATH and CRAS_DOCS_COMMON_SPHINX_HTML_THEME
148

15-
extensions = ['sphinx.ext.autodoc']
16-
17-
master_doc = 'index'
18-
autoclass_content = 'both'
19-
20-
html_theme = 'default'
9+
# include the master configuration
10+
from cras_docs_common.sphinx_docs_conf import *

0 commit comments

Comments
 (0)