update
This commit is contained in:
parent
0cc344d88d
commit
f7b9d02578
8 changed files with 32 additions and 18 deletions
|
|
@ -33,10 +33,11 @@ sudo apt-get install -y python3-opencv
|
|||
pip3 install -r requirements.txt
|
||||
```
|
||||
|
||||
Optional PaddleOCR backend (Python 3.8+ only):
|
||||
Optional PaddleOCR backend for Python 3.6:
|
||||
```bash
|
||||
pip3 install -r requirements-paddle.txt
|
||||
```
|
||||
If you see `No matching distribution found for paddleocr>=3.0.0`, use the pinned `2.7.x` requirement above (already set in this repo).
|
||||
|
||||
## Models
|
||||
Place your models in `./models` (paths can be overridden via env):
|
||||
|
|
@ -80,8 +81,8 @@ OpenCV from JetPack repos (4.x) usually ships without CUDA dnn. To use CUDA, bui
|
|||
- `PADDLE_LANG` (default `ru`; used when `OCR_BACKEND=paddle`)
|
||||
- `PADDLE_USE_GPU` (default `false`)
|
||||
- `PADDLE_USE_ANGLE_CLS` (default `false`)
|
||||
- `PADDLE_DET_MODEL_DIR` (default `./models/paddle/PP-OCRv5_mobile_det_infer`)
|
||||
- `PADDLE_REC_MODEL_DIR` (default `./models/paddle/eslav_PP-OCRv5_mobile_rec_infer`)
|
||||
- `PADDLE_DET_MODEL_DIR` (default `./models/paddle/PP-OCRv3_mobile_det_infer`)
|
||||
- `PADDLE_REC_MODEL_DIR` (default `./models/paddle/cyrillic_PP-OCRv3_mobile_rec_infer`)
|
||||
- `PADDLE_CLS_MODEL_DIR` (default empty)
|
||||
- `PADDLE_CPU_THREADS` (default `4`)
|
||||
- `TESSDATA_PREFIX` (path to tessdata / tessdata_best if you install better models)
|
||||
|
|
|
|||
Binary file not shown.
4
app.py
4
app.py
|
|
@ -69,8 +69,8 @@ OCR_AUTO_LANG = env_bool("OCR_AUTO_LANG", True)
|
|||
PADDLE_LANG = os.getenv("PADDLE_LANG", "ru")
|
||||
PADDLE_USE_GPU = env_bool("PADDLE_USE_GPU", False)
|
||||
PADDLE_USE_ANGLE_CLS = env_bool("PADDLE_USE_ANGLE_CLS", False)
|
||||
PADDLE_DET_MODEL_DIR = os.getenv("PADDLE_DET_MODEL_DIR", "")
|
||||
PADDLE_REC_MODEL_DIR = os.getenv("PADDLE_REC_MODEL_DIR", "")
|
||||
PADDLE_DET_MODEL_DIR = os.getenv("PADDLE_DET_MODEL_DIR", "./models/paddle/PP-OCRv3_mobile_det_infer")
|
||||
PADDLE_REC_MODEL_DIR = os.getenv("PADDLE_REC_MODEL_DIR", "./models/paddle/cyrillic_PP-OCRv3_mobile_rec_infer")
|
||||
PADDLE_CLS_MODEL_DIR = os.getenv("PADDLE_CLS_MODEL_DIR", "")
|
||||
PADDLE_CPU_THREADS = env_int("PADDLE_CPU_THREADS", 0)
|
||||
MAX_CONTENT_LENGTH = MAX_IMAGE_MB * 1024 * 1024
|
||||
|
|
|
|||
Binary file not shown.
|
|
@ -58,7 +58,7 @@ class PaddleOCRBackend(object):
|
|||
if self.cpu_threads > 0:
|
||||
kwargs['cpu_threads'] = self.cpu_threads
|
||||
try:
|
||||
self.engine = PaddleOCR(**kwargs)
|
||||
self.engine = self._create_engine(kwargs)
|
||||
self.available = True
|
||||
print('[INFO] PaddleOCR backend ready (lang={})'.format(self.lang))
|
||||
except Exception as exc:
|
||||
|
|
@ -66,6 +66,19 @@ class PaddleOCRBackend(object):
|
|||
self.available = False
|
||||
print('[WARN] Failed to initialize PaddleOCR backend: {}'.format(exc), file=sys.stderr)
|
||||
|
||||
def _create_engine(self, kwargs):
|
||||
try:
|
||||
return PaddleOCR(**kwargs)
|
||||
except TypeError as exc:
|
||||
# Backward compatibility with older PaddleOCR versions.
|
||||
msg = str(exc)
|
||||
if 'unexpected keyword argument' not in msg:
|
||||
raise
|
||||
relaxed = dict(kwargs)
|
||||
relaxed.pop('cpu_threads', None)
|
||||
relaxed.pop('show_log', None)
|
||||
return PaddleOCR(**relaxed)
|
||||
|
||||
def run_ocr(self, img_rgb, return_boxes=True):
|
||||
if not self.available or img_rgb is None:
|
||||
return '', []
|
||||
|
|
|
|||
|
|
@ -1,3 +1,3 @@
|
|||
# Optional OCR backend dependencies.
|
||||
# PaddleOCR 3.x supports Python 3.8+.
|
||||
paddleocr>=3.0.0
|
||||
# Optional OCR backend dependencies (Python 3.6 compatible line).
|
||||
# 2.7.5 is yanked on PyPI; 2.7.3 is usually the safer pin.
|
||||
paddleocr==2.7.3
|
||||
|
|
|
|||
|
|
@ -15,8 +15,8 @@ export OCR_CONFIG=${OCR_CONFIG:---oem 1 --psm 6}
|
|||
export PADDLE_LANG=${PADDLE_LANG:-ru}
|
||||
export PADDLE_USE_GPU=${PADDLE_USE_GPU:-false}
|
||||
export PADDLE_USE_ANGLE_CLS=${PADDLE_USE_ANGLE_CLS:-false}
|
||||
export PADDLE_DET_MODEL_DIR=${PADDLE_DET_MODEL_DIR:-./models/paddle/PP-OCRv5_mobile_det_infer}
|
||||
export PADDLE_REC_MODEL_DIR=${PADDLE_REC_MODEL_DIR:-./models/paddle/eslav_PP-OCRv5_mobile_rec_infer}
|
||||
export PADDLE_DET_MODEL_DIR=${PADDLE_DET_MODEL_DIR:-./models/paddle/PP-OCRv3_mobile_det_infer}
|
||||
export PADDLE_REC_MODEL_DIR=${PADDLE_REC_MODEL_DIR:-./models/paddle/cyrillic_PP-OCRv3_mobile_rec_infer}
|
||||
export PADDLE_CLS_MODEL_DIR=${PADDLE_CLS_MODEL_DIR:-}
|
||||
export PADDLE_CPU_THREADS=${PADDLE_CPU_THREADS:-4}
|
||||
# Point to tessdata_best if installed
|
||||
|
|
|
|||
|
|
@ -130,9 +130,9 @@ EAST_URL="https://github.com/argman/EAST/releases/download/model/frozen_east_tex
|
|||
TESS_ENG_URL="https://github.com/tesseract-ocr/tessdata_best/raw/main/eng.traineddata"
|
||||
TESS_RUS_URL="https://github.com/tesseract-ocr/tessdata_best/raw/main/rus.traineddata"
|
||||
|
||||
# PaddleOCR v5 mobile models (detection + RU/EN recognition)
|
||||
PADDLE_DET_URL="https://paddle-model-ecology.bj.bcebos.com/paddlex/official_inference_model/paddle3.0.0/PP-OCRv5_mobile_det_infer.tar"
|
||||
PADDLE_REC_URL="https://paddle-model-ecology.bj.bcebos.com/paddlex/official_inference_model/paddle3.0.0/eslav_PP-OCRv5_mobile_rec_infer.tar"
|
||||
# PaddleOCR v3 mobile models (good compatibility with paddleocr 2.7.x / Python 3.6)
|
||||
PADDLE_DET_URL="https://paddle-model-ecology.bj.bcebos.com/paddlex/official_inference_model/paddle3.0.0/PP-OCRv3_mobile_det_infer.tar"
|
||||
PADDLE_REC_URL="https://paddle-model-ecology.bj.bcebos.com/paddlex/official_inference_model/paddle3.0.0/cyrillic_PP-OCRv3_mobile_rec_infer.tar"
|
||||
|
||||
if [[ "$DOWNLOAD_CORAL" == "1" ]]; then
|
||||
download_file "$CORAL_MODEL_URL" "$MODELS_DIR/ssd_mobilenet_v2_coco_quant_postprocess_edgetpu.tflite"
|
||||
|
|
@ -144,8 +144,8 @@ if [[ "$DOWNLOAD_EAST" == "1" ]]; then
|
|||
fi
|
||||
|
||||
if [[ "$DOWNLOAD_PADDLE" == "1" ]]; then
|
||||
download_and_extract_tar "$PADDLE_DET_URL" "PP-OCRv5_mobile_det_infer" "$PADDLE_DIR"
|
||||
download_and_extract_tar "$PADDLE_REC_URL" "eslav_PP-OCRv5_mobile_rec_infer" "$PADDLE_DIR"
|
||||
download_and_extract_tar "$PADDLE_DET_URL" "PP-OCRv3_mobile_det_infer" "$PADDLE_DIR"
|
||||
download_and_extract_tar "$PADDLE_REC_URL" "cyrillic_PP-OCRv3_mobile_rec_infer" "$PADDLE_DIR"
|
||||
fi
|
||||
|
||||
if [[ "$DOWNLOAD_TESSDATA" == "1" ]]; then
|
||||
|
|
@ -167,6 +167,6 @@ Recommended env:
|
|||
For PaddleOCR backend:
|
||||
export OCR_BACKEND="paddle"
|
||||
export PADDLE_LANG="ru"
|
||||
export PADDLE_DET_MODEL_DIR="$PADDLE_DIR/PP-OCRv5_mobile_det_infer"
|
||||
export PADDLE_REC_MODEL_DIR="$PADDLE_DIR/eslav_PP-OCRv5_mobile_rec_infer"
|
||||
export PADDLE_DET_MODEL_DIR="$PADDLE_DIR/PP-OCRv3_mobile_det_infer"
|
||||
export PADDLE_REC_MODEL_DIR="$PADDLE_DIR/cyrillic_PP-OCRv3_mobile_rec_infer"
|
||||
EOF
|
||||
|
|
|
|||
Loading…
Reference in a new issue