我有一個專案,我正在使用 tesseract 進行螢屏抓取以查找文本框以輸入電子郵件地址。
Tessearact 找到該框,回傳一個名為textas的變數Send copy to email
,我可以在 python 中很好地列印該字串,但是當我嘗試在if陳述句中使用它時,它不會匹配
這只是我在制作的螢屏截圖中使用的測驗腳本回傳保證值Send copy to email
I'm Sure I'm Missing something simple here.. 非常感謝任何幫助
編輯* 文本 [to/by] 已修復
import cv2
import pytesseract
pytesseract.pytesseract.tesseract_cmd = r'C:\\Program Files\\Tesseract-OCR\\tesseract.exe'
img = cv2.imread('C:\\screeny\\emailscreentest.png')
text = pytesseract.image_to_string(img)
print(text)
#As a Test I simply added this line to guarantee the string I wanted
text = 'Send copy by email'
number = 0
for number in range(1000):
if text == str('Send copy by email') :
break # break here
print('Number is ' str(number))
img = cv2.imread('C:\\screeny\\emailscreentest.png')
text = pytesseract.image_to_string(img)
print('Out of loop')
uj5u.com熱心網友回復:
所以我在有人回復之前找到了一個對我有用的解決方案......我不知道它是正確的答案還是最好的方法......但它似乎很完美
import cv
import pyautogui as pg
import pytesseract
import re
#initial Screenshot-------
pg.screenshot('emailscreentest.png', region=(763,441, 125, 19))
img = cv2.imread('C:\\screeny\\emailscreentest.png')
text = str(pytesseract.image_to_string(img))
match= re.search("Send copy by email",text)
#Loop till screenshot match---------
number = 0
for number in range(1000):
if match :
break # break here
#print('Number is ' str(number))
pg.screenshot('emailscreentest.png', region=(763,441, 125, 19))
img = cv2.imread('C:\\screeny\emailscreentest.png')
text = pytesseract.image_to_string(img)
match= re.search("Send copy by email",text)
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/420762.html
標籤:
