【问题标题】:Determine whether or not a smaller image is within a screenshot?确定屏幕截图中是否有较小的图像?
【发布时间】:2013-01-12 09:49:03
【问题描述】:

我已经开始用 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

【问题讨论】:

  • 如果您正在寻找模板匹配,请访问此 SOF:stackoverflow.com/questions/14486353/image-in-image-with-cvmatchtemplate-but-how/14487266

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


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-03-10
    • 2022-09-28
    • 1970-01-01
    • 2014-04-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-20
    相关资源
    最近更新 更多