-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathpybgs_test.py
73 lines (61 loc) · 1.54 KB
/
pybgs_test.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import numpy as np
import cv2
import pybgs
#params = {
# 'algorithm': 'eigenbackground',
# 'low': 15 * 15,
# 'high': 15 * 15 * 2,
# 'history_size': 100,
# 'dims': 5 }
params = {
'algorithm': 'adaptive_median',
'low': 40,
'high': 40 * 2,
'sampling_rate': 10,
'learning_frames': 400 }
# params = {
# 'algorithm': 'grimson_gmm',
# 'low': 3.0 * 3.0,
# 'high': 3.0 * 3.0 * 2,
# 'alpha': 0.01,
# 'max_modes': 3 }
# params = {
# 'algorithm': 'mean_bgs',
# 'low': 3 * 30 * 30,
# 'high': 3 * 30 * 30 * 2,
# 'alpha': 1e-6,
# 'learning_frames': 30 }
# params = {
# 'algorithm': 'prati_mediod_bgs',
# 'low': 50,
# 'high': 50 * 2,
# 'weight': 1,
# 'sampling_rate': 5,
# 'history_size': 16 }
#params = {
# 'algorithm': 'wren_ga',
# 'low': 3.5 * 3.5,
# 'high': 3.5 * 3.5 * 2,
# 'alpha': 0.05,
# 'learning_frames': 30 }
#params = {
# 'algorithm': 'zivkovic_agmm',
# 'low': 5 * 5,
# 'high': 5 * 5 * 2,
# 'alpha': 0.001,
# 'max_modes': 3 }
bg_sub = pybgs.BackgroundSubtraction()
camera_source = cv2.VideoCapture()
camera_source.open(0)
i = 0
error, img = camera_source.read()
high_threshold_mask = np.zeros(shape=img.shape[0:2], dtype=np.uint8)
low_threshold_mask = np.zeros_like(high_threshold_mask)
bg_sub.init_model(img, params)
while cv2.waitKey(30) == -1:
error, img = camera_source.read()
bg_sub.subtract(i, img, low_threshold_mask, high_threshold_mask)
bg_sub.update(i, img, high_threshold_mask)
cv2.imshow('foreground', low_threshold_mask)
# cv2.imshow('background', bg_sub.get_background())
i += 1