import pytesseract
from PIL import Image
def image_recognition(image_path):
try:
text = pytesseract.image_to_string(Image.open(image_path))
if text.strip(): # 如果识别出的文本去除空白字符后不为空,说明识别到了有效内容
print(“识别成功”)
print(text)
else:
print(“识别失败,未识别到有效文字内容”)
except Exception as e:
print(“识别失败,出现错误:”, e)
if name == “main”:
image_path = “1.png” # 这里需要替换为你实际要识别的图像的路径
image_recognition(image_path)