fix: 空渠道检测改用JSONObject.has + 移除gitignore误排除manifest
This commit is contained in:
48
ocr_fixed.py
Normal file
48
ocr_fixed.py
Normal file
@@ -0,0 +1,48 @@
|
||||
import sys
|
||||
import io
|
||||
|
||||
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8')
|
||||
|
||||
from PIL import Image
|
||||
|
||||
img = Image.open(r"D:\Yuzu-GCA\screen_fixed.png")
|
||||
print(f"Format: {img.format}")
|
||||
print(f"Size: {img.size}")
|
||||
print(f"Mode: {img.mode}")
|
||||
|
||||
# Try OCR
|
||||
try:
|
||||
import pytesseract
|
||||
text = pytesseract.image_to_string(img, lang='eng+chi_sim')
|
||||
print("\n=== pytesseract OCR result ===")
|
||||
print(text)
|
||||
except ImportError:
|
||||
print("pytesseract not available")
|
||||
|
||||
# Also try Windows OCR
|
||||
try:
|
||||
import asyncio
|
||||
from winsdk.windows.media.ocr import OcrEngine
|
||||
from winsdk.windows.graphics.imaging import BitmapDecoder, SoftwareBitmap
|
||||
from winsdk.windows.storage.streams import RandomAccessStreamReference
|
||||
from winsdk.windows.globalization import Language
|
||||
import os
|
||||
|
||||
async def ocr_windows():
|
||||
engine = OcrEngine.try_create_from_user_profile_languages()
|
||||
if not engine:
|
||||
engine = OcrEngine.try_create_from_language(Language("en"))
|
||||
|
||||
path = os.path.abspath(r"D:\Yuzu-GCA\screen_fixed.png")
|
||||
file_stream = await RandomAccessStreamReference.create_from_file(path).open_read_async()
|
||||
decoder = await BitmapDecoder.create_async(file_stream)
|
||||
bitmap = await decoder.get_software_bitmap_async()
|
||||
|
||||
result = await engine.recognize_async(bitmap)
|
||||
print("\n=== Windows OCR result ===")
|
||||
for line in result.lines:
|
||||
print(line.text)
|
||||
|
||||
asyncio.run(ocr_windows())
|
||||
except Exception as e:
|
||||
print(f"Windows OCR failed: {e}")
|
||||
Reference in New Issue
Block a user