3

Pythonでボットを作り始めました。ボットの目的は、画面から単純な 1 桁の数字を読み取り、それらを足し合わせることです。現時点では、スクリーンショットを取得する方法を知っています。画像認識で困っています。OpenCV テンプレート マッチングについて調べました。

私は何日もこれを行う方法について頭を悩ませようとしました。私が書くことができた唯一のコードは、質問の一番下にあります。

たとえば、私がやろうとしていることは次のとおりです:(順番に)

  1. スクリーンショットを取得します
  2. 数字の画像とスクリーンショットを比較して実行します
  3. 一致する画像が見つかると、値が変数に記録されます。
  4. その後、次の番号に移動します。
  5. 手順 1 ~ 3 を繰り返します。
  6. to 番号を一緒に追加します。

現在、これは私のコードがどのように見えるかです:

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を使用することをお勧めします。これは、主要なOCRテクノロジーとしてGoogleによって維持されているTesseractに基づくPythonライブラリです。数値検出のみの設定もあります。

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

于 2013-02-10T12:08:46.073 に答える