Ask Your Question
0

Remove People Using Running Median of Frames

asked 2018-10-11 13:41:00 -0600

Hello,

I am trying to take the people out of a video, leaving only the background. The background cannot have any holes in it. I have tried some methods of background subtraction and filling in the holes with some image repair techniques, but those do not work super well or are really slow. I also made some code to do moving averaging across the frames and that works okay, but it leaves some blur. Now I am trying to take the median across frames. This is different from a median filter. I am hoping that if I take the median of the previous 40 or so frames, the people will be removed.

Code so far:

import numpy as np
import cv2 as cv

 cap = cv.VideoCapture('/home/matthew/Downloads/Cam2_Indoor.avi')
 framecount = cap.get(cv.CAP_PROP_FRAME_COUNT)
 print framecount
 buff = cap.get(cv.CAP_PROP_BUFFERSIZE)
 print buff
 frames = []
 index = cap.get(cv.CAP_PROP_POS_FRAMES)



print index

 #while(1):
 for _ in range(241, 295):
     ret, frame = cap.read()
     index = cap.get(cv.CAP_PROP_POS_FRAMES)
     print index

 setbuff = cap.set(cv.CAP_PROP_BUFFERSIZE, 40)

     median = np.median(frame, axis=2).astype(dtype=np.uint8)    
     cv.imshow('frame', median)


     k = cv.waitKey(30) & 0xff
     if k == 27:
         break
 cap.release()
 cv.destroyAllWindows()

Thank you for the help. This code works but it doesn't work like I want it to. I want it to continuously take the previous for images and take the median across the frames. This code here does not seem to be taking the median at all. Link to video: [http://iselab.cvc.uab.es/silverage.ph...]

video is on the page, called cam2_indoor.zip. I'm not a super great python programmer, so I'm trying to keep the code simple for now. Thanks!

edit retag flag offensive close merge delete

Comments

so, according to you, we need to watch a silly video, that did NOT solve it ?

berak gravatar imageberak ( 2018-10-11 13:53:02 -0600 )edit
1

The video is the video that I am trying to take the people out of. I think I have figured out how to take the median of the same pixel across multiple images, but I can't answer my own question until tomorrow due to forum rules.

98mazdaman gravatar image98mazdaman ( 2018-10-11 16:20:50 -0600 )edit

sorry, misread it then.

berak gravatar imageberak ( 2018-10-12 01:03:53 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2018-10-12 21:05:10 -0600

Tetragramm gravatar image

OpenCV does not have a Temporal Median algorithm. You can use one of the background subtraction algorithms and call getBackgroundImage. Or as you seem to be trying here, use numpy's median algorithm.

You don't seem to be stacking them up properly, at least in the code currently here, but the correct general idea.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2018-10-11 13:41:00 -0600

Seen: 1,484 times

Last updated: Oct 12 '18