MCPcopy
hub / github.com/yosinski/deep-visualization-toolbox / run_loop

Method run_loop

live_vis.py:118–270  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

116 self.help_pane.data = self.help_buffer[self.help_pane.i_begin:self.help_pane.i_end, self.help_pane.j_begin:self.help_pane.j_end]
117
118 def run_loop(self):
119 self.quit = False
120 # Setup
121 self.init_window()
122 #cap = cv2.VideoCapture(self.settings.capture_device)
123 self.input_updater = InputImageFetcher(self.settings)
124 self.input_updater.bind_camera()
125 self.input_updater.start()
126
127 heartbeat_functions = [self.input_updater.heartbeat]
128 for app_name, app in self.apps.iteritems():
129 print 'Starting app:', app_name
130 app.start()
131 heartbeat_functions.extend(app.get_heartbeats())
132
133 ii = 0
134 since_keypress = 999
135 since_redraw = 999
136 since_imshow = 0
137 last_render = time.time() - 999
138 latest_frame_idx = None
139 latest_frame_data = None
140 frame_for_apps = None
141 redraw_needed = True # Force redraw the first time
142 imshow_needed = True
143 while not self.quit:
144 # Call any heartbeats
145 for heartbeat in heartbeat_functions:
146 #print 'Heartbeat: calling', heartbeat
147 heartbeat()
148
149 # Handle key presses
150 keys = []
151 # Collect key presses (multiple if len(range)>1)
152 for cc in range(1):
153 with WithTimer('LiveVis:waitKey', quiet = self.debug_level < 2):
154 key = cv2.waitKey(self.settings.main_loop_sleep_ms)
155 if key == -1:
156 break
157 else:
158 if (key != 255):
159 keys.append(key)
160 #print 'Got key:', key
161 now = time.time()
162 #print 'Since last:', now - last_render
163
164 skip_imshow = False
165 #if now - last_render > .05 and since_imshow < 1:
166 # skip_imshow = True
167
168 if skip_imshow:
169 since_imshow += 1
170 else:
171 since_imshow = 0
172 last_render = now
173
174 #print ' Number of keys:', len(keys)
175 for key in keys:

Callers 1

mainFunction · 0.95

Calls 15

init_windowMethod · 0.95
handle_key_pre_appsMethod · 0.95
handle_key_post_appsMethod · 0.95
display_frameMethod · 0.95
draw_helpMethod · 0.95
InputImageFetcherClass · 0.90
WithTimerClass · 0.90
FormattedStringClass · 0.90
cv2_typeset_textFunction · 0.90
cv2_imshow_rgbFunction · 0.90
bind_cameraMethod · 0.80
get_frameMethod · 0.80

Tested by

no test coverage detected