我写了一个OCR测试工具:DeepSeekOCR、PaddleOCR 和 混元OCR

大家好,我是 Ai 学习的老章

最近的 OCR 大模型我都做了本地部署和测试,还写了一个 API 统一对接这三个模型

腾讯混元 OCR 大模型,本地部署,实测

本地部署 PaddleOCR,消费级显卡轻松跑,支持本地图片和 PDF 文件

DeepSeek-OCR 本地部署(上):CUDA 升级 12.9,vLLM 升级至最新稳定版

DeepSeek-OCR 本地部署(下):vLLM 离线推理,API 重写,支持本地图片、PDF 解析

很多同学问选哪个?

成年人怎么还在做选择呢,必须全都要啊

我用 FastAPI 框架撸了一个简单的 OCR 模型对比工具 (OCR Comparison Tool),可以实现同样的提示词 + 图片/PDF,利用 Python 多线程并行调用 DeepSeek、Paddle 和 混元这三个模型的 API 进行解析,并将结果并排展示。

前端其实纯 HTML+CSS+js 实现,为了内网部署,不依赖任何 CND。

使用也很简单,图片/PDF 上传之后,输入提示词,没有特殊要求,使用默认就行。

点击 Run OCR Comparison 即可

三者都很快,内置了轻量级 Markdown 解析其,自动渲染结果。

也可以切换到识别后的原始 Markdown,支持一键 copy

核心代码如下(完整代码接近 600 行,大多是 HTML 相关):

感兴趣的同学可以试试,OCR 模型 API 部分替换成官方/第三方的 API

这段代码稍作修改就可以在线部署运行了

python 复制代码
#!/usr/bin/env python3
"""
OCR Comparison Web App - 美化版,不依赖外部 CDN
"""
import os
import re
import shutil
import tempfile
import requests
from concurrent.futures import ThreadPoolExecutor

import uvicorn
from fastapi import FastAPI, File, Form, UploadFile
from fastapi.responses import HTMLResponse

app = FastAPI(title="OCR Comparison")

# --- Configuration ---
MODELS = {
    "DeepSeek-OCR": "http://",
    "PaddleOCR": "http://",
    "HunyuanOCR": "http://",
}


def call_api(model_name, api_url, file_path, prompt):
    """调用单个 OCR API"""
    print(f"[INFO] Calling {model_name}: {api_url}")
    try:
        with open(file_path, 'rb') as f:
            resp = requests.post(
                api_url,
                files={'file': (os.path.basename(file_path), f)},
                data={'prompt': prompt},
                timeout=300
            )
        print(f"[INFO] {model_name} status: {resp.status_code}")
        if resp.status_code == 200:
            data = resp.json()
            result = data.get("result", str(data))
            print(f"[INFO] {model_name} result length: {len(result)}")
            return result
        return f"HTTP Error: {resp.status_code}"
    except Exception as e:
        print(f"[ERROR] {model_name}: {e}")
        return f"Error: {e}"


HTML_PAGE = """
<!DOCTYPE html>
省略
</html>
"""


@app.get("/", response_class=HTMLResponse)
async def index():
    return HTML_PAGE


@app.post("/api/compare")
async def compare(
    file: UploadFile = File(...),
    prompt: str = Form("Convert the document to markdown.")
):
    print(f"\n{'='*60}")
    print(f"[INFO] Received request: {file.filename}")
    print(f"[INFO] Prompt: {prompt[:50]}...")
    print(f"{'='*60}")
    
    temp_dir = tempfile.mkdtemp()
    temp_path = os.path.join(temp_dir, file.filename)
    
    try:
        with open(temp_path, "wb") as f:
            content = await file.read()
            f.write(content)
        
        print(f"[INFO] Saved to: {temp_path}, size: {len(content)} bytes")
        
        # 并行调用三个 API
        results = {}
        with ThreadPoolExecutor(max_workers=3) as executor:
            futures = {
                "deepseek": executor.submit(call_api, "DeepSeek-OCR", MODELS["DeepSeek-OCR"], temp_path, prompt),
                "paddle": executor.submit(call_api, "PaddleOCR", MODELS["PaddleOCR"], temp_path, prompt),
                "hunyuan": executor.submit(call_api, "HunyuanOCR", MODELS["HunyuanOCR"], temp_path, prompt),
            }
            
            for name, future in futures.items():
                try:
                    result = future.result(timeout=310)
                    results[name] = result
                    print(f"[INFO] {name} done, length: {len(result)}")
                except Exception as e:
                    results[name] = f"Error: {e}"
                    print(f"[ERROR] {name}: {e}")
        
        print(f"[INFO] All done. Returning results.")
        print(f"[DEBUG] Results keys: {list(results.keys())}")
        
        return results
        
    finally:
        shutil.rmtree(temp_dir, ignore_errors=True)


if __name__ == "__main__":
    print("\n" + "="*60)
    print("OCR Comparison Server")
    print("URL: http://0.0.0.0:8080")
    print("="*60 + "\n")
    
    uvicorn.run(app, host="0.0.0.0", port=8080)
相关推荐
AI人工智能+18 分钟前
药品经营许可证识别技术:通过图像预处理、目标检测、序列识别和版面分析,实现对药品经营许可证关键信息的高精度提取
深度学习·计算机视觉·ocr·药品经营许可证识别
weixin_408099671 小时前
【保姆级教程】易语言调用 OCR 文字识别 API(从0到1完整实战 + 示例源码)
图像处理·人工智能·后端·ocr·api·文字识别·易语言
weixin_408099672 小时前
【保姆级教程】按键精灵调用 OCR 文字识别 API(从0到1完整实战 + 可运行脚本)
java·前端·人工智能·后端·ocr·api·按键精灵
小女孩真可爱2 小时前
paddleocr使用50显卡训练报错
人工智能·ocr
AI人工智能+12 小时前
基于高精度身份证OCR识别、炫彩活体检测及人脸比对技术的人脸核身系统,为通信行业数字化转型提供了坚实的安全底座
人工智能·计算机视觉·人脸识别·ocr·人脸核身
AI人工智能+12 小时前
一种以深度学习与计算机视觉技术为核心的表格识别系统,实现了结构化、半结构化表格的精准文字提取、布局解析与版面完整还原
深度学习·计算机视觉·ocr·表格识别
AI人工智能+3 天前
智能文档抽取系统:结合OCR与大语言模型(LLM),高效处理非结构化文档
人工智能·计算机视觉·语言模型·自然语言处理·ocr·文档抽取
xuedeyumu4 天前
Paddle ocr基本识别
ocr·paddle
handsomestWei5 天前
百度飞桨PaddleOCR图片印章检测技术简介
人工智能·百度·ocr·paddlepaddle·红色印章
stereohomology6 天前
光荣梦想:大模型图片OCR中文识别对比 Qwen3.6plus强
ocr