0

I am using the following piece of code to do background subtraction.

import numpy as np
import cv2

cap = cv2.VideoCapture('Desktop/001.avi')
fgbg = cv2.BackgroundSubtractorMOG(100, 5, 0.3, 0.1)
while(1):
  ret, frame = cap.read()
  fgmask = fgbg.apply(frame)
  cv2.imshow('frame',frame)
  cv2.imshow('fgmask',fgmask)
  k = cv2.waitKey(1) & 0xff
  if k == 27:
    break 
cap.release()
v2.destroyAllWindows()

And the test video is from http://www.ee.cuhk.edu.hk/~xgwang/MITtraffic.html I choose the first video, the background mask has 4 most pedestrians and 1 car, Could any body tell me how to fix this or why this happened? Where are the host pedestrians from ? Thanks

Saransh Kejriwal
  • 2,467
  • 5
  • 15
  • 39
printemp
  • 869
  • 1
  • 10
  • 33
  • 2
    noise, shadows, movements, etc. can lead to foreground-artifacts – Micka Mar 07 '16 at 15:11
  • 2
    You're probably initializing the background model with people or cars in it. As soon as they move, they'll create a ghost artifact. You should initialize your background model on an empty background (i.e. without moving objects) – Miki Mar 07 '16 at 15:13
  • @Miki, Yes, I see, they are just the first frame of the video, but as I understand, the background should be updated? yes? – printemp Mar 07 '16 at 15:57
  • Yes, but it takes a while, and in the meantime you have those artifacts – Miki Mar 07 '16 at 15:58
  • @Miki, it seems they are always there for 4 minutes, even I change the length of history parameter. Do you know how to make the time shorter? Any parameters or any other API I could use? Sorry for so many problems – printemp Mar 07 '16 at 16:00
  • playing with `history` (in constructor) and `learningRate` (in `apply`) parameters should help – Miki Mar 07 '16 at 16:02
  • @Miki, thanks, after changing to opencv 3.1.0, it truly works, with many thanks~~ – printemp Mar 08 '16 at 08:27

0 Answers0