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

Class InputImageFetcher

input_fetcher.py:13–246  ·  view source on GitHub ↗

Fetches images from a webcam or loads from a directory.

Source from the content-addressed store, hash-verified

11
12
13class InputImageFetcher(CodependentThread):
14 '''Fetches images from a webcam or loads from a directory.'''
15
16 def __init__(self, settings):
17 CodependentThread.__init__(self, settings.input_updater_heartbeat_required)
18 self.daemon = True
19 self.lock = RLock()
20 self.quit = False
21 self.latest_frame_idx = -1
22 self.latest_frame_data = None
23 self.latest_frame_is_from_cam = False
24
25 # True for loading from file, False for loading from camera
26 self.static_file_mode = True
27 self.settings = settings
28
29 # True for streching the image, False for cropping largest square
30 self.static_file_stretch_mode = self.settings.static_file_stretch_mode
31
32 # Cam input
33 self.capture_device = settings.input_updater_capture_device
34 self.no_cam_present = (self.capture_device is None) # Disable all cam functionality
35 self.bound_cap_device = None
36 self.sleep_after_read_frame = settings.input_updater_sleep_after_read_frame
37 self.latest_cam_frame = None
38 self.freeze_cam = False
39
40 # Static file input
41
42 # latest image filename selected, used to avoid reloading
43 self.latest_static_filename = None
44
45 # latest loaded image frame, holds the pixels and used to force reloading
46 self.latest_static_frame = None
47
48 # keeps current index of loaded file, doesn't seem important
49 self.static_file_idx = None
50
51 # contains the requested number of increaments for file index
52 self.static_file_idx_increment = 0
53
54 def bind_camera(self):
55 # Due to OpenCV limitations, this should be called from the main thread
56 print 'InputImageFetcher: bind_camera starting'
57 if self.no_cam_present:
58 print 'InputImageFetcher: skipping camera bind (device: None)'
59 else:
60 self.bound_cap_device = cv2.VideoCapture(self.capture_device)
61 if self.bound_cap_device.isOpened():
62 print 'InputImageFetcher: capture device %s is open' % self.capture_device
63 else:
64 print '\n\nWARNING: InputImageFetcher: capture device %s failed to open! Camera will not be available!\n\n' % self.capture_device
65 self.bound_cap_device = None
66 self.no_cam_present = True
67 print 'InputImageFetcher: bind_camera finished'
68
69 def free_camera(self):
70 # Due to OpenCV limitations, this should be called from the main thread

Callers 1

run_loopMethod · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected