def CordsToImage(y1, x1, y2, x2): time.sleep(1) box = (y1, x1, y2, x2) pytezzeret.pytezzeret.tesseract_cmd = r"C:\Program Files\Tesseract-OCR\tesseract.exe" im = ImageGrab.grab(box) if box != (0, 0, 0, 0): resize_im = im.resize((0, 0), resample=Image.NEAREST) #(170, 139) The values work when resizing image for # the amount of cards in hand text = pytezzeret.image_to_string(cv2.cvtColor(numpy.array(resize_im), cv2.IMREAD_GRAYSCALE), lang='eng') resize_im.show() print(text) print() split_text = text.split() print(split_text) #time.sleep(3) return split_text else: print("else statement") text = pytezzeret.image_to_string(cv2.cvtColor(numpy.array(im), cv2.IMREAD_GRAYSCALE), lang='eng') #im.show() print(text) print() #split_text = text.split() #print(split_text) #time.sleep(3) return text
def image_to_text(image): """Reading the text that is embedded in images and spliting it. """ time.sleep(6) pytezzeret.pytezzeret.tesseract_cmd = r"C:\Program Files\Tesseract-OCR\tesseract.exe" im = ImageGrab.grab(image) #resize_im = im.resize((0, 0), resample=Image.NEAREST) #(width, height) text = pytezzeret.image_to_string(cv2.cvtColor(numpy.array(im), cv2.IMREAD_GRAYSCALE), lang='eng') #im.show() print(text) split_text = text.split() print(split_text) return split_text
def check_my_turn(self): """ will take a snapshot of the area where the bigger button on bottom rightcorner of the screen based on the coordinates """ box = (0, 0, 0, 0) # the path to use tesseract in program. May be different depending on location of file pytezzeret.pytezzeret.tesseract_cmd = r"C:\Program Files\Tesseract-OCR\tesseract.exe" im = ImageGrab.grab(box) resize_im = im.resize((0, 0), resample = Image.NEAREST) #im.show() #resize_im.show() #cv2.cvtColor takes a numpy ndarray as an argument # convereted the image to grayscale for it to be easily read by the OCR and obrained the output string text = pytezzeret.image_to_string(cv2.cvtColor(numpy.array(resize_im), cv2.IMREAD_GRAYSCALE), lang = 'eng') #print(text) print(text.split()) return text.split()
def GetHandSize(): time.sleep(3) box = (0, 0, 0, 0) pytezzeret.pytezzeret.tesseract_cmd = r"C:\Program Files\Tesseract-OCR\tesseract.exe" im = ImageGrab.grab(box) resize_im = im.resize((0, 0), resample=Image.NEAREST) text = pytezzeret.image_to_string(cv2.cvtColor(numpy.array(resize_im), cv2.IMREAD_GRAYSCALE), lang='eng') resize_im.show() print(text) print() split_text = text.split() print(split_text) #time.sleep(3) return split_text
def getdeck(self): box = (0, 0,0, 0) decks = ((0, 0), (0, 0), (0, 0), (0, 0), (0, 0) ) colors = [] DeckFound = False no_color_quest = False pytezzeret.pytezzeret.tesseract_cmd = r"C:\Program Files\Tesseract-OCR\tesseract.exe" im = ImageGrab.grab(box) resize_im = im.resize((0, 0), resample=Image.NEAREST) text = pytezzeret.image_to_string(cv2.cvtColor(numpy.array(im), cv2.IMREAD_GRAYSCALE), lang='eng') #im.show() #print(text) split_text = text.split() for word in split_text: if word == 'red' or word == 'white' or word == 'green' \ or word == 'black' or word == 'blue': #print(word) colors.append(word) if colors: print("The colors in the quest are:", colors) #if there is nothing in the list, the quest is probably a non-color #quest else: no_color_quest = True # move cursor to 'play' button and left click mousePos(Cords.play_button) leftClick() time.sleep(1) # move cursor to play row and left click mousePos((0, 0)) #'Play' the button found under "Find Match" time.sleep(2) leftClick() # move cursor to the deck displayed and left click mousePos(Cords.deck) #area that displays the deck time.sleep(1) leftClick() #This will open the gallery of decks, pick a deck one at time #compare the 'name' of the deck with the list of 'colors' if no_color_quest == False: for cords in decks: if DeckFound == False: print("Checking if this deck is required to complete quest\n") time.sleep(2) mousePos(cords) time.sleep(2) leftClick() # Checks if the one of the colors matches the name of the deck name = self.CheckDeck() time.sleep(5) for color in colors: print("The color of quest being compared:", color, "\n") time.sleep(1) if name == color: print("Found a deck for the quest \n") DeckFound = True break else: print("Not the right deck") else: break print("The deck is appropriate for the quest") mousePos(Cords.play_button) time.sleep(3) leftClick() self.loading_screen() return