3

我已经开始用 Python 制作一个机器人。该机器人的目标是从屏幕上读取简单的一位数字,然后将它们加在一起。目前我知道如何获取屏幕截图。我被困在图像识别上。我研究了 OpenCV 模板匹配。

几天来,我一直试图弄清楚如何做到这一点。我能写的唯一代码在问题的底部。

例如我想做的是:(按顺序)

  1. 它将抓取屏幕截图
  2. 它将通过将我的数字图像与屏幕截图进行比较
  3. 找到匹配的图像后,它会将值记录到变量中。
  4. 然后它会移动到下一个数字。
  5. 它将重复步骤 1 - 3
  6. 它将把数字加在一起。

目前这是我的代码的样子:

import sys
import cv2
import numpy
from cv2 import cv
import PIL
from PIL import ImageGrab

print("Authentication")
print("Enter Password:")
entered = raw_input()
if entered == "hello":
    print("************Menu************")
    print("1: Quit")
    print("2: Start Bot")
    print("3: Settings")
    print("*" * 28)
    mode = input("")
    if mode == 1:
        print("Closing Answer Quick")
        import time
        time.sleep(3)
        quit
    elif mode == 2:
        import time
        print("Bot Initialize")
        time.sleep(1)
        print("Getting Screen")
        time.sleep(3)

        screenimage = ImageGrab.grab()
        x = [1, "images\1.png", "images\2.png", "images\3.png", "images\4.png", "images\5.png", "images\6.png", "images\7.png", "images\8.png", "images\9.png"]
    ##Here is where the screen recognition code goes

    elif mode == 3:
        print("Settings")
    else:

        import time
        print("Incorrect Password")
        time.sleep(3)
        quit
4

1 回答 1

1

如果您不只是将 OpenCV 用于学术目的,我建议您使用 OCR 作为解决号码识别任务的更简单的方法。这是一个基于 Tesseract 的 Python 库,由 Google 作为领先的 OCR 技术维护。它还具有仅数字检测设置。

http://code.google.com/p/pytesser/

于 2013-02-10T12:08:46.073 回答