def run(): while True: screen = grab_screen(region=(0, 0, 1920, 1080)) crop = screen[85:950, 0:970] # select region of interest center = int(crop.shape[0] / 2), int(crop.shape[1] / 2) # x,y,r copy = crop.copy() gray = cv2.cvtColor(copy, cv2.COLOR_RGB2GRAY) # use HoughCircles to detect circles within image circle_coords, img = circles(gray) # calculate distance to smallest detected circles closest_coord, all_circles = find_smallest_r(circle_coords, center) print(f'Moving to -> {closest_coord}') # go to eat closest blob thats smaller than me move(closest_coord[0], closest_coord[1]) # ToDo: implement functionality to go as long as own radius increases # g = [i for i in all_circles if (i[0] > center[0]-5) & (qi[0] < center[0]+5) & (i[1] > center[1]-5) & (i[1] < center[1]+5)] # if len(g) > 0: # new_radius = g[0][2] time.sleep(1)
def run_while(): while keyboard.is_pressed('q') == False: last = time.time() screen = grab_screen(region=(0, 0, 1920, 1080)) crop_img = screen[320:820, 150:810] threshold_slow(crop_img)
def make_grid_image(grab_area): img = np.zeros(get_hw(grab_area)) for i in tqdm(range(50)): refresh(grab_area) time.sleep(0.5) ss = grab_screen(grab_area) gray = cv2.cvtColor(ss, cv2.COLOR_BGR2GRAY) ret, thresh = cv2.threshold(gray, 150, 255, 0) img += 255 - thresh img = np.clip(img, 0, 255) cv2.imwrite('grid.png', 255 - img)
def main(): mkdir_if_not_exists(IMAGE_DIR) empty_dir(IMAGE_DIR) grab_area = read_grab_area() crop_areas = find_crop_areas() for _ in tqdm(range(2 ** 11)): ss = grab_screen(grab_area) draw_crop_areas(ss, crop_areas) for img in crop_images(ss, crop_areas): save_path = os.path.join(IMAGE_DIR, generate_uuid() + '.png') cv2.imwrite(save_path, img) refresh(grab_area) time.sleep(1)
def look_at_image(): screen = grab_screen(region=(0, 0, 1920, 1080)) crop_img = screen[320:820, 150:810] plt.imshow(crop_img) plt.show()
# start """ vec = 315 # po gradusam iz 360, gde 0 - verh, 90 - pravo, 180 - niz, 270 - levo game = self_window() for i in list(range(4))[::-1]: print(i + 1) time.sleep(1) other_route_vector = None enemy_spotted = False paused = False while True: if not paused: img = (grab_screen(region=(game.differenceX, game.differenceY, 800 + game.differenceX - 1, 600 + game.differenceY - 1))) if enemy_spotted is True: enemy_spotted = check_if_enemy_on_hover(img[22, 330]) if enemy_spotted is True: continue # cursor_pos = game.cursor_pos() # file_name = 'img_cursorPos.npy' # examples = [img, cursor_pos,game] # np.save(file_name,examples) #read minimap minimap = img[4:154, 646:796] # visota sverhu, shirina sleva minimap = minimap[ 40:110, 40:110] # 70x70 # - vidimost' zoni na kotoryuy mojno clicknut'