【发布时间】:2022-01-21 20:20:47
【问题描述】:
我有一个项目,我正在使用 tesseract 抓取屏幕以查找文本框以输入电子邮件地址。
Tessearact 找到该框,将名为 text 的变量返回为 Send copy to email
我可以在python中很好地打印那个字符串
但是当我尝试在 if 语句中使用它时,它不会匹配
这只是我与我制作的屏幕截图一起使用的一个测试脚本,它返回Send copy to email的保证值
我确定我在这里遗漏了一些简单的东西......非常感谢任何帮助
编辑* 文本 [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')
【问题讨论】:
-
text具有by但您要比较的字符串具有to。 -
在 if text == str('Send copy to email') 行中:你说“to”,在 text = 'Send copy by email' 行中你说“by”,这样他们就会不匹配。
text的type()是什么。
标签: python string if-statement