- Updated `config.json` to modify `yanghao_recommend_interval_seconds` for better timing control. - Refactored logging in `douyin_detection.py` to enhance readability and error handling. - Improved pixel loading and error management in image processing functions across multiple modules. - Enhanced GUI elements in `gui_app.py` to support new configuration options and improve user experience.
85 lines
3.3 KiB
Python
85 lines
3.3 KiB
Python
"""
|
|
简单的图片坐标查看工具
|
|
直接查看现有的 OCR 截图文件,帮助你确认坐标
|
|
"""
|
|
|
|
import os
|
|
import sys
|
|
from PIL import Image
|
|
|
|
# 修复 Windows 控制台编码问题
|
|
if sys.platform == 'win32':
|
|
try:
|
|
sys.stdout.reconfigure(encoding='utf-8', errors='replace') # type: ignore[attr-defined]
|
|
except Exception:
|
|
pass
|
|
|
|
def show_image_info(image_path):
|
|
"""显示图片信息和简单的坐标提示"""
|
|
if not os.path.exists(image_path):
|
|
print(f"❌ 图片文件不存在: {image_path}")
|
|
return False
|
|
|
|
try:
|
|
img = Image.open(image_path)
|
|
width, height = img.size
|
|
file_size = os.path.getsize(image_path) / 1024 # KB
|
|
|
|
print(f"\n{'='*60}")
|
|
print(f"图片信息: {os.path.basename(image_path)}")
|
|
print(f"{'='*60}")
|
|
print(f"📐 尺寸: {width} x {height} 像素")
|
|
print(f"📦 文件大小: {file_size:.2f} KB")
|
|
print(f"📍 路径: {image_path}")
|
|
print(f"\n💡 如何获取坐标:")
|
|
print(f" 方法1: Windows画图工具(推荐)")
|
|
print(f" 1. 双击图片文件,用画图打开")
|
|
print(f" 2. 将鼠标移动到目标位置")
|
|
print(f" 3. 查看画图左下角状态栏,显示格式: 'X: 123 Y: 456'")
|
|
print(f" 4. 记录左上角坐标 (x1, y1) 和右下角坐标 (x2, y2)")
|
|
print(f"\n 方法2: 使用截图工具")
|
|
print(f" 1. 打开 QQ截图 / 微信截图 / Snipping Tool")
|
|
print(f" 2. 框选目标区域")
|
|
print(f" 3. 查看显示的区域大小和位置")
|
|
print(f"\n 方法3: 使用交互式查看器(需要 tkinter)")
|
|
print(f" 运行: python check_image_coordinates.py interactive")
|
|
print(f"\n📝 坐标格式说明:")
|
|
print(f" - 坐标系: 左上角为原点 (0, 0)")
|
|
print(f" - X轴: 向右递增")
|
|
print(f" - Y轴: 向下递增")
|
|
print(f" - 格式: cut_pic(x1, y1, x2, y2, ...)")
|
|
print(f" - 示例: cut_pic(100, 150, 400, 200, ...) 表示")
|
|
print(f" 左上角(100, 150) 到 右下角(400, 200) 的矩形区域")
|
|
print(f"{'='*60}\n")
|
|
return True
|
|
except Exception as e:
|
|
print(f"❌ 打开图片失败: {e}")
|
|
return False
|
|
|
|
if __name__ == "__main__":
|
|
base_dir = os.path.dirname(os.path.abspath(__file__))
|
|
|
|
# 查看多个可能的图片
|
|
images_to_check = [
|
|
('当前截图', os.path.join(base_dir, 'pic', 'screenshot.png')),
|
|
('直播间标题_中', os.path.join(base_dir, 'pic', 'ocr', '直播间标题_中.png')),
|
|
('直播间标题(large)', os.path.join(base_dir, 'pic', 'ocr', 'live_room_title_large.png')),
|
|
('直播间标题(small)', os.path.join(base_dir, 'pic', 'ocr', 'live_room_title_small.png')),
|
|
]
|
|
|
|
print("🔍 直播间标题坐标查看工具\n")
|
|
|
|
# 只显示存在的图片
|
|
found_images = []
|
|
for name, path in images_to_check:
|
|
if os.path.exists(path):
|
|
found_images.append((name, path))
|
|
|
|
if not found_images:
|
|
print("❌ 没有找到任何图片文件")
|
|
print(f" 请确保程序已运行过,生成了截图文件")
|
|
else:
|
|
for name, path in found_images:
|
|
show_image_info(path)
|
|
|