Skip to content

Latest commit

 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Image Recognition System v3.0

PP-OCRv6 ONNX + YOLO26n + ImageCache Smart OCR System. TCP Socket based architecture.

Architecture

                    HTTP 11719
  +------------------+------------------+
  |                                     |
  v                                     v
+---------------+     TCP 11720     +---------------+
|  API Service  | <---------------> |  SOE Server   |
|  (FastAPI)    |                   |  (TCP Socket) |
+---------------+                   +---------------+
  |                                     |
  | /v1/* (OpenAI)                     | OCR Engine
  | /* (Standard JSON)                  | YOLO Detector
  +------------------+                  | Image Cache
                     |                  | Device Profiler
                     v                  |
              +-------------+           |
              |   Client    |           |
              |  (Adapter)  | <---------+
              +-------------+

File List

File Description
ocr_openai_api.py API Service (HTTP), dual mode: v1 OpenAI + Standard JSON
smart_ocr_onnx.py SOE TCP Server (TCP 11720), core OCR engine
adapter.py TCP Client, connects to SOE via TCP
model_downloader.py Multi-source auto downloader
image_cache.py Image cache (SHA1 + pHash, SQLite)
yolo_detector.py YOLO26n detector (ONNX/OpenVINO)
device_profiler.py Device profiling & dynamic config
onnx_ocr_engine.py ONNX OCR engine
ocr_utils.py OCR utilities
ocr_compat_onnx.py Compat entry (TCP client)
compare_images_gt730_v34.py Deep feature comparison
convert_models.py Model conversion
launcher.py Launcher v3.0
config.json Full config with TCP settings
requirements.txt Dependencies

Quick Start

1. Install Dependencies

pip install -r requirements.txt
# Optional: pip install openvino
# Optional: pip install onnxruntime-gpu

2. Start SOE TCP Server

python smart_ocr_onnx.py --port 11720
# or
python launcher.py --soe

3. Start API Service (another terminal)

python ocr_openai_api.py --port 11719 --soe-port 11720
# or
python launcher.py --api

4. Test

# Standard API - OCR
curl -X POST http://localhost:11719/ocr \
  -H "Content-Type: application/json" \
  -d '{"image_path": "test.jpg"}'

# Standard API - YOLO
curl -X POST http://localhost:11719/yolo \
  -H "Content-Type: application/json" \
  -d '{"image_path": "test.jpg"}'

# OpenAI v1 API
curl -X POST http://localhost:11719/v1/chat/completions \
  -H "Content-Type: application/json" \
  -d '{
    "model": "ocr-ppocr-v4",
    "messages": [{"role": "user", "content": "recognize"}],
    "image_url": "https://example.com/image.jpg"
  }'

Standard API Endpoints

Method Path Description
GET / Service info
GET /health Health check
GET /models Model list
POST /ocr Full OCR recognition
POST /yolo YOLO detection only
GET /cache/stats Cache statistics
POST /cache/clear Clear cache
GET /profile Device profile
POST /ping Ping SOE

OpenAI v1 API Endpoints

Method Path Description
GET /v1/models Model list
POST /v1/chat/completions Chat completion (OCR)

TCP Protocol

SOE TCP Server listens on 127.0.0.1:11720.

Request format: JSON + newline

{"cmd": "ocr", "image_path": "test.jpg", "image_id": "test"}

Response format: JSON + newline

{"status": "ok", "image_id": "test", "content": [...], "yolo": [...]}

Commands:

  • ocr - Recognize image
  • cache_stats - Cache statistics
  • cache_clear - Clear cache
  • profile - Device profile
  • ping - Heartbeat
  • exit - Shutdown

Config

Key settings in config.json:

{
  "tcp": {
    "soe_host": "127.0.0.1",
    "soe_port": 11720,
    "api_host": "0.0.0.0",
    "api_port": 11719
  }
}

CLI Usage

# SOE Server
python smart_ocr_onnx.py --host 127.0.0.1 --port 11720

# API Service
python ocr_openai_api.py --host 0.0.0.0 --port 11719 --soe-host 127.0.0.1 --soe-port 11720

# Single image (auto starts SOE)
python smart_ocr_onnx.py image.jpg

# Download only
python smart_ocr_onnx.py --download

Detection Classes

YOLO26n supports: text, table, formula, handwriting, stamp, qr_code, barcode.

About

图像识别

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages