SwisTrack/Components/BlobDetectionRedGreen

Description
This component detects markers consisting of a red and a green blob on a color image. The background is supposed to be uniformly black, gray, blue, yellow, or white. The particle position is the point between the two blob centers, while the particle orientation is pointing towards the red blob.

The component was originally written to detect green and red LEDs mounted on a robot, and works reliably even if the green (resp. red) blob consists of various shades of green (resp. red). Best results were achieved in a dark room where the only visible light on the camera images were the red and green LEDs.

The algorithm compares the green (g) and red (r) value and classifies each pixel into one of the following categories: $$t_r$$ and $$t_g$$ denote the thresholds for the red resp. green blobs. The blue (b) channel is ignored.
 * Red pixel, if $$r-g > t_r$$
 * Green pixel, if $$g-r > t_g$$
 * Gray pixel, otherwise

Input


A color image with red and green blobs. The background is supposed to be uniformly black, gray, blue, yellow, white, or any combination of these colors.

Output


Particles, with the center being between the red and green blobs, and the orientation pointing towards the red blob.

Max. particles
Maximum number of particles to detect. Note that the algorithm first detects this many red and green blobs, and then matches them. Hence, if there are stray red or green areas in your image (not part of a marker), you should choose a number of particles that is slightly higher than the number of markers you deploy.

Max. distance
The maximum distance between the center of the red blob and the center of the green blob. Blobs that are farther away from each other are considered not being part of the same marker.

This distance is also used to eliminate stray blobs in the neighborhood of red or green blobs. More precisely, within any disk of this diameter (not radius), only the biggest red (resp. green) blob is detected.

Threshold (red and green blob)
The thresholds $$t_r$$ and $$t_g$$ (see description above).

Selection by area (red and green blob)
Check this to base blob selection on the blob area.

Min. blob size (red and green blob)
Minimum area in pixels of a blob to select.

Max. blob size (red and green blob)
Maximum area in pixels of a blob to select.

Selection by compactness (red and green blob)
Check this to base blobs section on the compactness of the blob.

Min. compactness (red and green blob)
Minimum compactness (0..1) of a blob to select.

Max. compactness (red and green blob)
Maximum compactness (0..1) of a blob to select.