From de5563371e0ebcf06661521ed522c956752abf73 Mon Sep 17 00:00:00 2001 From: Shuang_Dong <374191531@qq.com> Date: Mon, 9 Jun 2025 10:02:20 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E4=BB=A3=E7=A0=81=EF=BC=8C?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0ocr=E5=92=8Cwhisper?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- code/simple_ocr_test.py | 137 ---------------------------------------- 1 file changed, 137 deletions(-) delete mode 100644 code/simple_ocr_test.py diff --git a/code/simple_ocr_test.py b/code/simple_ocr_test.py deleted file mode 100644 index 843dc6d..0000000 --- a/code/simple_ocr_test.py +++ /dev/null @@ -1,137 +0,0 @@ -#!/usr/bin/env python3 -# -*- coding: utf-8 -*- -""" -简化OCR测试脚本 -""" - -import cv2 -import json -from pathlib import Path - -def test_paddleocr(): - """测试PaddleOCR基本功能""" - print("🔧 测试PaddleOCR...") - - try: - from paddleocr import PaddleOCR - - # 初始化OCR - ocr = PaddleOCR( - use_textline_orientation=True, - lang='ch' - ) - print("✅ PaddleOCR初始化成功") - - # 测试视频文件 - video_path = "/root/autodl-tmp/hot_video_analyse/video2audio/sample_demo_6.mp4" - - # 读取一帧进行测试 - cap = cv2.VideoCapture(video_path) - ret, frame = cap.read() - cap.release() - - if not ret: - print("❌ 无法读取视频帧") - return False - - print("📸 成功读取视频帧") - - # 进行OCR识别 - 使用predict方法 - try: - result = ocr.predict(frame) - except: - # 如果predict不工作,尝试ocr方法 - result = ocr.ocr(frame) - - print(f"🔍 OCR结果类型: {type(result)}") - - # 处理结果 - if result: - if isinstance(result, list) and len(result) > 0: - detections = result[0] if isinstance(result[0], list) else result - print(f"🔍 OCR结果: {len(detections)} 个检测") - - for i, detection in enumerate(detections[:3]): # 只显示前3个 - if detection and len(detection) >= 2: - try: - bbox, text_info = detection - if isinstance(text_info, tuple) and len(text_info) >= 2: - text, confidence = text_info - print(f" {i+1}. 文本: '{text}' 置信度: {confidence:.3f}") - else: - print(f" {i+1}. 检测到文本但格式异常: {text_info}") - except Exception as e: - print(f" {i+1}. 处理检测结果时出错: {e}") - else: - print("🔍 OCR结果为空或格式异常") - else: - print("🔍 OCR结果为None") - - return True - - except Exception as e: - print(f"❌ PaddleOCR测试失败: {e}") - import traceback - print(f"详细错误: {traceback.format_exc()}") - return False - -def test_easyocr(): - """测试EasyOCR基本功能""" - print("\n🔧 测试EasyOCR...") - - try: - import easyocr - - # 初始化OCR - reader = easyocr.Reader(['ch_sim', 'en']) - print("✅ EasyOCR初始化成功") - - # 测试视频文件 - video_path = "/root/autodl-tmp/hot_video_analyse/video2audio/sample_demo_6.mp4" - - # 读取一帧进行测试 - cap = cv2.VideoCapture(video_path) - ret, frame = cap.read() - cap.release() - - if not ret: - print("❌ 无法读取视频帧") - return - - print("📸 成功读取视频帧") - - # 进行OCR识别 - result = reader.readtext(frame) - - print(f"🔍 OCR结果: {len(result)} 个检测") - - for i, detection in enumerate(result[:3]): # 只显示前3个 - bbox, text, confidence = detection - print(f" {i+1}. 文本: '{text}' 置信度: {confidence:.3f}") - - return True - - except Exception as e: - print(f"❌ EasyOCR测试失败: {e}") - return False - -def main(): - """主函数""" - print("🧪 简化OCR功能测试") - print("=" * 40) - - paddle_ok = test_paddleocr() - easy_ok = test_easyocr() - - print("\n" + "=" * 40) - print("📊 测试结果:") - print(f" PaddleOCR: {'✅ 成功' if paddle_ok else '❌ 失败'}") - print(f" EasyOCR: {'✅ 成功' if easy_ok else '❌ 失败'}") - - if paddle_ok or easy_ok: - print("\n🎉 至少有一个OCR引擎工作正常,可以继续使用!") - else: - print("\n⚠️ 所有OCR引擎都有问题,请检查安装") - -if __name__ == "__main__": - main() \ No newline at end of file