import numpy as np
import time
from PIL import Image, ImageGrab
from paddleocr import PaddleOCR, draw_ocr
import pyautogui as pg
import time
print('\033[92m')
def get_curtime(time_format="%Y-%m-%d %H:%M:%S"):
curTime = time.localtime()
curTime = time.strftime(time_format, curTime)
return curTime
def ocr_img_text(path="", saveimg=False, printResult=False):
image = path
if image == "":
image = ImageGrab.grab()
image = np.array(image)
else:
image = Image.open(image).convert('RGB')
image = np.array(image)
ocr = PaddleOCR(use_angle_cls=printResult, lang="ch")
result = ocr.ocr(image, cls=printResult)
if printResult == True:
for line in result:
for word in line:
print(word)
img_name = "ImgTextOCR-img-" + get_curtime() + ".jpg"
if saveimg == True:
boxes = [detection[0] for line in result for detection in line]
txts = [detection[1][0] for line in result for detection in line]
scores = [detection[1][1] for line in result for detection in line]
im_show = draw_ocr(image, boxes, txts, scores)
im_show = Image.fromarray(im_show)
im_show.save(img_name)
return result, img_name
pos = []
is_goal = False
time.sleep(5)
for a in ocr_img_text():
goal_str = '目标是我!!!'
print('a循环')
print(a)
for b in a:
print('b循环')
print(b)
for c in b:
print('c循环')
print(c)
# print(c[0])
# print(c[1])
try:
for d in c:
print('d循环')
print(d)
print(d[0])
try:
if goal_str in d[0]:
is_goal = True
except:
pass
for e in d:
print('e循环')
print(e)
for f in e:
print('f循环')
print(f)
try:
pos.append(float(f))
except:
pass
if len(pos) == 2:
if is_goal == True:
pg.moveTo(pos[0]+2, pos[1]+2)
is_goal = False
except:
pass
为什么代码不能正常运行,我已经开着记事本写着内容了
