|
6 | 6 | Licensed under GNU General Public License v3.0 |
7 | 7 | """ |
8 | 8 | import time |
9 | | -import base64 |
10 | | - |
11 | 9 | import cv2 |
12 | 10 | import numpy as np |
13 | | -import zmq |
14 | 11 |
|
15 | | -from utils.configloader import CAMERA_SOURCE, VIDEO_SOURCE, RESOLUTION, FRAMERATE, PORT, REPEAT_VIDEO |
| 12 | +from utils.configloader import CAMERA_SOURCE, VIDEO_SOURCE, RESOLUTION, FRAMERATE, REPEAT_VIDEO |
16 | 13 |
|
17 | 14 | class MissingFrameError(Exception): |
18 | 15 | """Custom expection to be raised when frame is not received. Should be caught in app.py and deeplabstream.py |
@@ -157,72 +154,4 @@ def get_frames(self) -> tuple: |
157 | 154 | return color_frames, depth_maps, infra_frames |
158 | 155 |
|
159 | 156 |
|
160 | | -class WebCamManager(GenericManager): |
161 | | - |
162 | | - def __init__(self): |
163 | | - """ |
164 | | - Binds the computer to a ip address and starts listening for incoming streams. |
165 | | - Adapted from StreamViewer.py https://github.com/CT83/SmoothStream |
166 | | - """ |
167 | | - super().__init__() |
168 | | - self._context = zmq.Context() |
169 | | - self._footage_socket = self._context.socket(zmq.SUB) |
170 | | - self._footage_socket.bind('tcp://*:' + PORT) |
171 | | - self._footage_socket.setsockopt_string(zmq.SUBSCRIBE, np.unicode('')) |
172 | | - |
173 | | - self._camera = None |
174 | | - self._camera_name = "webcam" |
175 | | - self.initial_wait = False |
176 | | - self.last_frame_time = time.time() |
177 | | - |
178 | | - @ staticmethod |
179 | | - def string_to_image(string): |
180 | | - """ |
181 | | - Taken from https://github.com/CT83/SmoothStream |
182 | | - """ |
183 | | - |
184 | | - img = base64.b64decode(string) |
185 | | - npimg = np.fromstring(img, dtype=np.uint8) |
186 | | - return cv2.imdecode(npimg, 1) |
187 | | - |
188 | | - def get_frames(self) -> tuple: |
189 | | - """ |
190 | | - Collect frames for camera and outputs it in 'color' dictionary |
191 | | - ***depth and infrared are not used here*** |
192 | | - :return: tuple of three dictionaries: color, depth, infrared |
193 | | - """ |
194 | | - |
195 | | - color_frames = {} |
196 | | - depth_maps = {} |
197 | | - infra_frames = {} |
198 | | - |
199 | | - if self._footage_socket: |
200 | | - ret = True |
201 | | - else: |
202 | | - ret = False |
203 | | - self.last_frame_time = time.time() |
204 | | - if ret: |
205 | | - # if not self.initial_wait: |
206 | | - # cv2.waitKey(1000) |
207 | | - # self.initial_wait = True |
208 | | - # receives frame from stream |
209 | | - image = self._footage_socket.recv_string() |
210 | | - # converts image from str to image format that cv can handle |
211 | | - image = self.string_to_image(image) |
212 | | - image = cv2.resize(image, RESOLUTION) |
213 | | - color_frames[self._camera_name] = image |
214 | | - running_time = time.time() - self.last_frame_time |
215 | | - if running_time <= 1 / FRAMERATE: |
216 | | - sleepy_time = int(np.ceil(1000/FRAMERATE - running_time / 1000)) |
217 | | - cv2.waitKey(sleepy_time) |
218 | | - |
219 | | - else: |
220 | | - raise MissingFrameError('No frame was received from the webcam stream. Make sure that you started streaming on the host machine.') |
221 | 157 |
|
222 | | - return color_frames, depth_maps, infra_frames |
223 | | - |
224 | | - def enable_stream(self, resolution, framerate, *args): |
225 | | - """ |
226 | | - Not used for webcam streaming over network |
227 | | - """ |
228 | | - pass |
0 commit comments