0

I am relatively new to OpenCV. My program will have a fixed camera that will track insects moving passed it. I figured that this would mean that I could remove the background from the video. I have attempted to use the method (which I found in a tutorial - http://docs.opencv.org/3.1.0/d1/dc5/tutorial_background_subtraction.html#gsc.tab=0):

pMOG2 = cv::createBackgroundSubtractorMOG2();
..
pMOG2->apply(frame, background);

However, how does this determine the background?

I have tried another way, which I thought might work, which was to capture the background when the program first starts and then use absDiff() or subtraction() on the background and current frame. Unfortunately, this results in a strange image which has parts of the static background image displayed over the video, this messes up the tracking.

I am a bit confused as to what would be the best way to do things. Is it possible to remove a specific background from each frame?

Thanks!

liamw9
  • 527
  • 2
  • 6
  • 19
  • is the background static or dynamic/moving? Would be nice to see a short sample video (or a sequence of some single frames)... – Micka Aug 04 '16 at 13:47
  • That background will be static. It's just a small (raspberry pi) camera mounted above the entrance of a nest (under experimental conditions), so, the background is just a white floor. I don't currently have footage, as I'm trying to get the code running with a webcam, just to figure out the general method. – liamw9 Aug 04 '16 at 13:53
  • you can use Mixture of gaussian or ViBe or even simpler background modelling mechanisms. If you choose your background to be the first frame (if no insects are visible), just use absdiff as you did, and count a pixel to be foreground, if the absdiff of one or more channels is bigger than a threshold (or the root of squared sum of all thress channels). Typcal thresholds are 20 or 30. – Micka Aug 04 '16 at 13:56
  • Yes, I will likely take the first frame, as it will be empty of any insects. Sorry, what do you mean by counting the pixel to be the foreground? Thanks for your help – liamw9 Aug 04 '16 at 14:06
  • 1
    sorry, instead of counting I meant to create a mask and set those pixel (which have a absdiff distance from zero greater than some threshold) to 255 and all the other pixels to 0. – Micka Aug 04 '16 at 14:09
  • 1
    have a look at this: http://stackoverflow.com/questions/27035672/cv-extract-differences-between-two-images/27036614#27036614 you can do the same without converting to HSV color space – Micka Aug 04 '16 at 14:11

0 Answers0