uzycie bacground substraction do wyodrebnienia poruszajacych sie obiektow
This commit is contained in:
parent
1c3faff85f
commit
effa204471
32
main.py
32
main.py
@ -1,15 +1,35 @@
|
||||
import cv2
|
||||
|
||||
video = 'data/video_1.avi'
|
||||
input_video = 'data/video_1.avi'
|
||||
size = 1.0 #wielkosc obrazu
|
||||
|
||||
cap = cv2.VideoCapture(video);
|
||||
cap = cv2.VideoCapture(input_video)
|
||||
height, width, frames_count, fps = cap.get(cv2.CAP_PROP_FRAME_HEIGHT), cap.get(
|
||||
cv2.CAP_PROP_FRAME_WIDTH), cap.get(cv2.CAP_PROP_FRAME_COUNT), cap.get(cv2.CAP_PROP_FPS),
|
||||
|
||||
while(True):
|
||||
height = int(height)
|
||||
width = int(width)
|
||||
print(height, width, frames_count, fps)
|
||||
|
||||
sub = cv2.createBackgroundSubtractorMOG2() # utworz background subtractor
|
||||
|
||||
while True:
|
||||
ret, frame = cap.read()
|
||||
if not ret: # jezeli film sie zakonczyl
|
||||
#frame = cv2.VideoCapture(input_video)
|
||||
#continue
|
||||
break
|
||||
if ret: #przetwarzanie kadru
|
||||
input_vid = cv2.resize(frame, (0, 0), None, size, size) # rozmiar obrazu
|
||||
cv2.imshow("bez zmian", input_vid) # wyswietlanie filmu wejsciowego bez zmian
|
||||
gray = cv2.cvtColor(input_vid, cv2.COLOR_BGR2GRAY)
|
||||
cv2.imshow("czarnobialy", gray) # wyswietlanie filmu w skali szarosci
|
||||
fgMask = sub.apply(gray) # uzycie background subtraction
|
||||
cv2.imshow("fgMask", fgMask)
|
||||
|
||||
cv2.imshow('film', frame)
|
||||
#Wyjdz po nacisnieciu escape
|
||||
if cv2.waitKey(33) == 27:
|
||||
key = cv2.waitKey(60)
|
||||
if key == 27: #Wyjdz po nacisnieciu escape
|
||||
break
|
||||
|
||||
cap.release()
|
||||
cv2.destroyAllWindows()
|
Loading…
Reference in New Issue
Block a user