from PIL import Image, ImageEnhance, ImageFilter
import pytesseract

path = '/root/.hermes/cache/images/img_668b1b2125b9.jpg'
img = Image.open(path)

# 放大3倍提高OCR
img_large = img.resize((img.width * 3, img.height * 3), Image.LANCZOS)

# 增强对比度
enhancer = ImageEnhance.Contrast(img_large)
img_enhanced = enhancer.enhance(2.0)

# 转灰度
img_gray = img_enhanced.convert('L')

# 二值化
threshold = 180
img_bw = img_gray.point(lambda x: 0 if x < threshold else 255, '1')

text = pytesseract.image_to_string(img_bw, lang='chi_sim+eng', config='--psm 6')
print(text.strip())
print("\n" + "="*60)
print("尝试不同PSM模式...")
for psm in [3, 4, 6, 11]:
    t = pytesseract.image_to_string(img_large, lang='chi_sim+eng', config=f'--psm {psm}')
    print(f"\n--- PSM {psm} ---")
    print(t.strip()[:800])
