-
Notifications
You must be signed in to change notification settings - Fork 3
/
14_Arkaplan_Filtreleme.py
43 lines (30 loc) · 1.19 KB
/
14_Arkaplan_Filtreleme.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
""" -*- coding: utf-8 -*-
@author: omerkocadayi
https://github.com/omerkocadayi
https://www.linkedin.com/in/omerkocadayi/ """
import cv2
import numpy as np
cap = cv2.VideoCapture("cars.mp4")
cap2 = cv2.VideoCapture("cars.mp4")
ret, firstFrame = cap.read()
firstFrame = cv2.resize(firstFrame, (640,480))
firstGray = cv2.cvtColor(firstFrame, cv2.COLOR_BGR2GRAY)
firstGray = cv2.GaussianBlur(firstGray, (3,3), 0)
subtractor = cv2.createBackgroundSubtractorMOG2(history = 100, varThreshold = 75, detectShadows = True)
while True:
ret, frame = cap.read()
ret, frame1 = cap2.read()
frame = cv2.resize(frame, (640,480))
frame1 = cv2.resize(frame1, (640,480))
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
gray = cv2.GaussianBlur(gray, (3,3), 0)
diff = cv2.absdiff(firstGray, gray)
ret, diff = cv2.threshold(diff, 40, 355, cv2.THRESH_BINARY)
mask = subtractor.apply(frame)
cv2.imshow("Frame", frame)
cv2.imshow("Opencv Function Result", mask)
cv2.imshow("Manuel Result", diff)
if cv2.waitKey(15) & 0xFF == ord('q'):
break
cap.release()
cv2.destroyAllWindows()