Frame differencing
It should be straightforward to think of a simple background subtraction in order to retrieve foreground objects. A simple solution could look similar to the following line of code:
Core.absdiff(backgroundImage,inputImage , foregroundImage);
This function simply subtracts each pixel of backgroundImage
from inputImage
and writes its absolute value in foregroundImage
. As long as we have initialized the background to backgroundImage
and we have that clear from objects, this could work as a simple solution.
Here follows the background subtraction video processor code:
public class AbsDifferenceBackground implements VideoProcessor { private Mat backgroundImage; public AbsDifferenceBackground(Mat backgroundImage) { this.backgroundImage = backgroundImage; } public Mat process(Mat inputImage) { Mat foregroundImage = new Mat(); Core.absdiff(backgroundImage,inputImage , foregroundImage); return foregroundImage; } }
The main method, process
, is really simple...