可以使用Python语言中的字符串比较函数实现该功能。示例代码如下:
import os
tesseract_output = "Hello world" # tesseract输出
txt_file = "output.txt" # 待比较的.txt文件路径
with open(txt_file, "r") as f:
txt_content = f.read() # 读取文件内容
if tesseract_output == txt_content:
print("两字符串相等")
else:
print("两字符串不相等")
解释:此代码使用Python内置的open()
函数打开待比较的文本文件,并读取其内容。然后使用if
语句比较tesseract_output
和txt_content
两个字符串的值是否相等。如果相等,则打印“两字符串相等”,否则打印“两字符串不相等”。