def compute_image_features(self, image, print_arr=False): image_feature = [] try: image_path = os.path.join(os.path.dirname(__file__), image) image = misc.read_image(image_path) converted_image = misc.convert2gray(image) if self.model_name == 'CM': converted_image = misc.convert2yuv(image) if self.model_name == 'HOG': converted_image = misc.resize_image(converted_image, (120, 160)) if self.split_windows: windows = misc.split_into_windows(converted_image, 100, 100) for window in windows: window_pattern = self.model.compute(window) if len(image_feature) == 0: image_feature = window_pattern else: image_feature = np.concatenate( [image_feature, window_pattern]) else: image_feature = self.model.compute(converted_image) except OSError as e: print("Features_image", e.strerror) sys.exit() finally: if not print_arr: return image_feature else: print(image_feature)
def _precalculate_one_image(self, coords, pf, dsp, termsize): img = self._get_image(*coords) return ( pf.encode_image(img) if pf else None, dsp.encode_image(img, dsp.size) if dsp else None, pixelterm.termify_pixels(resize_image(img, termsize)) if termsize else None )
def encode_image(img, displaysize): return np.frombuffer(Display.do_gamma(resize_image(img, displaysize), 0.5).convert('1').tobytes(), dtype='1b')
for agent in agents: while time.time() - ts < args.wait: if random.random() > 0.2: action = random.choice(agent.animations) print('Playing:', action) for img_pf, img_dsp, img_term in agent(action, not args.nosleep): with runlock: if args.terminal: print('\033[H'+img_term) if args.display: dsp.sendframe(img_dsp) if args.pixelflut: pf.sendframe(img_pf) if time.time() - ts > args.wait: print('Force-advance', ts) break if not args.nosleep: time.sleep(1) print('Advancing', ts) ts = time.time() else: for img_pf, img_dsp, img_term in agents[0](args.action, not args.nosleep): if args.terminal: print(pixelterm.termify_pixels( resize_image(img, termsize))) if args.display: dsp.sendframe(img_dsp) if args.pixelflut: pf.sendframe(img_pf)