4

I am performing background subtraction to obtain a moving car from a video as below ( Running average background modeling)

I am applying findContours() after this to draw a polygon around the car.

As you can see, the quality of the obtained output is not great. Is there any way I can enhance the edges of the car to make it more prominent and cut out the extraneous noise surrounding it. I tried performing morphological closing(dilate -> erode) to fill the gaps, but the output was not as expected.

enter image description here

enter image description here

Jav_Rock
  • 22,059
  • 20
  • 123
  • 164
Madman
  • 309
  • 1
  • 5
  • 10
  • did you try using morphological operations the other way around -- instead of using closing to enhance the car silhouette, maybe you could try using opening to get rid of the surrounding noise? if you are then left just with an (imperfect) car on the picture, it might be easier to work with if it is left as the *only* object on the picture – penelope Dec 27 '11 at 09:48
  • Can you post a sample learned background, and then a sample frame with the car contained in it? – mevatron Dec 28 '11 at 00:18

2 Answers2

0

This might be overkill and far from a quick solution but Level Set Methods would be very suited to extract the presegmented car.

Herr von Wurst
  • 2,571
  • 5
  • 32
  • 53
0

You can try to apply background subtraction by using cv2.createBackgroundSubtractorMOG2().

Code:

import cv2
import numpy as np

cap = cv2.VideoCapture(0)
out = cv2.createBackgroundSubtractorMOG2()

fourcc = cv2.VideoWriter_fourcc(*'MJPG')
output = cv2.VideoWriter('output.avi', fourcc, 20.0, (640,480), isColor=False)

while(cap.isOpened()):
    ret, frame = cap.read()

    if ret==True:
        frame = cv2.flip(frame,180)

        outmask = out.apply(frame)
        output.write(outmask)

        cv2.imshow('original', frame)
        cv2.imshow('Motion Tracker', outmask)

        if cv2.waitKey(1) & 0xFF == ord('q'):
            break

    else:
        break


output.release()
cap.release()
cv2.destroyAllWindows()
Abu Noman Md Sakib
  • 322
  • 2
  • 5
  • 20