def __init__(self): self.tasks = [] self.camera = Camera() self.window = Window('Camera') self.should_detect = True self.trackers = [] self.color_filter = ColorFilter()
def classify(self): w = ['observation', 'prediction', 'target'] window = Window(*[int(self.config['window'][x]) for x in w]) # # Create the network of nodes (the source and its neighbors) # self.log.info('{0} + create network'.format(self.nid)) n = self.config['neighbors'] cluster = self.nhandler[n['selection']] self.network = nt.Network(self.nid, int(n['depth']), cluster) self.log.info('{0} - create network'.format(self.nid)) depth = self.network.depth() if depth != int(n['depth']): msg = 'Depth not fully explored: {0} < {1}' raise ValueError(msg.format(depth, n['depth'])) root = self.network.node assert (root.nid == self.nid) # # Clean up the nodes: All nodes are shifted, interpolated, and # time-aligned with the root. Missing values at the root are # maintained to determine which windows are valid to process. # s = root.readings.speed missing = s[s.isnull()].index for i in self.network: n = i.node n.readings.shift(i.lag) n.align(root, True) # # Build the observation matrix by looping over the root nodes # time periods # self.log.info('{0} + observe'.format(self.nid)) observations = [] for i in root.range(window): whole = [missing.intersection(x).size == 0 for x in i] if all(whole): (left, right) = i mid = left[-len(right):] assert (len(mid) == len(right)) labels = self._labels(root, mid, right) features = self._features(self.network.nodes(), left) observations.append(features + labels) self.log.info('{0} - observe {1}'.format(self.nid, len(observations))) return observations
def tune(self): tune_window = Window('Tune Window') colors = [(0, 255, 0), (255, 255, 0), (255, 0, 0), (0, 0, 255)] print print 'press Q to cancel the whole selection process' print try: print len(self.rect_points), self.rect_points print len(self.check_points[0]), self.check_points[0] print len(self.check_points[1]), self.check_points[1] print len(self.start_points), self.start_points except: pass while True: frame = self._get_video_frame() try: for p in self.rect_points: cv2.circle(frame, p, 3, colors[0], thickness=2) for p in self.check_points[0]: cv2.circle(frame, p, 3, colors[1], thickness=2) for p in self.check_points[1]: cv2.circle(frame, p, 3, colors[2], thickness=2) for p in self.start_points: cv2.circle(frame, p, 3, colors[3], thickness=2) except: pass tune_window.draw(frame) key_cmp = lambda k, c: k is ord(c.upper()) or k is ord(c.lower()) key = tune_window.wait() if key_cmp(key, 'q'): tune_window.close() break;
def main(): """ Prepara las ventanas, define modelos, controlador y vista y corre el programa. :return: void """ # Se obtiene el checksum del juego checksum = [ path_checksum('lib', VERBOSE), '8e1fd1c03d2bfe89d7dbdab8b0c4c69a'.upper(), path_checksum('bin', VERBOSE) ] # Se cargan las configuraciones control_config = Configloader(DIR_CONFIG + 'control.ini', verbose=VERBOSE) game_config = Configloader(DIR_CONFIG + 'game.ini', verbose=VERBOSE) map_config = Configloader(DIR_CONFIG + 'map.ini', verbose=VERBOSE) score_config = Configloader(DIR_CONFIG + 'scoreboard.ini', verbose=VERBOSE) user_config = Configloader(DIR_CONFIG + 'user.ini', verbose=VERBOSE) view_config = Configloader(DIR_CONFIG + 'view.ini', verbose=VERBOSE) window_config = Configloader(DIR_CONFIG + 'window.ini', verbose=VERBOSE) world_config = Configloader(DIR_CONFIG + 'world.ini', verbose=VERBOSE) # Se carga el idioma lang = langs.Langloader(game_config.getValue('LANG')) # Se carga la información de la pantalla del cliente display_info = pygame.display.Info() # Se comprueba que el nombre de jugador no sea Player, si no es valido se pide uno nuevo if not username.validate(user_config.getValue('NAME')): new_name = username.request(lang.get(111), lang.get(112)) if new_name is not username.NO_VALID_NAME: user_config.setParameter('NAME', new_name) user_config.export() else: utils.destroy_process() # Creación de ventana window = Window(window_config, lang.get(10), pygame.image.load(getIcons('icon')), display_info) clock = pygame.time.Clock() # Reloj fps = int(game_config.getValue('FPS')) # FPS a dibujar # Se crea el mundo world = World(world_config, map_config, window, checksum, score_config, user_config, lang, game_config, verbose=VERBOSE) # world.load_map(1) # Se crean los menús de inicio y pause menus = Createuimenu(lang, window, world, game_config, user_config, view_config, window_config, world_config, map_config) # Se crea la vista vista = View(window, clock, world, lang, view_config, menus) menus.addView(vista) # Se crea el controlador control = Controller(world, clock, lang, control_config, window, menus, verbose=VERBOSE) menus.addController(control) vista.add_controller(control) # Se lanza el mainloop while True: clock.tick(fps) vista.draw(control.event_loop())
def loop(window): for i in range(window.prediction): for j in range(1, window.target): yield Window(j, i, j)
d[j] = np.sqrt(df.sum(i)) return d def heatplot(fig, directory, fname, labels, extension='png'): fig.set(**labels) f = Path(args.figures, fname).with_suffix('.' + extension) utils.mkplot_(fig, str(f)) ############################################################################# cargs = cli.CommandLine(cli.optsfile('chgpt')) args = cargs.args window = Window(args.window_obs, args.window_pred, args.window_trgt) if args.resume: with open(args.resume, mode='rb') as fp: observations = pickle.load(fp) else: db.genop(args.reporting) classifier = cpoint.Acceleration(args.threshold) opts = [window, classifier.classify, 'D'] with Pool() as pool: observations = pool.starmap(f, nd.nodegen(opts)) if args.pickle: with open(args.pickle, mode='wb') as fp: pickle.dump(observations, fp)
def __init__(self): self._API_CONFIG = get_config('1q_api') self._window = Window(get_config('node_name')) self._app = Application(self._window)
class MainGui: def __init__(self): self._API_CONFIG = get_config('1q_api') self._window = Window(get_config('node_name')) self._app = Application(self._window) def exec(self, start=False): """ execution :return: void """ try: self._window.set_real_name(self._API_CONFIG['target']['real_name']) self._window.set_symbol_name(self._API_CONFIG['target']['symbol']) self._window.append_log('[run] Initialize main application.') self._window.set_quit_button_listener(self.quit) self._window.set_run_button_listener(self.run) self._window.open_window() if start is True: self.run() except Exception as _e: self._window.append_log('[exec] ERROR: {}'.format(str(_e))) def stop(self): """ stop :return: void """ try: self._window.append_log('[stop] service stopping..') self._window.set_run_button_text('STOPPING..') self._window.delete_run_button_listener() self._app.disconnect() self._window.append_log('[stop] service stop complete.') except Exception as _e: self._window.append_log('[stop] ERROR: {}'.format(str(_e))) finally: self._window.set_run_button_text('START') self._window.set_run_button_listener(self.run) def quit(self): """ quit application :return: void """ self.stop() self._window.close_window() sys.exit() def run(self): """ start :return: void """ try: self._window.set_run_button_text('STARTING..') self._window.delete_run_button_listener() self._app.connect() self._window.set_run_button_text('STOP') self._window.set_run_button_listener(self.stop) self._app.listen_real() except Exception as _e: self._window.append_log('[run] ERROR: {}'.format(str(_e))) self.stop()
if mode == "v" or pyautogui.locateOnScreen( 'media/title-window/cave_wall.png', confidence=.8): if status.stamin: pyautogui.typewrite('l') count += 1 time.sleep(random.random() * 2) if mode == "v" and count >= random.randint(10, 50): pyautogui.typewrite('l') time.sleep(random.random()) pyautogui.typewrite('l') time.sleep(random.random()) pyautogui.typewrite('l') pile_of_items = Window( title='media/box-titles/pile-of-items.png') bsb = Window(title='media/box-titles/bsb.png') pyautogui.typewrite('l') s_s = pile_of_items.find_item(item="media/items/ore_iron.png") mouse.move((s_s[0][0], s_s[0][1]), 2) pyautogui.mouseDown() bsb_workspace = bsb.get_workspace() mouse.move((bsb_workspace['left'], bsb_workspace["top"] + bsb_workspace["height"]), 2) pyautogui.mouseUp() time.sleep(random.random() * 2.5) mouse.move( (random.randint(2679, 2690), random.randint(472, 490)), 2) mouse.click() # 2679 472
self.window = window self.label = pyglet.text.Label('', font_name="Linux Libertine", font_size=28, x=self.window.width-10, y=10, anchor_x='right', anchor_y='bottom') self.label.text = "INITIATING MAPSET..." mapset = MapSet(map_name) self.label.text = "INITIATING MAPVIEW..." mapview = MapView(mapset, self.window) interface = Interface(self.window) renderer = Renderer(self.window, mapview, interface) self.window.pop_handlers() self.window.push_handlers(renderer) self.window.push_handlers(mapview) self.window.push_handlers(interface) if __name__ == '__main__': pyglet.gl.glBlendFunc(pyglet.gl.GL_SRC_ALPHA, pyglet.gl.GL_ONE_MINUS_SRC_ALPHA) window = Window(width=1024, height=768) if len(sys.argv) < 2: sys.exit("specify the map you want to load from the map folder\nusage: python hr.py \"A Viking We Shall Go\"") if not os.path.exists(os.path.join(pyglet.resource._default_loader._script_home,"maps","%s.h3m" % sys.argv[1])): sys.exit("cannot find file %s" % os.path.join(pyglet.resource._default_loader._script_home,"maps","%s.h3m" % sys.argv[1])) window.push_handlers(LoadScreen(window, sys.argv[1])) img = pyglet.resource.image("data/cursors/cradvntr.def/0.png") window.set_mouse_cursor(pyglet.window.ImageMouseCursor(img, 0, 40)) pyglet.app.run()
from status import Status_Bar from pyclick import HumanClicker # super symulacja ruchu myszki import pyautogui import time from random import randint, random from lib.craft import Crafting from lib.window import Window mouse = HumanClicker() status = Status_Bar() t = Crafting(button='media/box-titles/create.png') source = Window(title='media/box-titles/source.png') inventory = Window(title='media/box-titles/inventory.png') target = Window(title='media/box-titles/target.png') while True: if status.stamin: t.continue_() # Get resources s_s = source.find_item(item="media/items/stone_shards.png") mouse.move((s_s[0][0], s_s[0][1]), 2) pyautogui.mouseDown() inventory_workspace = inventory.get_workspace() mouse.move( (inventory_workspace['left'], inventory_workspace["top"] + inventory_workspace["height"]), 2) pyautogui.mouseUp() time.sleep(random() * 2.5) pyautogui.press('enter') # Add resources to Crafting window and combine it
def do_activate(self): win = Window(self) win.show()
class Main: def __init__(self): self.tasks = [] self.camera = Camera() self.window = Window('Camera') self.should_detect = True self.trackers = [] self.color_filter = ColorFilter() def add_target(self, filename): self.trackers.append(Tracker(filename)) def clear(self): for tracker in self.trackers: tracker.clear() def loop(self): runner = CmdRunner(self) runner.start() while runner.isAlive(): while len(self.tasks) > 0: task = self.tasks.pop(0) task.execute() try: img = self.camera.get_frame() if img is None: self.window.clear() continue img = cv2.resize(img, (640, 480)) # TODO: show color mask color_mask = self.color_filter.filter(img) next_should_detect = self.should_detect for tracker in self.trackers: if self.should_detect: rect = tracker.detect(img) if rect is not None: ret = tracker.update_window(img, rect) self.window.draw_rectangle(rect, (255, 0, 255)) next_should_detect = False rect = tracker.track(img) if rect is None: next_should_detect = True continue self.window.draw_rectangle(rect, (255, 0, 0)) self.should_detect = next_should_detect except Exception as e: print >> sys.stderr, e finally: self.window.update() runner.join(0) def _add_task(self, task): self.should_detect = True self.tasks.append(task) def do_add_target(self, filename): self._add_task(Task(self.add_target, (filename, ))) def do_clear(self): self._add_task(Task(self.clear)) def do_snapshot(self, filename): self._add_task(Task(self.window.snapshot, (filename, ))) def do_switch_camera(self, cid): self._add_task(Task(self.camera.switch, (cid, )))
def start(self, video): ps = PumpSpark() try: ps.pump2([ ([(1, 254), (4, 254)], 10), ([(2, 100), (5, 100)], 12), ([(1, 254), (4, 254)], 10)]) except: pass window = Window('Water Ira-Ira Bou') mask_window = Window('Mask') fps = video.get(cv.CV_CAP_PROP_FPS) if fps > 0: window.fps = fps h = int(video.get(cv.CV_CAP_PROP_FRAME_HEIGHT)) w = int(video.get(cv.CV_CAP_PROP_FRAME_WIDTH)) rect = bounding_rect(self.rect_points) cfilter_bar = ColorFilter(self.color_range_bar) cfilter_water = ColorFilter(self.color_range_water) searcher_bar = CheatSearcher(self.check_points[0]) searcher_water = CheatSearcher(self.check_points[1]) colors = [(0, 255, 0), (255, 255, 0)] ret, frame = video.read() if not ret: 'frame is null' bar_index = 0 water_index = 0 start = False print self.color_range_bar while True: key = window.wait() if key is ord('Q') or key is ord('q'): break ret, frame = video.read() if not ret: break current_img = crop(frame, rect) mask_bar = cfilter_bar.get_mask(current_img) mask_water = cfilter_water.get_mask(current_img) bar_index, (x, y) = searcher_bar.search(mask_bar, bar_index) cv2.circle(current_img, (x, y), 3, colors[0], thickness=2) water_index, (x, y) = searcher_water.search(mask_water, water_index) cv2.circle(current_img, (x, y), 3, colors[0], thickness=2) mask_window.draw(mask_bar) window.draw(current_img) if bar_index != 0 and start == False: play_sound('sound/button-8.wav') start = True mask_window.close() window.close() ps.turnOff()