Background subtraction is any technique that allows an image's foreground to be extracted for further processing
Many applications do not need to know everything about the evolution of movement in a video sequence, but only require the information of changes in the scene, because an image's regions of interest are objects(humans, cars, text, etc) in its foreground. After the stage of image processing(which may include image denoising, post-processing like morphology, etc.) object localization is required which may make use of this technique
So let's create this most valuable project with python so easily.
Modules:
- OpenCV
- Numpy
Code:
import numpy as np
import cv2
cap = cv2.VideoCapture('walking.avi')
# Initlaize background subtractor
foreground_background = cv2.createBackgroundSubtractorMOG2()
while True:
ret, frame = cap.read()
# Apply background subtractor to get our foreground mask
foreground_mask = foreground_background.apply(frame)
cv2.imshow('Output', foreground_mask)
if cv2.waitKey(1) == 13:
break
cap.release()
cv2.destroyAllWindows()
Note:
You can get an error for the file so if you want the file and also the code then click here
Comments
Post a Comment