确定屏幕截图中是否有较小的图像?

时间:2013-01-28 22:34:10

标签: python opencv image-processing bots image-recognition

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

我试图了解如何做好几天。 我能写的唯一代码就是问题的底部。

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

  1. 它会抓一个截图
  2. 它会将我的数字图像与屏幕截图进行比较
  3. 找到匹配的图像后,它会将值记录到变量中。
  4. 然后它会转到下一个号码。
  5. 将重复步骤1 - 3
  6. 它会将数字加在一起。
  7. 目前这是我的代码:

    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
    

1 个答案:

答案 0 :(得分:1)

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

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