4.2.0 • Published 9 days ago

esearch-ocr v4.2.0

Weekly downloads
-
License
Apache-2.0
Repository
-
Last release
9 days ago

eSearch-OCR

本仓库是 eSearch的 OCR 服务依赖

支持本地 OCR(基于 PaddleOCR

PaddleOCR License

paddle 预测库

基于onnxruntime的 web runtime,使用 wasm 运行,未来可能使用 webgl 甚至是 webgpu。

模型需要转换为 onnx 才能使用:Paddle2ONNX在线转换

在 js 文件下可以使用 electron 进行调试

使用

npm i esearch-ocr onnxruntime-web

web

import * as ocr from "esearch-ocr";
import * as ort from "onnxruntime-web";
const ocr = require("esearch-ocr");
const ort = require("onnxruntime-node");

!IMPORTANT 需要手动安装 onnxruntime(onnxruntime-node 或 onnxruntime-web,视平台而定),并在init参数中传入ort 这样设计是因为 web 和 electron 可以使用不同的 ort,很难协调,不如让开发者自己决定

浏览器或 Electron 实例

await ocr.init({
    detPath: "ocr/det.onnx",
    recPath: "ocr/rec.onnx",
    dic: "abcdefg...",
    ort,
});

let img = document.createElement("img");
img.src = "data:image/png;base64,...";
img.onload = async () => {
    let canvas = document.createElement("canvas");
    canvas.width = img.width;
    canvas.height = img.height;
    canvas.getContext("2d").drawImage(img, 0, 0);
    ocr.ocr(canvas.getContext("2d").getImageData(0, 0, img.width, img.height))
        .then((l) => {})
        .catch((e) => {});
};

node.js 实例,需要安装canvas

init type

{
    ort: typeof import("onnxruntime-web");
    detPath: string;
    recPath: string;
    dic: string; // 文件内容,不是路径
    dev?: boolean;
    maxSide?: number;
    imgh?: number;
    imgw?: number;
    detShape?: [number, number]; // ppocr v3 需要指定为[960, 960], v4 为[640, 640]
    canvas?: (w: number, h: number) => any; // 用于node
    imageData?: any; // 用于node
    cv?: any;
}

ocr type

type PointType = [number, number]
ocr(img: ImageData): Promise<{
    text: string;
    mean: number;
    box: [PointType, PointType, PointType, PointType]; // ↖ ↗ ↘ ↙
}[]>

除了 ocr 函数,还有det函数,可单独运行,检测文字坐标;rec函数,可单独运行,检测文字内容。具体定义可看编辑器提示

4.1.5

9 days ago

4.2.0

9 days ago

4.1.2

4 months ago

4.1.1

8 months ago

4.1.0

11 months ago

4.0.1

11 months ago

4.0.0

11 months ago