We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Greg Borenstein's new OpenCV library includes an example for background detection:
…but it assumes you want to detect foreground objects using live video, which changes frame to frame. I want to take a snapshot of the "background" once, and then compare the current video capture image against that (static) snapshot, like in Golan Levin's library that comes with Processing (see File > Examples > Libraries > Video > Capture > BackgroundSubtraction):
Can I use the new OpenCV library to accomplish what Golan does here manually?
If not, can I use Golan's manual approach to background detection, then pass the pixels of that difference image into OpenCV for contour detection and other processing?
Answers
updateBackground() is really cool but you're right, for a static background the approach Golan is using is the easiest. There's a nice utility function for it: absdiff(), which Greg has in there as "public static void diff(Mat mat1, Mat mat2)". Just get the difference between the two images and voila, that's your "foreground".
Thanks! This looks like what I want. But how do I define the two Mat arguments and pass them in? I can't find the source for the Mat class.
Figured it out! The method you mentioned is great if you already have two Mat objects and just want to diff them. It was simpler for me to use "public void diff(PImage img)" to calc the difference between a PImage I pass in and the current OpenCV Mat. I have a PImage called bg, so this worked well for me:
I'm on the lookout for a similar thing, there is a static reference image and a current video capture. I want to compare the video frames with that static frame. The difficult part being, that the program should give the user the instructions to either pan and/or zoom to get to the reference frame. Also, I'm new to programming.