-
Notifications
You must be signed in to change notification settings - Fork 31
op backgroundSubtractor
The FirePick backgroundSubtractor stage wraps the OpenCV BackgroundSubtractor class. Background subtraction is excellent for detecting the orientation and offset of objects newly placed on a known background. For pick-and-place operations, this stage can help determine angular and offset error of a picked part. The stage output image is the binary foreground mask computed by the background subtractor.
-
method The default
absdiff
works well for static images. Method MOG2 may be more useful for video. -
varThreshold OpenCV recommends the default of
16
. Higher values reduce sensitivity and therefore noise. -
bShadowDetection (MOG2) The OpenCV and FireSight default is
true
, but false may be more useful given the lack of shadows in most pick-and-place images. - background (MOG2) If provided, this specifies the path to a fixed background image to compare.
-
history (MOG2) If non-zero, specifies the number of preceding images to aggregate as the background for comparison. The default is
0
. A non-zero value really only matters for video pipelines that need to compute an ever-changing background from the most recent video frames. -
learningRate (MOG2) Default is
-1
.
{}
Example 1: BackgroundSubtractorMOG2 varThreshold=16 pipeline
firesight -i img/mog2.jpg -p json/bgsub.json -o target/bgsub.png -DbgImg=img/pcb.jpg -Dmethod=MOG2
Background image →
Background with text →
Foreground mask (Windows) →
Raspberry Pi uses OpenCV 32-bit, and the results are not as good →
Example 2: BackgroundSubtractorMOG2 varThreshold=64 pipeline
firesight -i img/mog2.jpg -p json/bgsub.json -o target/bgsub-mog2.png -DbgImg=img/pcb.jpg -Dmethod=MOG2 -Dthresh=64
The previous example demonstrates that the 32-bit OpenCV version of BackgroundSubtractorMOG2 does not work as well as the 64-bit version of OpenCV. However, we can improve our results by using the varThreshold, which is bound to the thresh
pipeline parameter. To reduce noise artifacts, we increase varThreshold from the default 16
to 64
:
varThreshold set to 64
→
Example 3: absdiff method, thresh=32 pipeline
firesight -i img/mog2.jpg -p json/bgsub.json -o target/bgsub-absdiff.png -DbgImg=img/pcb.jpg -Dmethod=absdiff -Dthresh=32 -Dmethod=absdiff
Thanks to Chris, who pointed out that a faster and simpler method of background subtraction can be had by simply combining [absdiff](op absdiff) and [threshold](op threshold). As you can see, setting method to absdiff is almost 5x faster and results in cleaner output: