-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathocr.py
More file actions
38 lines (31 loc) · 1.14 KB
/
Copy pathocr.py
File metadata and controls
38 lines (31 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import easyocr
import ollama
# ====================== 初始化(永远不报错)======================
reader = easyocr.Reader(['ch', 'en'], gpu=False)
# ====================== 图片转文字 ======================
def img2text(img_path):
result = reader.readtext(img_path, detail=0)
return " ".join(result)
# ====================== AI 分析 ======================
def ai_analyze(text: str, target_keyword: str):
prompt = f"""
你是内容匹配助手。
文本内容:{text}
请判断是否包含关键词:【{target_keyword}】
只允许回答两个字:包含 或 不包含
"""
response = ollama.chat(
model="qwen:7b",
messages=[{"role": "user", "content": prompt}]
)
return response["message"]["content"].strip()
# ====================== 主程序 ======================
if __name__ == "__main__":
img_path = "test.png" # 你的图片
target = "登录" # 你要找的文字
print("正在识别图片文字...")
text = img2text(img_path)
print("识别结果:\n", text)
print("\nAI 匹配中...")
result = ai_analyze(text, target)
print("\n✅ 最终结果:", result)