Determine if the smaller image is in the screenshot?

I started making a bot in Python. The bot's goal is to read simple one-digit numbers from the screen and then add them together. At the moment I know how to get a screenshot. I am stuck with image recognition. I looked into OpenCV pattern matching.

I tried to figure out how to do this for several days. The only code I could write is at the bottom of the question.

For example, I'm trying to do the following: (OK)

  • He will receive a screenshot
  • It will go through by comparing my pictures of numbers with the screenshot
  • When searching for a matching image, it writes the value to a variable.
  • Then it will move on to the next number.
  • He will repeat steps 1 - 3
  • It will add to the numbers together.

It currently looks like this:

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

      

+3


source to share


1 answer


If you are not using OpenCV just for academic purposes, I would recommend using OCR as a more simplistic approach to solving the number identification problem. Here is a Tesseract based python library which is backed by Google as the leading OCR technology. It also only has a numeric detection definition.



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

+1


source







All Articles