Ask Your Question
0

Background subtraction

asked 2014-10-13 13:33:01 -0600

chargaff gravatar image

updated 2014-10-13 13:35:41 -0600

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 !

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2014-10-15 08:26:48 -0600

chargaff gravatar image

It seems like running average is working

edit flag offensive delete link more

Question Tools

Stats

Asked: 2014-10-13 13:33:01 -0600

Seen: 267 times

Last updated: Oct 13 '14