Background subtraction
I'm new to openCV. I have images sequences from a still camera who takes 5 images when movement is detected. The resulting sequences are images taken 1-2 seconds apart, some with a moving object, some without. On many sequences, there are no frames without a moving object. Can you think of a way to isolate the moving object in such situation ?
I thought background subtraction would be the way to go. I made a movie of one 5 image sequence with mencoder. In this clip, I have 3 images with only background and two images with a moving object.
I tried cv2.BackgroundSubtractorMOG just to see:
while(True):
# Capture frame-by-frame
ret, frame = cap.read()
fgmask = fgbg.apply(frame)
# Display the resulting fgmask
cv2.imshow('frame',fgmask)
# display corresponding original image
cv2.imshow('img', frame)
k = cv2.waitKey(0) & 0xff
if k == 5:
break
This kind of work, as I get the moving object isolated (white) from the background (black). But the problem is that I don't get the expected fgmasks (3 black frames and 2 with objects in white). Also, in the while loop, the fgmask showed does not correspond to the original image showed. So I thought maybe 5 frames are not enough to do background subtraction ? But since I get the moving object isolated correctly, I feel like this could maybe work. Any thoughts on this ? Thank you for helping !