def IsMyRound(): os.chdir(os.path.dirname(os.path.abspath(__file__))) # initialize the WindowCapture class wincap = WindowCapture('Legends of Runeterra') # finding myRound.jpg #vision_IP = Vision('img\minalegal.jpg') vToFind = Vision('img\isMyRound.jpg') loop_time = time() while(True): screen = wincap.get_screenshot() points = vToFind.find(screen, 0.99, 'rectangles') #print('FPS {}'.format(1 / (time() - loop_time))) if points: print('Is my turn.') else: print('Not my turn') pass loop_time = time() #return False if cv.waitKey(1) == ord('q'): cv.destroyAllWindows() break pass
loop_time = time() while (True): # get an updated image of the game screenshot = wincap.get_screenshot() points_1 = [] points_2 = [] points_3 = [] #points_4 = [] points_5 = [] points_6 = [] points_7 = [] #points_62 = [] points_pr = [] # display the processed image points_1 = vision_pilar1.find(screenshot, 0.45, 'rectangles') points_2 = vision_pilar2.find(screenshot, 0.6, 'rectangles') points_3 = vision_pilar3.find(screenshot, 0.6, 'rectangles') #points_4 = vision_pilar4.find(screenshot, 0.5) points_5 = vision_pilar5.find(screenshot, 0.6, 'rectangles') points_6 = vision_pilar6.find(screenshot, 0.6, 'rectangles') points_7 = vision_pilar7.find(screenshot, 0.6, 'rectangles') points_pr = vision_pilarPr.find(screenshot, 0.69, 'rectangles') #points_62 = vision_pilar62.find(screenshot,0.5, 'rectangles') if len(points_pr): print('pilar prohibido') elif len(points_1) or len(points_2) or len(points_3) or len( points_5) or len(points_6) or len(points_7): clicker = Bot() clicker.click()
vision_limestone.init_control_gui() # limestone HSV filter hsv_filter = HsvFilter(0, 180, 129, 15, 229, 243, 143, 0, 67, 0) loop_time = time() while (True): # get an updated image of the game screenshot = wincap.get_screenshot() # pre-process the image processed_image = vision_limestone.apply_hsv_filter(screenshot, hsv_filter) # do object detection rectangles = vision_limestone.find(processed_image, 0.46) # draw the detection results onto the original image output_image = vision_limestone.draw_rectangles(screenshot, rectangles) # display the processed image cv.imshow('Processed', processed_image) cv.imshow('Matches', output_image) # debug the loop rate print('FPS {}'.format(1 / (time() - loop_time))) loop_time = time() # press 'q' with the output window focused to exit. # waits 1 ms every loop to process key presses if cv.waitKey(1) == ord('q'):
def runCommsCheck(): send('test', 123) result = rioComms.receive(TABLE_NAME, 'test', 404) print("No Comms") if result == 404 else print("Network Established") return (False if result == 404 else True) def send(key, value): rioComms.send(TABLE_NAME, key, value) #Instantiate vision object to look for objects with 8 vertices vision = Vision(8) targets = vision.find() rioComms = RioComms(SERVER_URL) if (runCommsCheck()): while 1: targets = vision.find() #print(vision.find()) if (len(targets) > 0): value = targets[0].getAngleToCenterFromCamera( vision.resX, vision.resY, VIEWPORT_ANGLE_X, VIEWPORT_ANGLE_Y) print(value[0]) send(X_KEY_PREFIX, value[0])
# initialize the Vision class vision_limestone = Vision('albion_limestone.jpg') ''' # https://www.crazygames.com/game/guns-and-bottle wincap = WindowCapture() vision_gunsnbottle = Vision('gunsnbottle.jpg') ''' loop_time = time() while(True): # get an updated image of the game screenshot = wincap.get_screenshot() # display the processed image points = vision_limestone.find(screenshot, 0.5, 'rectangles') #points = vision_gunsnbottle.find(screenshot, 0.7, 'points') # debug the loop rate print('FPS {}'.format(1 / (time() - loop_time))) loop_time = time() # press 'q' with the output window focused to exit. # waits 1 ms every loop to process key presses if cv.waitKey(1) == ord('q'): cv.destroyAllWindows() break print('Done.')
# Reversing the RGB values # screenshot = screenshot[:, :, ::-1].copy() # More self-documenting version below: # screenshot = cv.cvtColor(screenshot, cv.COLOR_RGB2BGR) # screenshot = window_capture() screenshot = wincap.get_screenshot() # Processed Image shown instead of raw screenshot! # We show image in our find() function. # cv.imshow('Computer Vision', screenshot) # findClickPositions('', screenshot, threshold=0.72, debug_mode='points') # Show the best match only. Must run find() at least once however. if not firstRun: bestMatch = vision_speedchat.bestMatch() points = vision_speedchat.find(screenshot, bestMatch, 'rectangles') else: points = vision_speedchat.find(screenshot, 0.72, 'rectangles') firstRun = False # debug the loop rate - bad atm print('FPS {}'.format(1 / (time() - loop_time))) loop_time = time() # Press 'q' with the output window focused to exit. # Waits 1 ms every loop to process key presses if cv.waitKey(1) == ord('q'): cv.destroyAllWindows() break print('Done.')
# HSV filter to needle img #hsv_filter = HsvFilter(0,0,0,0,0,0,0,0,0,0) loop_time = time() while (True): screenshot = wincap.get_screenshot() # cv.imshow('computer vision', screenshot) # pre-process image # processed_image = vision_friend.apply_hsv_filter(screenshot,hsv_filter) #object detection # Processed needle image finding # rectangles = vision_friend.find(processed_image, threshhold=0.8) rectangles = vision_friend.find(screenshot, threshhold=0.8) # draw detection result on original image output_image = vision_friend.draw_rectangles(screenshot, rectangles) cv.imshow("matches", output_image) print('FPS {}'.format(1 / (time() - loop_time))) loop_time = time() if cv.waitKey(1) == ord('q'): cv.destroyAllWindows() break print('Done')
class Movement: # Properties wincap = None vision_target = None firstRun = True points = [] current = '' key = None user = b'gAAAAABf470AGsKOJ65Ee9ZxZasRjABVUbdimwfivMloakcKoa20R_guknxp0K7xqYAbLD5IfZ9dUMJP77lKTM6oWRpYl17GHw==' pw = b'gAAAAABf470AeGuSrJmZEZrBzs8rJEQqiUDUoArQPNSkMJnlaKyxEknOUXvtvpWlLbTqBkq0SnEnYvjadV7gFI1sd7jtJJbImQ==' # Constructor def __init__(self, target, haystack_wnd='Toontown Rewritten'): # Window Capture has default to TTR, else we choose from main. self.wincap = WindowCapture(window_name=haystack_wnd) # Previously, we had to use the object to call this function. # Now that it is static, we can call the class directly. # wincap.list_window_names() # WindowCapture.list_window_names() # check foreground window title current = self.wincap.title() """ The Encryption Method I used: click.write_key() key = click.load_key() message1 = user.encode() print(message1) - bytes now message2 = pw.encode() print(message2) f = Fernet(key) encrypted1 = f.encrypt(message1) encrypted2 = f.encrypt(message2) print(encrypted1) print(encrypted2) """ # Decrypt our user name and pw. IF you want to use it, # remove the encryption method, or generate your own encrypted values. # Add in your own user/pw instead.`` self.key = self.load_key() f = Fernet(self.key) # Target is selectable from main file now. if (current == "Toontown Rewritten Launcher"): # Make TextBox Bigger self.vision_target = Vision('TextBox.png') # empty bits on bitmap, idk how they made the launcher # self.locator() # Just send input pdi.press(['tab']) time.sleep(0.05) pdi.typewrite(f.decrypt(self.user).decode()) time.sleep(0.05) pdi.press(['tab']) time.sleep(0.05) pdi.typewrite(f.decrypt(self.pw).decode()) time.sleep(0.05) pdi.press(['enter']) time.sleep(0.05) else: self.vision_target = Vision(target) # Only find best match self.locator(multi=False) def locator(self, single=False, multi=True): loop_time = time() if not single: while (True): # screenshot = None # screenshot = pyautogui.screenshot() # cv.imshow is not compatable with pyautogui ss format. # so we use numpy. # screenshot = ImageGrab.grab() # screenshot = np.array(screenshot) # Reversing the RGB values # screenshot = screenshot[:, :, ::-1].copy() # More self-documenting version below: # screenshot = cv.cvtColor(screenshot, cv.COLOR_RGB2BGR) # screenshot = window_capture() screenshot = self.wincap.get_screenshot() # Processed Image shown instead of raw screenshot! # We show image in our find() function. # cv.imshow('Computer Vision', screenshot) # findClickPositions('', screenshot, threshold=0.72, debug_mode='points') # Show the best match only. Must run find() at least once however. if not multi: if not self.firstRun: bestMatch = self.vision_target.bestMatch() self.points = self.vision_target.find( screenshot, bestMatch, 'rectangles') else: self.points = self.vision_target.find( screenshot, 0.9, 'rectangles') self.firstRun = False else: self.points = self.vision_target.find( screenshot, 0.9, 'rectangles') # debug the loop rate - bad atm print('FPS {}'.format(1 / (time() - loop_time))) loop_time = time() # Press 'q' with the output window focused to exit. # Waits 1 ms every loop to process key presses if cv.waitKey(1) == ord('q'): cv.destroyAllWindows() break # For single uses else: screenshot = self.wincap.get_screenshot() if not multi: if not self.firstRun: bestMatch = self.vision_target.bestMatch() self.points = self.vision_target.find( screenshot, bestMatch, 'rectangles') else: self.points = self.vision_target.find( screenshot, 0.9, 'rectangles') self.firstRun = False else: self.points = self.vision_target.find(screenshot, 0.9, 'rectangles') while (True): if cv.waitKey(1) == ord('q'): cv.destroyAllWindows() break print('Done.') # Encrypts our user/pw def write_key(self): # Generates a key and save it into a file self.key = Fernet.generate_key() with open("key.key", "wb") as key_file: key_file.write(self.key) def load_key(self): # Loads the key from the current directory named `key.key` return open("key.key", "rb").read()
wincap = WindowCapture('Legends of Runeterra') # initialize the WindowCapture class #vision_IP = Vision('img\minalegal.jpg') fogolivre = ["img\\oomcrewrookie.jpg", "img\\crimsondisciple.jpg", "img\\decimate.jpg", "img\\getexcited.jpg", "img\\imperialdemoli.jpg", "img\\legiongran.jpg", "img\\legionrear.jpg", "img\\legionsaboteur.jpg", "img\\mysticshot.jpg", "img\\oxianfervor.jpg", "img\\preciouspet.jpg", "img\\statikkshock.jpg", "img\\sformation.jpg", "img\\usedcasksalesman.jpg"] vToFind = Vision(fogolivre[6]) loop_time = time() while(True): screenshot = wincap.get_screenshot() #cv.imshow('Computer Vision', screenshot) # Esse funciona # points = vision_IP.find(screenshot, 0.7, 'rectangles') points = vToFind.find(screenshot, 0.99, 'rectangles') #print('FPS {}'.format(1 / (time() - loop_time))) #print('FPS {}'.format(time() - loop_time)) loop_time = time() # press 'q' with the out if cv.waitKey(1) == ord('q'): cv.destroyAllWindows() break print('Done.') #endregion #region Procurando imagem dentro do jogo ''' #haystack_img = cv.imread('img/myRound.png', cv.IMREAD_UNCHANGED)
# Doing this because I'll be putting the files from each video in their own folder on GitHub os.chdir(os.path.dirname(os.path.abspath(__file__))) # initialize the WindowCapture class wincap = WindowCapture('Calculator') print(WindowCapture.list_window_names()) print(wincap.get_element_tree()) vision_limestone = Vision('seven.jpg') print(vision_limestone) loop_time = time() while (True): # get an updated image of the game screenshot = wincap.get_screenshot() points = vision_limestone.find(np.array(screenshot), 0.8, 'rectangles') cv.imshow('Computer Vision', np.array(screenshot)) # debug the loop rate print('FPS {}'.format(1 / (time() - loop_time))) loop_time = time() # press 'q' with the output window focused to exit. # waits 1 ms every loop to process key presses if cv.waitKey(1) == ord('q'): cv.destroyAllWindows() break print('Done.')
def countdown(timer): while timer: mins, secs = divmod(timer, 60) timeformat = '{:02d}:{:02d}'.format(mins, secs) print(timeformat, end='\r') time.sleep(1) timer -= 1 return mins loop_time = time() while(True): # get an updated image of the game screenshot = wincap.get_screenshot() # display the processed image points1 = vision_cash.find(screenshot, 0.41, 'rectangles') #points = vision_gunsnbottle.find(screenshot, 0.7, 'points') # # print(x_coord[0]) # click () # ============================================================================= # if timer == 0: # # click(points[0][0], points[0][1]) # timer = timer + 300 # =============================================================================