Skip to content
Update getting started with image streams authored by Vsevolod Vlaskine's avatar Vsevolod Vlaskine
[[_TOC_]] [[_TOC_]]
# **cv-cat**: image streaming and processing # **cv-cat**: image streaming and processing
# hello world ## hello world
If your laptop or desktop has a webcam, try: If your laptop or desktop has a webcam, try:
``` ```
...@@ -12,7 +12,7 @@ If you don't have a webcam, pick some video and use **--file some-video.mp4** in ...@@ -12,7 +12,7 @@ If you don't have a webcam, pick some video and use **--file some-video.mp4** in
``` ```
> cv-cat --file some-video.mp4 "view;null" > cv-cat --file some-video.mp4 "view;null"
``` ```
# basic input/output and image filters ## basic input/output and image filters
If you don't specify **null** the images **cv-cat** reads from your camera will be output to stdout in a simple binary format (see **image data format** section below). Try: If you don't specify **null** the images **cv-cat** reads from your camera will be output to stdout in a simple binary format (see **image data format** section below). Try:
``` ```
...@@ -32,8 +32,8 @@ Play back saved images ...@@ -32,8 +32,8 @@ Play back saved images
``` ```
> cat images.bin | cv-cat "view;null" > cat images.bin | cv-cat "view;null"
``` ```
# image data format ## image data format
## example ### example
In previous example **cv-cat** plays back the images as fast as it can, not in realtime. In previous example **cv-cat** plays back the images as fast as it can, not in realtime.
To play back in realtime, let us use [**csv-play**](https://gitlab.com/orthographic/comma/-/wikis/csv/getting-started:-basic-data-manipulations,-ascii-and-binary-data). To play back in realtime, let us use [**csv-play**](https://gitlab.com/orthographic/comma/-/wikis/csv/getting-started:-basic-data-manipulations,-ascii-and-binary-data).
...@@ -52,13 +52,13 @@ Now, let's play back **images.bin** in real time: ...@@ -52,13 +52,13 @@ Now, let's play back **images.bin** in real time:
``` ```
cat images.bin | csv-play --binary t,3ui,s[921600] | cv-cat "timestamp;view;null" cat images.bin | csv-play --binary t,3ui,s[921600] | cv-cat "timestamp;view;null"
``` ```
## binary image format ### binary image format
**snark** uses a custom image format. However, don't be disturbed by that for several reasons: **snark** uses a custom image format. However, don't be disturbed by that for several reasons:
- **snark** image format is **very** simple and compatible with other image and non-image data representations - **snark** image format is **very** simple and compatible with other image and non-image data representations
- **snark** image format is **optional** - **snark** image format is **optional**
- there are easy ways to convert **snark** image format from/to common image, video, and data formats - there are easy ways to convert **snark** image format from/to common image, video, and data formats
The format: **\<header\>\<image\>** The format: **\<header\>\<image\>**
### \<header\> #### \<header\>
Try to output only image headers: Try to output only image headers:
``` ```
> cv-cat --camera --output header-only | csv-from-bin t,3ui | head -n4 > cv-cat --camera --output header-only | csv-from-bin t,3ui | head -n4
...@@ -80,7 +80,8 @@ Outputting number of rows, columns, and image type with each image may look redu ...@@ -80,7 +80,8 @@ Outputting number of rows, columns, and image type with each image may look redu
- by having image size and type, each image record is self-contained - by having image size and type, each image record is self-contained
- each image can be of different size and type (see examples in **image files and file lists** section below) - each image can be of different size and type (see examples in **image files and file lists** section below)
- header is optional (see examples in **\<image\>** section below) - header is optional (see examples in **\<image\>** section below)
### \<image\>
#### \<image\>
The image part of the **snark** image format is simply an uncompressed binary image bitmap. E.g. an 8-byte RGB image 20x10 would have 20x10x3=600 bytes, each 3 bytes representing blue, green, and red components of the pixel. (Why blue-green-red rather than red-green-blue? Because, this is the byte order used in **OpenCV** and originally stipulated by **Microsoft**. Sigh. Fortunately, if you need to change pixel byte order, **cv-cat** has filters for that, e.g. **convert-color=bgr,rgb**) The image part of the **snark** image format is simply an uncompressed binary image bitmap. E.g. an 8-byte RGB image 20x10 would have 20x10x3=600 bytes, each 3 bytes representing blue, green, and red components of the pixel. (Why blue-green-red rather than red-green-blue? Because, this is the byte order used in **OpenCV** and originally stipulated by **Microsoft**. Sigh. Fortunately, if you need to change pixel byte order, **cv-cat** has filters for that, e.g. **convert-color=bgr,rgb**)
Try to output your camera feed without header, i.e. images only. Try to output your camera feed without header, i.e. images only.
... ...
......