Pythonでボットを作り始めました。ボットの目的は、画面から単純な 1 桁の数字を読み取り、それらを足し合わせることです。現時点では、スクリーンショットを取得する方法を知っています。画像認識で困っています。OpenCV テンプレート マッチングについて調べました。
私は何日もこれを行う方法について頭を悩ませようとしました。私が書くことができた唯一のコードは、質問の一番下にあります。
たとえば、私がやろうとしていることは次のとおりです:(順番に)
- スクリーンショットを取得します
- 数字の画像とスクリーンショットを比較して実行します
- 一致する画像が見つかると、値が変数に記録されます。
- その後、次の番号に移動します。
- 手順 1 ~ 3 を繰り返します。
- 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