# Recording data for evaluation

This tutorial shows how to record sample data sets with the *rc_visard* as single snapshots or image sequences.

In order to go through this tutorial, the *rc_visard* must be running the latest firmware (version 26.10). This can be verified on the System ‣ Firmware & License page of the Web GUI.

## Downloading single snapshots

The recommended way to capture a snapshot of the current scene is via the rc_visard’s Web GUI.

For evaluation of use-cases and support, Roboception requires snapshots taken from the **Depth Image** page of the Web GUI.

A new snapshot of the current scene is downloaded by clicking on the camera icon below the image live streams (see [Fig. 12](#downloading-single-snapshots)). This will create an archive containing the left and right camera images, the disparity, error and confidence images, as well as the current point cloud as a ply file, and the rc_visard’s current parameters.

> ![Web GUI Depth Image page with snapshot button](../_images/webgui_depth_image_snapshot.png)

> *Web GUI **Depth Image** page with snapshot button*

The steps below describe the optimal sensor setup before capturing snapshots:

> 1. In the **Camera** page of the Web GUI
>    > * make sure that the Exposure is set to *Auto*
>    > * optionally set an *Exposure Region* around the objects of interest

Steps 2 to 5 only apply to users of the *rc_randomdot* projector

> 1. In the **Camera** page of the Web GUI, set the *Auto Exposure Mode* to *AdaptiveOut1*
> 2. Follow the [Configuring the rc_randomdot projector](../image_tuning/projector.md#configuring-the-rc_randomdot-projector) tutorial to configure the projector
> 3. In the **Depth Image** page of the Web GUI
>    > * select *Single+Out1* as *Acquisition Mode*
>    > * increase the *Exposure Adaptation Timeout* to the maximum (2 seconds)
>    > * press the Acquire button a few times
> 4. Back on the **Camera** page of the Web GUI
>    > * check that the *Out1 Reduction* value reported below the live image streams is below 50%. If not, decrease the aperture of the *rc_randomdot* projector, or add more light to the scene.
>    > * increase the *Min Brightness* value, if the images appear too dark

Final verification steps for all users

> 1. Check that the *Gain* reported below the live image streams in the **Camera** page is as low as possible (ideally 0 dB). The *Gain* can be decreased by adding more light to the scene.
> 2. Check that the *Confidence Image* in the **Depth Image** page is bright on the objects of interest. If not, follow the steps described in the [Tuning of depth images](../image_tuning/depth_tuning.md#tuning-of-depth-images) tutorial.

#### NOTE
Users of the *rc_reason* software modules have also the possibility to download snapshots of the last detection from each module’s page in the Web GUI (currently available for LoadCarrier, ItemPick, BoxPick, and SilhouetteMatch).

These snapshots should be provided to Roboception in addition to Depth Image snapshots, captured as described above.

## Recording image sequences

#### NOTE
The following instructions are only applicable if you want to download image sequences (image streams) from the *rc_visard*. For recording single snapshots, follow the approach above.

### Before we start

Before going through this tutorial, the following prerequisites should be met.

### The *rc_visard* is up and running:

1. The *rc_visard* is running and connected properly to the host. One can verify that with our [discovery tool](https://github.com/roboception/rcdiscover/releases).
2. One should know the serial number or user defined name of the *rc_visard*. The serial number is of the format 029xxxxx. It will be referred to as `rc_visard_id` in the remainder of this tutorial.

### Download and install the following required client software:

Linux

1. Download [rc_genicam_api](https://github.com/roboception/rc_genicam_api/releases)
2. Download [rc_dynamics_api](https://github.com/roboception/rc_dynamics_api/releases)

For Ubuntu, we provide ready-to-use Debian packages.

Windows

For Windows, all required software is bundled with the recording scripts, so no download is necessary.

### Optional software for viewing the recorded images can be installed:

Linux

Download [cvkit](https://github.com/roboception/cvkit/releases).

For Linux, it is easiest to download the source code and build it by entering the main directory and typing:

```bash
mkdir build
cd build
cmake ..
make
sudo make install
```

Images can be viewed using the viewer `sv`. Disparity images, i.e. with the suffix  *.pfm* can be viewed in 3D by pressing ‘p’ or calling `plyv` with the disparity image as argument. Both tools show a help page with all key codes by pressing ‘h’.

Windows

Download [cvkit](https://github.com/roboception/cvkit/releases).

For Windows, pre-compiled software is available in a ZIP archive. The archive contains a self-installing executable.

After installation, images can be viewed by double clicking on them in the explorer. Disparity images, i.e. with the suffix  *.pfm* can be viewed in 3D by pressing ‘p’. Both tools show a help page with all key codes by pressing ‘h’.

### The network configuration is optimized:

Enable “Jumbo frames” by setting the MTU to 9000.

Ubuntu

### Temporarily

Enter the following command in the terminal.

```bash
ifconfig <interface> mtu 9000
```

### Persistently

1. Open the network manager
2. Select interface and edit settings
3. On “Ethernet” tab, change MTU to 9000

Windows 10

1. Open “Network Connections”
2. Right-click on the network interface
3. Choose “Properties”
4. Click “Configure”
5. On the “Advanced” tab, choose “Jumbo Packet”
6. Select “9014 Bytes”

### Recording data

We provide scripts for Linux and Windows to record data in our `rc_visard_offboard_record` [GitHub repository](https://github.com/roboception/rc_visard_offboard_record).

The script offers two modes: An interactive mode that is started if the script is launched via a double-click or called without any arguments from a terminal/command line window. In that mode, the user is asked by the script for the `rc_visard_id`. In standard mode, in contrast, the `rc_visard_id` is passed to the script as command line argument, optionally next to other arguments.

Each time, the script runs, it creates a new folder in the working directory (i.e. the place the script was started in) and writes all data to that folder. The folder’s name is of the format `rc-visard_<SN>_<T>`, where `<SN>` is replaced by the `rc_visard_id` and `<T>` by the current time. The images are stored in PGM or PPM format, which are supported by many image viewers. All other files are stored as text.

#### CAUTION
On Windows, proper configuration of the firewall is important. On the first run of the script, the user will be asked whether the `rc_genicam_api` and `rc_dynamics_api` tools should be allowed to access the network. This needs to be allowed, otherwise the script will not work properly. In case of problems with data recording, temporarily disabling the firewall can help to pinpoint the source of the problem. It may be necessary to manually whitelist `gc_info.exe`, `gc_config.exe` and `gc_stream.exe` that are located in the folder `rc_genicam_api-*`, and `rcdynamics_stream.exe` that can be found in the folder `rc_dynamics_api-*`.

#### Interactive mode

Start the script via double-click. The script asks for the `rc_visard_id`, i.e. the serial number (which is of the format 029xxxxx) or user defined name. By entering `L`, all available *rc_visard* devices are listed. Interactive mode does not allow changing of script parameters other than the `rc_visard_id`. If that is required, the standard mode should be chosen, as it offers more flexibility.

#### Standard mode

In standard mode, the script is called from a terminal/command line window.

The basic usage is as follows:

Linux

1. Open a terminal.
2. Change to the script folder.
3. Launch the `rc_visard_record.sh`:
   > ```bash
   > ./rc_visard_record.sh [options] <rc_visard_id>
   > ```

Windows

1. Open a terminal.
2. Change to the script folder.
3. Launch the `rc_visard_record.bat`:
   > ```bash
   > rc_visard_record.bat [options] <rc_visard_id>
   > ```

The script offers optional arguments, which can be listed with the -h flag:

Linux

```bash
./rc_visard_record.sh -h
```

Windows

```bash
rc_visard_record.bat -h
```

By default, the script will run until it is stopped with `Enter` and record images from the left camera, disparity images, confidence images and error images.

This behavior can be changed by passing different arguments to the script. For example, to record only the left camera images and stop after 10 images, the following command can be used:

Linux

```bash
./rc_visard_record.sh --number=10 --left=true --right=false --disparity=false --confidence=false --error=false <rc_visard_id>
```

Windows

```bash
rc_visard_record.bat -n 10 -left true -right false -disparity false -confidence false -error false <rc_visard_id>
```

The `cam-params` argument allows to also record the current camera parameters including the camera calibration. It will write the parameters to the given file, below called params.txt.

Linux

```bash
./rc_visard_record.sh --cam-params=params.txt <rc_visard_id>
```

Windows

```bash
rc_visard_record.bat -cam-params params.txt <rc_visard_id>
```

The script also supports recording of the SLAM trajectory, which can be enabled with the `slam` argument. The script will automatically start and stop SLAM, and eventually write the trajectory to the given file (trajectory.json in the example). The trajectory is written when image grabbing is finished, which is either when the user presses `Enter` or enough data sets are recorded according to the `number` argument.

Linux

```bash
./rc_visard_record.sh --slam=trajectory.json <rc_visard_id>
```

Windows

```bash
rc_visard_record.bat -slam trajectory.json <rc_visard_id>
```

### Troubleshooting

**The script writes “gc_stream is not found” or “gc_info is not found”**

> `rc_genicam_api` is not installed properly.

**The script writes “rcdynamics_stream is not found”**

> `rc_dynamics_api` is not installed properly.

**The script writes “Cannot find device: 01234567” or “Device 01234567 not found”**

> The script could not find the *rc_visard* with the given serial number. Are serial number and network configuration correct?

**The script writes “storeBuffer(): Received incomplete buffer”**

> The network configuration may be slow or not optimized properly. Is the *rc_visard* connected via a 1 GBit/s wired ethernet connection? Please follow [network optimization](#the-network-configuration-is-optimized). Try to connect the *rc_visard* to the host directly.

**The script writes “Device::open() failed”**

> The *rc_visard* may have not booted completely yet, or another client may already be connected to the *rc_visard*.

**The script writes “Cannot grab images”**

> The network may not be configured properly. On Windows, the firewall may block the network connection. Temporarily disabling the firewall can help to pinpoint the source of the problem. Try to connect the *rc_visard* to the host directly.
