59 lines
1.5 KiB
Python
59 lines
1.5 KiB
Python
import asyncio
|
|
import os
|
|
import sys
|
|
|
|
|
|
project_root = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
|
if project_root not in sys.path:
|
|
sys.path.append(project_root)
|
|
|
|
|
|
from Apps.TeLaiDian.FirstPageKit import run_ocr_rect
|
|
|
|
|
|
async def main():
|
|
image_dir = os.path.join(project_root, "Output")
|
|
if not os.path.isdir(image_dir):
|
|
print(f"目录不存在: {image_dir}")
|
|
return
|
|
|
|
img_files = []
|
|
for name in os.listdir(image_dir):
|
|
lower = name.lower()
|
|
if not lower.endswith(".jpg"):
|
|
continue
|
|
if "_flag" in lower or "_vl" in lower:
|
|
continue
|
|
img_files.append(os.path.join(image_dir, name))
|
|
img_files.sort()
|
|
|
|
if not img_files:
|
|
print(f"目录下未找到图片: {image_dir}")
|
|
return
|
|
|
|
img_files = img_files[:3]
|
|
|
|
for path in img_files:
|
|
base, ext = os.path.splitext(path)
|
|
vl_path = f"{base}_vl{ext}"
|
|
flag_path = f"{base}_flag{ext}"
|
|
for p in (vl_path, flag_path):
|
|
if os.path.exists(p):
|
|
try:
|
|
os.remove(p)
|
|
except PermissionError:
|
|
pass
|
|
|
|
print(f"开始处理图片: {path}")
|
|
await run_ocr_rect(path)
|
|
if os.path.exists(vl_path):
|
|
try:
|
|
os.remove(vl_path)
|
|
except PermissionError:
|
|
pass
|
|
print(f"处理完成: {path}")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
asyncio.run(main())
|