def _view_image_array(self): if self.force_scale: self.original_image_array = self.image_array[:] for i in range(len(self.image_array)): img, intensity = self.image_array[i] img = ptpscale(intensity) img = np.minimum(np.maximum(img, 0), 255).astype('B') self.image_array[i] = (img, intensity) else: self.original_image_array = None self.window.set_caption(self.name + ' - %d' % self.fcnt) img = self._stack([img for img, _ in self.image_array]) intensity = self._stack([ii for _, ii in self.image_array]) self.color_mask = np.hstack([[len(ii.shape)==3] * ii.shape[1] for _, ii in self.image_array]) # FIXME: split image_array if self.image is None: resize = True else: resize = img.shape != self.prev_image_shape self.prev_image_shape = img.shape if len(img.shape) == 3: f = 'RGB' pitch = -img.shape[1] * 3 else: f = 'I' pitch = -img.shape[1] self.image = pyglet.image.ImageData(img.shape[1], img.shape[0], f, img.tostring(), pitch) texture = get_texture(self.image) glTexParameteri(texture.target, GL_TEXTURE_MAG_FILTER, GL_NEAREST) glTexParameteri(texture.target, GL_TEXTURE_MIN_FILTER, GL_NEAREST) if resize: self.on_resize(self.window.width, self.window.height) self.intensity = intensity while True: self._dispatch_events() if not DebugViewer.paused: self.mystep = DebugViewer.step_counter break elif self.mystep < DebugViewer.step_counter: self.mystep += 1 break
def _view_image_array(self): if self.force_scale: self.original_image_array = self.image_array[:] for i in range(len(self.image_array)): img, intensity = self.image_array[i] img = ptpscale(intensity) img = np.minimum(np.maximum(img, 0), 255).astype('B') self.image_array[i] = (img, intensity) else: self.original_image_array = None self.window.set_caption(self.name + ' - %d' % self.fcnt) img = self._stack([img for img, _ in self.image_array]) intensity = self._stack([ii for _, ii in self.image_array]) self.color_mask = np.hstack([len(ii.shape)==3] * ii.shape[1] for _, ii in self.image_array) # FIXME: split image_array if self.image is None: resize = True else: resize = img.shape != self.prev_image_shape self.prev_image_shape = img.shape if len(img.shape) == 3: f = 'RGB' pitch = -img.shape[1] * 3 else: f = 'I' pitch = -img.shape[1] self.image = pyglet.image.ImageData(img.shape[1], img.shape[0], f, img.tostring(), pitch) glTexParameteri(self.image.texture.target, GL_TEXTURE_MAG_FILTER, GL_NEAREST) glTexParameteri(self.image.texture.target, GL_TEXTURE_MIN_FILTER, GL_NEAREST) if resize: self.on_resize(self.window.width, self.window.height) self.intensity = intensity while True: self._dispatch_events() if not DebugViewer.paused: self.mystep = DebugViewer.step_counter break elif self.mystep < DebugViewer.step_counter: self.mystep += 1 break
def view(self, img, scale=False): if img.dtype == 'bool': img = img.astype('B') if scale: img = ptpscale(img) if img.dtype != 'B': img = np.minimum(np.maximum(img, 0), 255).astype('B') img = cv2.cvtColor(img, cv2.COLOR_RGB2BGR) if self.video is None: height, width, _ = img.shape for codec in [cv2.cv.FOURCC(*"H264"), cv2.cv.FOURCC(*"DIVX"), -1]: self.video = cv2.VideoWriter(self.filename, codec, self.fps, (width, height)) if self.video.isOpened(): break self.video.write(img)
def view(self, img, scale=False, intensity=None, pause=None): with global_pyglet_lock: if img.dtype == 'bool': img = img.astype('B') if intensity is None: intensity = img if scale: img = ptpscale(img) if img.dtype != 'B': img = np.minimum(np.maximum(img, 0), 255).astype('B') if pause is not None: DebugViewer.paused = pause if self.autoflipp: self.image_array = [(img, intensity)] self._inc_fcnt() self._view_image_array() else: self.image_array.append((img, intensity))
def view(self, img, scale=False): if img.dtype == 'bool': img = img.astype('B') if scale: img = ptpscale(img) if img.dtype != 'B': img = np.minimum(np.maximum(img, 0), 255).astype('B') if len(img.shape) == 2: img = cv2.cvtColor(img, cv2.COLOR_GRAY2RGB) else: img = cv2.cvtColor(img, cv2.COLOR_RGB2BGR) if self.video is None: height, width, _ = img.shape for codec in [ 875967048, 1482049860, -1 ]: #[cv2.cv.FOURCC(*"H264"), cv2.cv.FOURCC(*"DIVX"), -1]: self.video = cv2.VideoWriter(self.filename, codec, self.fps, (width, height)) if self.video.isOpened(): break self.video.write(img)