imagesubtraction
#contents
Please note that this sample is not included with the Python or Java editions of OpenRTM-aist. On Linux, build and install it according to Building OpenCV Sample Code on Linux.
Overview
By starting ImageSubtraction, background images are extracted from the input image, foreground regions are detected, and both a mask image for extracting the foreground and the background image are output.
It is used together with OpenCVCamera and CameraViewer. (Please note that this component does not currently operate correctly on Windows unless it is rebuilt. Therefore, use on Ubuntu 18.04 is recommended.)
Startup Screen
Usage
ImageSubtraction is a component for extracting a background image from an input image. In this example, it is used together with the OpenCVCamera component for capturing images from a USB camera and the CameraViewer component for displaying processed images.
-
Procedure (The following steps are for Ubuntu 18.04.)
-
Start a terminal.
-
Install the sample code according to Building OpenCV Sample Code on Linux.
-
Start OpenRTP and RTSystemEditor according to OpenRTP, and make sure RTCs are displayed in the Name Service View. Open a new SystemEditor. For details on using RTSystemEditor, refer to RTSystemEditor.
-
Open a new terminal window.
-
Execute the following commands to edit rtc.conf.
-
$ cd ImageProcessing/opencv/bin
$ sudo vi rtc.conf
- Add the following line to the end of the file.
manager.components.naming_policy: ns_unique
- Open a new terminal and execute:
$ cd ImageProcessing/opencv/bin
$ ./CameraViewerComp
After starting the terminal, repeat the above command three more times to launch four CameraViewer components.
- Open a new terminal.
$ cd ImageProcessing/opencv/bin
$ ./OpenCVCameraComp
to start OpenCVCameraComp.
- Open another terminal and execute:
$ cd ImageProcessing/opencv/bin
$ ./ImageSubtractionComp
to start the ImageSubtraction component.
-
In the RTSystemEditor Name Service View, click [>] and confirm that the components CameraViewer0, CameraViewer1, CameraViewer2, CameraViewer3, OpenCVCamera0, and ImageSubtraction0 are displayed.
-
In RTSystemEditor, click the [Open New System Editor] button
at the top of the screen to open a new System Editor and display a new [System Diagram]. -
Drag and drop the above components onto the System Diagram.
-
Connect the ports of each component as shown below.
-
Right-click any component and select [Activate Systems].
-
Arrange the windows so that all four CameraViewer windows are visible.
- Move the mouse cursor out of the capture_image window. At that moment, the background image is captured and displayed in back_image. Observe how the other windows change as well.
The following configuration parameters can be set.
| Parameter Name | Description |
|---|---|
| control_mode | Either b or m can be selected. When b is selected, a background image is captured in response to a key event. When m is selected, the mode switches between DYNAMIC_MODE, which determines a threshold for each pixel, and CONSTANT_MODE, which uses a single threshold value for the entire image. |
| image_height | Specifies the vertical pixel count. This parameter is not functional in this sample. |
| image_width | Specifies the horizontal pixel count. This parameter is not functional in this sample. |
| threshold_coefficient | Coefficient used in DYNAMIC_MODE. |
| constant_threshold | Threshold value used in CONSTANT_MODE. |


