2020-02-13 12:54:14 +01:00
|
|
|
import cv2
|
|
|
|
|
2020-02-13 17:15:43 +01:00
|
|
|
input_video = 'data/video_1.avi'
|
|
|
|
size = 1.0 #wielkosc obrazu
|
2020-02-13 12:54:14 +01:00
|
|
|
|
2020-02-13 17:15:43 +01:00
|
|
|
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),
|
2020-02-13 12:54:14 +01:00
|
|
|
|
2020-02-13 17:15:43 +01:00
|
|
|
height = int(height)
|
|
|
|
width = int(width)
|
|
|
|
print(height, width, frames_count, fps)
|
|
|
|
|
|
|
|
sub = cv2.createBackgroundSubtractorMOG2() # utworz background subtractor
|
|
|
|
|
|
|
|
while True:
|
2020-02-13 12:54:14 +01:00
|
|
|
ret, frame = cap.read()
|
2020-02-13 17:15:43 +01:00
|
|
|
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)
|
2020-02-13 12:54:14 +01:00
|
|
|
|
2020-02-13 17:15:43 +01:00
|
|
|
key = cv2.waitKey(60)
|
|
|
|
if key == 27: #Wyjdz po nacisnieciu escape
|
2020-02-13 12:54:14 +01:00
|
|
|
break
|
|
|
|
|
2020-02-13 17:15:43 +01:00
|
|
|
cap.release()
|
2020-02-13 12:54:14 +01:00
|
|
|
cv2.destroyAllWindows()
|