fix: 空渠道检测改用JSONObject.has + 移除gitignore误排除manifest
This commit is contained in:
55
ocr_screen.py
Normal file
55
ocr_screen.py
Normal file
@@ -0,0 +1,55 @@
|
||||
"""
|
||||
OCR script to extract text from screen.png
|
||||
Attempts to use pytesseract if available, otherwise falls back to basic image info.
|
||||
"""
|
||||
import sys
|
||||
import os
|
||||
|
||||
image_path = r"D:\Yuzu-GCA\screen.png"
|
||||
|
||||
# First, try to get basic image info
|
||||
try:
|
||||
from PIL import Image
|
||||
img = Image.open(image_path)
|
||||
print(f"Image size: {img.size}")
|
||||
print(f"Image mode: {img.mode}")
|
||||
print(f"Image format: {img.format}")
|
||||
print("---")
|
||||
except ImportError:
|
||||
print("Pillow not available, trying basic file read...")
|
||||
# Can't do much without PIL
|
||||
|
||||
# Try pytesseract
|
||||
try:
|
||||
import pytesseract
|
||||
text = pytesseract.image_to_string(img, lang='chi_sim+eng')
|
||||
print("OCR Result (pytesseract):")
|
||||
print(text)
|
||||
except ImportError:
|
||||
print("pytesseract not available")
|
||||
# Try subprocess call to system tesseract
|
||||
import subprocess
|
||||
try:
|
||||
result = subprocess.run(
|
||||
['tesseract', image_path, 'stdout', '-l', 'chi_sim+eng'],
|
||||
capture_output=True, text=True, timeout=30
|
||||
)
|
||||
if result.returncode == 0:
|
||||
print("OCR Result (system tesseract):")
|
||||
print(result.stdout)
|
||||
else:
|
||||
print(f"Tesseract error: {result.stderr}")
|
||||
except FileNotFoundError:
|
||||
print("System tesseract not found either")
|
||||
except Exception as e:
|
||||
print(f"Error running tesseract: {e}")
|
||||
|
||||
# If nothing works, try reading raw pixels to detect if it's a text screenshot
|
||||
try:
|
||||
from PIL import Image
|
||||
img = Image.open(image_path)
|
||||
# Print first few pixel values to understand the image
|
||||
pixels = list(img.getdata())[:20]
|
||||
print(f"\nFirst 20 pixel values: {pixels}")
|
||||
except:
|
||||
pass
|
||||
Reference in New Issue
Block a user