forked from lacatus/TFM
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mainloop.py
139 lines (94 loc) · 3.65 KB
/
mainloop.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#!/usr/bin/env python
import cv2
import datasets.datasetloader
"""
import datasets.grazptz1
import datasets.grazptz2
import datasets.pets091
import datasets.pets092
import datasets.pets093
import datasets.pets094
import datasets.pets095
import datasets.pets096
import datasets.pets097
import datasets.pets098
import datasets.pets099
import datasets.oxtown
import datasets.caviar01
import datasets.caviar02
import datasets.caviar03
import datasets.caviar04
import datasets.caviar05
"""
import datasets.pets01_crop
import datasets.pets091
import threedgeometry.frameretriever
import threedgeometry.retroprojection
from gui import imshow
from gui import trackbar
from bgsubtraction import bgprocess
from detection import detectionprocess
from tracker import trackerprocess
def initcameras():
dataset = datasets.datasetloader.selectdataset()
load_cmd = 'datasets.%s.loaddataset()' % dataset
print load_cmd
cameras, configuration = eval(load_cmd)
cameras = threedgeometry.frameretriever.getnumcameras(cameras)
return cameras, configuration
#initloop returns 'tracks' = an empty list to be filled in loop() @cia
def initloop(cameras, configuration):
frames = threedgeometry.frameretriever.getbg(cameras)
bg = bgprocess.getbgobject(configuration['global'])
bg_models = bgprocess.getbgmodels(frames, bg, configuration, cameras)
# Init trackbars
tb = trackbar.setdefaulttrackbarmain(bg)
trackbar.setdefaulttrackbardsecondary(bg_models)
tracks = trackerprocess.inittracks(len(cameras))
return bg_models, tb, tracks
#RETURN 'tracks' is an empty list to be filled in mainloop() @cia
def loop():
cameras, configuration = initcameras()
bg_models, tb, tracks = initloop(cameras, configuration)
while True:
print '' # Debug purposes
print '######################'
print ' NEW FRAME'
print '######################'
print ''
option = bg_models[0].bg.option # get which img you want to visualize
frames = threedgeometry.frameretriever.getframes(cameras)
#frames = threedgeometry.frameretriever.getundistortedframes(cameras)
if not frames: # Video ended
break
bg_models = bgprocess.bgprocess(frames, bg_models)
blobs, subjects = detectionprocess.detectionprocess(bg_models, cameras, frames)
tracks = trackerprocess.trackerprocess(tracks, subjects)
# imshow options
if option is 0:
imshow.showallimg(frames)
elif option is 1:
imshow.showallimg(bgprocess.getbgimg(bg_models))
elif option is 2:
imshow.showallimg(bgprocess.getbinimg(bg_models))
elif option is 3:
imshow.showallimg(bgprocess.getscanimg(bg_models))
elif option is 4:
imshow.showallimg(bgprocess.getdiffimg(bg_models))
elif option is 5:
imshow.showallimg(imshow.paintcontours(frames, bg_models))
elif option is 6:
imshow.showallimg(imshow.paintblobs(frames, blobs))
elif option is 7:
imshow.showallimg(imshow.paint3dworld(frames, cameras))
#imshow.showallimg(imshow.paintmasks(frames, blobs))
elif option is 8:
imshow.showallimg(imshow.paintsubjectsboxes(frames, subjects))
elif option is 9:
imshow.showallimg(imshow.painttracks(frames, tracks))
# show frames no video
if tb.framebyframe is 1:
cv2.waitKey()
cv2.waitKey(bg_models[0].bg.waitkey)
#tracks = trackerprocess.trackerprocess(tracks, subjects)
datasets.datasetloader.saveconfiguration(cameras, configuration, bg_models)