Remove People Using Running Median of Frames
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!
so, according to you, we need to watch a silly video, that did NOT solve it ?
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.
sorry, misread it then.