ВОТ КАК Я ПРОТИВ CV2:
Код: Выделить всё
def preprocess_image(image_path):
image = cv2.imread(image_path)
grey = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
_, binary = cv2.threshold(grey, 0, 255, cv2.THRESH_BINARY_INV + cv2.THRESH_OTSU)
return binary
def take_screenshot_and_preprocess(x1, y1, x2, y2, config=None):
screenshot = pyautogui.screenshot(region=(x1, y1, x2 - x1, y2 - y1))
screenshot_path = "screenshot.png"
screenshot.save(screenshot_path)
preprocessed_image = preprocess_image(screenshot_path)
return preprocessed_image
def extract_text_from_image(preprocessed_image, config=None):
cv2.imwrite("preprocessed_image.png", preprocessed_image)
preprocessed_pil_image= Image.open("preprocessed_image.png")
text = pytesseract.image_to_string(preprocessed_pil_image)
return text
Код: Выделить всё
preprocessed_image = take_screenshot_and_preprocess(402, 208, 480, 225,) #screenshot payment
text = extract_text_from_image(preprocessed_image, config='--oem 3')
pyautogui.typewrite(text)
Обработанный снимок экрана:
Номер, обнаруженный кодом на исходном снимке экрана: 1.31218
Я пытался инвертировать значения для CV2, принудительно инвертировать двоичный файл, но ничего не помогло
Подробнее здесь: https://stackoverflow.com/questions/784 ... n-using-cv