diff --git a/menti_words.py b/menti_words.py index 1406bec..f2bbb9f 100644 --- a/menti_words.py +++ b/menti_words.py @@ -4,6 +4,7 @@ import pydirectinput from nltk.corpus import words from pytesseract import pytesseract +import utils from utils import mse from game_base_class import GameBase import random @@ -126,7 +127,7 @@ class MentiWords(GameBase): #screenshot = cv.imread("menti_words/screenshot.jpg") screenshot = self.capture_window.get_screenshot() - screenshot = screenshot[870:1270, 1080:1480] + screenshot = utils.scale_screenshot(screenshot[870:1270, 1080:1480], 200, False) #cv.imshow("screenshot", screenshot) #cv.waitKey(150) @@ -134,19 +135,27 @@ class MentiWords(GameBase): for needle_key in self.needles.keys(): # gray_needle = cv.cvtColor(self.needles[needle_key], cv.COLOR_BGR2GRAY) # thresh_needle = cv.threshold(gray_needle, 0, 255, cv.THRESH_BINARY_INV + cv.THRESH_OTSU)[1] - rectangles = self.vision_stun.find(screenshot, self.needles[needle_key], 0.85, 1) + + thresh_needle = utils.scale_screenshot(self.needles[needle_key], 200, False) + rectangles = self.vision_stun.find(screenshot, thresh_needle , 0.85, 1) #rectangles = self.vision_stun.find(screenshot, self.needles[needle_key], 0.95, 1 ,True, self.masks[needle_key]) if len(rectangles) == 0: continue + points = self.vision_stun.get_click_points(rectangles) + self.current_letters.append(needle_key) + self.letter_coords[needle_key] = points[0] + ''' cropped1 = self.vision_stun.draw_display_picture(screenshot, rectangles, 10) - + #cropped1 = utils.scale_screenshot(cropped1) + cv.imshow("cropped1", cropped1) + cv.waitKey(150) text_1 = pytesseract.image_to_string(cropped1, lang='eng', config='--psm 6').strip() if str.isalpha(text_1): #cv.imshow("cropped1", cropped1) #cv.waitKey(150) points = self.vision_stun.get_click_points(rectangles) self.current_letters.append(text_1) - self.letter_coords[text_1] = points[0] + self.letter_coords[text_1] = points[0]''' if self.overlay.run_mode == 'stopped' or self.overlay.run_mode == 'paused': return diff --git a/menti_words/p.jpg b/menti_words/p.jpg index e964f03..bd27120 100644 Binary files a/menti_words/p.jpg and b/menti_words/p.jpg differ diff --git a/utils.py b/utils.py index 4d1f8c4..a769109 100644 --- a/utils.py +++ b/utils.py @@ -61,18 +61,20 @@ def check_for_bl_line(line_item, black_list): return False -def scale_screenshot(screenshot): - scale_percent = 200 # percent of original size +def scale_screenshot(screenshot, percent = 200, thresh_mode = True): + scale_percent = percent # percent of original size width = int(screenshot.shape[1] * scale_percent / 100) height = int(screenshot.shape[0] * scale_percent / 100) dim = (width, height) resized_img = cv.resize(screenshot, dim, interpolation=4) - gray = cv.cvtColor(resized_img, cv.COLOR_BGR2GRAY) - thresh = cv.threshold(gray, 0, 255, cv.THRESH_BINARY_INV + cv.THRESH_OTSU)[1] + if thresh_mode: + gray = cv.cvtColor(resized_img, cv.COLOR_BGR2GRAY) + thresh = cv.threshold(gray, 0, 255, cv.THRESH_BINARY_INV + cv.THRESH_OTSU)[1] + return thresh # cv.imshow("Tresh", thresh) # cv.waitKey(1000) - return thresh + return resized_img def save_line_item_npy_jpg(short_pic_list):