基于hiroi-sora/PaddleOCR-json的node.js api.
Log
v1.1.0 2023.5.2
适配 hiroi-sora/PaddleOCR-json v1.3.0 Alpha.1
(v1.2 回退 paddleocrjson@1.0.11-a)
v1.0.8 2023.1.20
---
v1.0.7 2022.11.8
---
v1.0.6 2022.11.8
OCR.postMessage
与OCR.flush
区别开.
使监听的数据与OCR.flush
返回的数据一致.
优化动态参数中关于路径的字段.
使用npm
包管理.
使用ts
编译.
v1.0.5 2022.10.12
---
v1.0.4 2022.10.1
适配hiroi-sora/PaddleOCR-json v1.2.1.
不使用iconv-lite
包.
更改启动参数输入方式.
v1.0.3 2022.10.1
适配hiroi-sora/PaddleOCR-json v1.2.1.
v1.0.2 2022.9.14
增加环境选项.
v1.0.1 2022.9.14
修复无法识别 Alpha版 的启动完成标志的bug. JSON输入更改为ascii转义.
v1.0.0 2022.9.10
---
npm install paddleocrjson
const OCR = require('paddleocrjson');
const OCR = require('paddleocrjson/es5'); // ES5
const ocr = new OCR('PaddleOCR-json.exe', [/* '-port=9985', '-addr=loopback' */], {
cwd: './PaddleOCR-json',
}, /* debug */true);
ocr.flush({ image_path: 'path/to/test/img' })
.then((data) => console.log(data));
.then(() => ocr.terminate());
// debug = true
ocr.stdout.on('data', (chunk) =>{
console.log(chunk.toString());
});
ocr.stderr.on('data', (data) =>{
console.log(data.toString());
});
ocr.on('exit', (code) =>{
console.log('exit code: ', code);
});
详见PunchlY/PaddleOCR-json-node-api/test.
OCR
是worker_threads.Worker
的派生类.
const ocr = new OCR('PaddleOCR_json.exe', [], {
cwd: './PaddleOCR-json',
}, false);
args
详见Node.js child_process.spawn与hiroi-sora/PaddleOCR-json#配置参数说明.
options
详见Node.js child_process.spawn.
ocr.flush({
/* image_path: null, // -image_path=clipboard */
image_path: 'path/to/test/img',
// limit_side_len: 960,
// ...
});
ocr.flush
返回的是Promise
对象.
obj
详见hiroi-sora/PaddleOCR-json/blob/main/docs/详细使用指南.md#配置参数
如果要识别剪贴板,请传入{ image_path: null }
(obj.image_dir
设置为null
).
你可以用worker_threads.Worker
的api来监听或操作OCR
实例.
例如:
ocr.on('init', (pid, addr, port) => {
console.log('OCR init completed.');
console.log('pid:', pid);
console.log('addr:', addr);
console.log('port:', port);
});
ocr.on('message', (data) => {
console.log(data);
// { code: ..., message: ..., data: ... }
});
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2023 PunchlY
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
1. You just DO WHAT THE FUCK YOU WANT TO.