Skip to content

Commit

Permalink
Optimize rapidocr_api return parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
SWHL committed Mar 4, 2024
1 parent 2caa0b0 commit 39c3a35
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 9 deletions.
1 change: 1 addition & 0 deletions .github/workflows/gen_whl_to_pypi_rapidocr_api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ jobs:
run: |
cd api
pip install -r requirements.txt
pip install get_pypi_latest_version wheel
python -m pip install --upgrade pip
python setup.py bdist_wheel ${{ github.event.head_commit.message }}
Expand Down
11 changes: 4 additions & 7 deletions api/rapidocr_api/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,29 @@
import argparse
import base64
import io
import json
from pathlib import Path
import sys
from pathlib import Path
from typing import Dict

import cv2
import numpy as np
import uvicorn
from fastapi import FastAPI, Form, UploadFile
from PIL import Image
from rapidocr_onnxruntime import RapidOCR


sys.path.append(str(Path(__file__).resolve().parent.parent))


class OCRAPIUtils:
def __init__(self) -> None:
self.ocr = RapidOCR()

def __call__(self, img):
def __call__(self, img: Image.Image) -> Dict:
img = np.array(img)
img = cv2.cvtColor(img, cv2.COLOR_RGB2BGR)

ocr_res, _ = self.ocr(img)
if not ocr_res:
return json.dumps({})
return {}

out_dict = {
str(i): {"rec_txt": rec, "dt_boxes": dt_box, "score": score}
Expand Down
3 changes: 1 addition & 2 deletions api/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
requests
rapidocr_onnxruntime
get_pypi_latest_version
wheel
fastapi
uvicorn[standard]
python-multipart

0 comments on commit 39c3a35

Please sign in to comment.