@solazah/solazah-runtime 0.2.33 → 0.2.36
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/types/SystemOCR.d.ts +43 -0
package/package.json
CHANGED
package/types/SystemOCR.d.ts
CHANGED
|
@@ -6,6 +6,22 @@ export interface OCRTextBlock {
|
|
|
6
6
|
/** 四个角点坐标,顺时针或逆时针,不是 x/y/width/height 矩形 */
|
|
7
7
|
box: [number, number][];
|
|
8
8
|
}
|
|
9
|
+
/** 检测结果,与主进程 OcrProtocol 的 OcrDetection 同构(真源在那里)。 */
|
|
10
|
+
export interface OCRDetection {
|
|
11
|
+
/** 帧句柄,交给 recognizeBoxes 按框取字。 */
|
|
12
|
+
frame: string;
|
|
13
|
+
width: number;
|
|
14
|
+
height: number;
|
|
15
|
+
/** 文字框,每个是四个角点坐标(顺时针,从左上起),按阅读顺序排列;recognizeBoxes 的 indices 指的就是这里的序号。 */
|
|
16
|
+
boxes: [number, number][][];
|
|
17
|
+
}
|
|
18
|
+
/** 按框识别的结果,与主进程 OcrProtocol 的 OcrBoxTexts 同构(真源在那里)。 */
|
|
19
|
+
export type OCRBoxTexts = {
|
|
20
|
+
found: true;
|
|
21
|
+
texts: Array<OCRTextBlock | null>;
|
|
22
|
+
} | {
|
|
23
|
+
found: false;
|
|
24
|
+
};
|
|
9
25
|
export default class SystemOCR {
|
|
10
26
|
private transport;
|
|
11
27
|
constructor(transport?: IpcRenderer);
|
|
@@ -17,4 +33,31 @@ export default class SystemOCR {
|
|
|
17
33
|
* @throws 图片解码失败或 OCR 引擎未就绪时抛错。
|
|
18
34
|
*/
|
|
19
35
|
recognize: (base64String: string) => Promise<OCRTextBlock[]>;
|
|
36
|
+
/**
|
|
37
|
+
* 两步式识别的第一步:只检测出文字框,不认字。检测只占整图识别耗时的一小部分,大头是逐框认字;
|
|
38
|
+
* 先要框的位置(如框选、高亮)时用它,文字再用 recognizeBoxes 按需取。
|
|
39
|
+
* 同一张图重复调用命中缓存,直接返回同一个帧句柄。
|
|
40
|
+
*
|
|
41
|
+
* @param base64String Base64 编码的图片数据(PNG、JPEG、BMP)。
|
|
42
|
+
* @returns frame(帧句柄)、width/height(图片尺寸)、boxes(文字框,阅读顺序)。
|
|
43
|
+
* @throws 图片解码失败或 OCR 引擎未就绪时抛错。
|
|
44
|
+
*/
|
|
45
|
+
detect: (base64String: string) => Promise<OCRDetection>;
|
|
46
|
+
/**
|
|
47
|
+
* 两步式识别的第二步:按框认字。已认过的框直接返回,同一个框不会重复推理。
|
|
48
|
+
*
|
|
49
|
+
* 返回 found: false 表示这一帧已不在引擎里(之后检测的图太多把它挤出、OCR 进程空闲回收或重启),
|
|
50
|
+
* 或要的框里有没认过的、而这一帧的原图已经释放(之后又有几张图检测完在等补字,引擎只给最近用过的几张留原图);
|
|
51
|
+
* 这是预期内的结果,不是失败:用同一张图重新 detect,拿新的 frame 再取(框的序号不变)。
|
|
52
|
+
*
|
|
53
|
+
* @param frame detect 返回的帧句柄。
|
|
54
|
+
* @param indices 要认的框在 detect 返回的 boxes 里的序号。
|
|
55
|
+
* @param options background 为 true 时排在一切前台请求之后,适合在后台分批把整帧补齐;
|
|
56
|
+
* 用户正在看、正在选的框不要带它。
|
|
57
|
+
* @returns found 为 true 时 texts 与 indices 一一对应,框里认不出字为 null。
|
|
58
|
+
* @throws 序号越界或 OCR 引擎出错时抛错。
|
|
59
|
+
*/
|
|
60
|
+
recognizeBoxes: (frame: string, indices: number[], options?: {
|
|
61
|
+
background?: boolean;
|
|
62
|
+
}) => Promise<OCRBoxTexts>;
|
|
20
63
|
}
|