from PIL import Image
import pytesseract
import os

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

# 切成4个区域分别识别
regions = {
    '左上': (0, 0, w//2, h//2),
    '右上': (w//2, 0, w, h//2),
    '左下': (0, h//2, w//2, h),
    '右下': (w//2, h//2, w, h),
}

for name, box in regions.items():
    region = img.crop(box)
    # 放大2倍
    region = region.resize((region.width * 2, region.height * 2), Image.LANCZOS)
    text = pytesseract.image_to_string(region, lang='chi_sim', config='--psm 6')
    print(f"\n{'='*40}")
    print(f"【{name}】")
    print(f"{'='*40}")
    print(text.strip()[:800])
