@areb0s/ocr-common 1.0.0
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/build/Ocr.d.ts +15 -0
- package/build/Ocr.js +24 -0
- package/build/Ocr.js.map +1 -0
- package/build/backend/FileUtilsBase.d.ts +3 -0
- package/build/backend/FileUtilsBase.js +6 -0
- package/build/backend/FileUtilsBase.js.map +1 -0
- package/build/backend/ImageRawBase.d.ts +8 -0
- package/build/backend/ImageRawBase.js +14 -0
- package/build/backend/ImageRawBase.js.map +1 -0
- package/build/backend/backend.d.ts +14 -0
- package/build/backend/backend.js +14 -0
- package/build/backend/backend.js.map +1 -0
- package/build/backend/index.d.ts +3 -0
- package/build/backend/index.js +4 -0
- package/build/backend/index.js.map +1 -0
- package/build/backend/splitIntoLineImages.d.ts +2 -0
- package/build/backend/splitIntoLineImages.js +231 -0
- package/build/backend/splitIntoLineImages.js.map +1 -0
- package/build/index.d.ts +6 -0
- package/build/index.js +6 -0
- package/build/index.js.map +1 -0
- package/build/models/Detection.d.ts +13 -0
- package/build/models/Detection.js +82 -0
- package/build/models/Detection.js.map +1 -0
- package/build/models/ModelBase.d.ts +14 -0
- package/build/models/ModelBase.js +53 -0
- package/build/models/ModelBase.js.map +1 -0
- package/build/models/Recognition.d.ts +12 -0
- package/build/models/Recognition.js +190 -0
- package/build/models/Recognition.js.map +1 -0
- package/build/models/index.d.ts +2 -0
- package/build/models/index.js +3 -0
- package/build/models/index.js.map +1 -0
- package/build/types/index.d.ts +1 -0
- package/build/types/index.js +2 -0
- package/build/types/index.js.map +1 -0
- package/build/types/types.d.ts +67 -0
- package/build/types/types.js +5 -0
- package/build/types/types.js.map +1 -0
- package/package.json +34 -0
- package/src/Ocr.ts +34 -0
- package/src/backend/FileUtilsBase.ts +5 -0
- package/src/backend/ImageRawBase.ts +17 -0
- package/src/backend/backend.ts +29 -0
- package/src/backend/index.ts +3 -0
- package/src/backend/splitIntoLineImages.ts +296 -0
- package/src/index.ts +8 -0
- package/src/models/Detection.ts +96 -0
- package/src/models/ModelBase.ts +74 -0
- package/src/models/Recognition.ts +217 -0
- package/src/models/index.ts +2 -0
- package/src/types/global.d.ts +7 -0
- package/src/types/index.ts +1 -0
- package/src/types/types.ts +90 -0
- package/tsconfig.json +10 -0
package/build/Ocr.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { ImageRawData, BrowserImageInput, ModelCreateOptions } from './types/index.js';
|
|
2
|
+
import { Detection, Recognition } from './models/index.js';
|
|
3
|
+
export declare class Ocr {
|
|
4
|
+
#private;
|
|
5
|
+
static create(options?: ModelCreateOptions): Promise<Ocr>;
|
|
6
|
+
constructor({ detection, recognition, }: {
|
|
7
|
+
detection: Detection;
|
|
8
|
+
recognition: Recognition;
|
|
9
|
+
});
|
|
10
|
+
detect(image: string | ImageRawData | BrowserImageInput, options?: {}): Promise<{
|
|
11
|
+
texts: import("./types/index.js").Line[];
|
|
12
|
+
resizedImageWidth: any;
|
|
13
|
+
resizedImageHeight: any;
|
|
14
|
+
}>;
|
|
15
|
+
}
|
package/build/Ocr.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Detection, Recognition } from './models/index.js';
|
|
2
|
+
export class Ocr {
|
|
3
|
+
static async create(options = {}) {
|
|
4
|
+
const detection = await Detection.create(options);
|
|
5
|
+
const recognition = await Recognition.create(options);
|
|
6
|
+
return new Ocr({ detection, recognition });
|
|
7
|
+
}
|
|
8
|
+
#detection;
|
|
9
|
+
#recognition;
|
|
10
|
+
constructor({ detection, recognition, }) {
|
|
11
|
+
this.#detection = detection;
|
|
12
|
+
this.#recognition = recognition;
|
|
13
|
+
}
|
|
14
|
+
async detect(image, options = {}) {
|
|
15
|
+
const { lineImages, resizedImageWidth, resizedImageHeight } = await this.#detection.run(image, options);
|
|
16
|
+
const texts = await this.#recognition.run(lineImages, options);
|
|
17
|
+
return {
|
|
18
|
+
texts,
|
|
19
|
+
resizedImageWidth,
|
|
20
|
+
resizedImageHeight,
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=Ocr.js.map
|
package/build/Ocr.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Ocr.js","sourceRoot":"","sources":["../src/Ocr.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,UAAU,CAAA;AAEjD,MAAM,OAAO,GAAG;IACd,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,UAA8B,EAAE;QAClD,MAAM,SAAS,GAAG,MAAM,SAAS,CAAC,MAAM,CAAC,OAAO,CAAC,CAAA;QACjD,MAAM,WAAW,GAAG,MAAM,WAAW,CAAC,MAAM,CAAC,OAAO,CAAC,CAAA;QACrD,OAAO,IAAI,GAAG,CAAC,EAAE,SAAS,EAAE,WAAW,EAAE,CAAC,CAAA;IAC5C,CAAC;IAED,UAAU,CAAW;IACrB,YAAY,CAAa;IAEzB,YAAY,EACV,SAAS,EACT,WAAW,GAIZ;QACC,IAAI,CAAC,UAAU,GAAG,SAAS,CAAA;QAC3B,IAAI,CAAC,YAAY,GAAG,WAAW,CAAA;IACjC,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,KAAgD,EAAE,OAAO,GAAG,EAAE;QACzE,MAAM,EAAE,UAAU,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,KAAK,EAAE,OAAO,CAAC,CAAA;QACvG,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,UAAU,EAAE,OAAO,CAAC,CAAA;QAC9D,OAAO;YACL,KAAK;YACL,iBAAiB;YACjB,kBAAkB;SACnB,CAAA;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FileUtilsBase.js","sourceRoot":"","sources":["../../src/backend/FileUtilsBase.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,aAAa;IACxB,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,IAAY;QAC5B,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC,CAAA;IACpC,CAAC;CACF"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { ImageRawData } from '../types/index.js';
|
|
2
|
+
export declare class ImageRawBase {
|
|
3
|
+
data: ImageRawData['data'];
|
|
4
|
+
width: ImageRawData['width'];
|
|
5
|
+
height: ImageRawData['height'];
|
|
6
|
+
constructor({ data, width, height }: ImageRawData);
|
|
7
|
+
getImageRawData(): ImageRawData;
|
|
8
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export class ImageRawBase {
|
|
2
|
+
data;
|
|
3
|
+
width;
|
|
4
|
+
height;
|
|
5
|
+
constructor({ data, width, height }) {
|
|
6
|
+
this.data = data;
|
|
7
|
+
this.width = width;
|
|
8
|
+
this.height = height;
|
|
9
|
+
}
|
|
10
|
+
getImageRawData() {
|
|
11
|
+
return { data: this.data, width: this.width, height: this.height };
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=ImageRawBase.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ImageRawBase.js","sourceRoot":"","sources":["../../src/backend/ImageRawBase.ts"],"names":[],"mappings":"AAEA,MAAM,OAAO,YAAY;IACvB,IAAI,CAAsB;IAC1B,KAAK,CAAuB;IAC5B,MAAM,CAAwB;IAE9B,YAAY,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,EAAgB;QAC/C,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;QAChB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAA;QAClB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;IACtB,CAAC;IAED,eAAe;QACb,OAAO,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,CAAA;IACpE,CAAC;CACF"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { FileUtils as FileUtilsType, ImageRaw as ImageRawType, InferenceSession as InferenceSessionType, ModelCreateOptions as ModelCreateOptionsType, SplitIntoLineImages as SplitIntoLineImagesType } from '../types/index.js';
|
|
2
|
+
declare let FileUtils: FileUtilsType | any;
|
|
3
|
+
declare let ImageRaw: ImageRawType | any;
|
|
4
|
+
declare let InferenceSession: InferenceSessionType | any;
|
|
5
|
+
declare let splitIntoLineImages: SplitIntoLineImagesType;
|
|
6
|
+
declare let defaultModels: ModelCreateOptionsType['models'];
|
|
7
|
+
export declare function registerBackend(backend: {
|
|
8
|
+
FileUtils: FileUtilsType;
|
|
9
|
+
ImageRaw: ImageRawType | any;
|
|
10
|
+
InferenceSession: InferenceSessionType | any;
|
|
11
|
+
splitIntoLineImages: SplitIntoLineImagesType;
|
|
12
|
+
defaultModels: ModelCreateOptionsType['models'];
|
|
13
|
+
}): void;
|
|
14
|
+
export { FileUtils, ImageRaw, InferenceSession, splitIntoLineImages, defaultModels };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
let FileUtils = undefined;
|
|
2
|
+
let ImageRaw = undefined;
|
|
3
|
+
let InferenceSession = undefined;
|
|
4
|
+
let splitIntoLineImages = undefined;
|
|
5
|
+
let defaultModels = undefined;
|
|
6
|
+
export function registerBackend(backend) {
|
|
7
|
+
FileUtils = backend.FileUtils;
|
|
8
|
+
ImageRaw = backend.ImageRaw;
|
|
9
|
+
InferenceSession = backend.InferenceSession;
|
|
10
|
+
splitIntoLineImages = backend.splitIntoLineImages;
|
|
11
|
+
defaultModels = backend.defaultModels;
|
|
12
|
+
}
|
|
13
|
+
export { FileUtils, ImageRaw, InferenceSession, splitIntoLineImages, defaultModels };
|
|
14
|
+
//# sourceMappingURL=backend.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"backend.js","sourceRoot":"","sources":["../../src/backend/backend.ts"],"names":[],"mappings":"AAQA,IAAI,SAAS,GAAwB,SAAqC,CAAA;AAC1E,IAAI,QAAQ,GAAuB,SAAoC,CAAA;AACvE,IAAI,gBAAgB,GAA+B,SAA4C,CAAA;AAC/F,IAAI,mBAAmB,GAA4B,SAA+C,CAAA;AAClG,IAAI,aAAa,GAAqC,SAAwD,CAAA;AAE9G,MAAM,UAAU,eAAe,CAAC,OAM/B;IACC,SAAS,GAAG,OAAO,CAAC,SAAS,CAAA;IAC7B,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAA;IAC3B,gBAAgB,GAAG,OAAO,CAAC,gBAAgB,CAAA;IAC3C,mBAAmB,GAAG,OAAO,CAAC,mBAAmB,CAAA;IACjD,aAAa,GAAG,OAAO,CAAC,aAAa,CAAA;AACvC,CAAC;AAED,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,aAAa,EAAE,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/backend/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAA;AACzB,cAAc,iBAAiB,CAAA;AAC/B,cAAc,gBAAgB,CAAA"}
|
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
import cv from '@techstark/opencv-js';
|
|
2
|
+
import clipper from 'js-clipper';
|
|
3
|
+
import { ImageRaw } from '../backend/index.js';
|
|
4
|
+
export async function splitIntoLineImages(image, sourceImage) {
|
|
5
|
+
const w = image.width;
|
|
6
|
+
const h = image.height;
|
|
7
|
+
const srcData = sourceImage;
|
|
8
|
+
const edgeRect = [];
|
|
9
|
+
const src = cvImread(image);
|
|
10
|
+
cv.cvtColor(src, src, cv.COLOR_RGBA2GRAY, 0);
|
|
11
|
+
const contours = new cv.MatVector();
|
|
12
|
+
const hierarchy = new cv.Mat();
|
|
13
|
+
cv.findContours(src, contours, hierarchy, cv.RETR_LIST, cv.CHAIN_APPROX_SIMPLE);
|
|
14
|
+
for (let i = 0; i < contours.size(); i++) {
|
|
15
|
+
const minSize = 3;
|
|
16
|
+
const cnt = contours.get(i);
|
|
17
|
+
const { points, sside } = getMiniBoxes(cnt);
|
|
18
|
+
if (sside < minSize)
|
|
19
|
+
continue;
|
|
20
|
+
// TODO sort fast
|
|
21
|
+
const clipBox = unclip(points);
|
|
22
|
+
const boxMap = cv.matFromArray(clipBox.length / 2, 1, cv.CV_32SC2, clipBox);
|
|
23
|
+
const resultObj = getMiniBoxes(boxMap);
|
|
24
|
+
const box = resultObj.points;
|
|
25
|
+
if (resultObj.sside < minSize + 2) {
|
|
26
|
+
continue;
|
|
27
|
+
}
|
|
28
|
+
function clip(n, min, max) {
|
|
29
|
+
return Math.max(min, Math.min(n, max));
|
|
30
|
+
}
|
|
31
|
+
const rx = srcData.width / w;
|
|
32
|
+
const ry = srcData.height / h;
|
|
33
|
+
for (let i = 0; i < box.length; i++) {
|
|
34
|
+
box[i][0] *= rx;
|
|
35
|
+
box[i][1] *= ry;
|
|
36
|
+
}
|
|
37
|
+
const box1 = orderPointsClockwise(box);
|
|
38
|
+
box1.forEach((item) => {
|
|
39
|
+
item[0] = clip(Math.round(item[0]), 0, srcData.width);
|
|
40
|
+
item[1] = clip(Math.round(item[1]), 0, srcData.height);
|
|
41
|
+
});
|
|
42
|
+
const rect_width = int(linalgNorm(box1[0], box1[1]));
|
|
43
|
+
const rect_height = int(linalgNorm(box1[0], box1[3]));
|
|
44
|
+
if (rect_width <= 3 || rect_height <= 3)
|
|
45
|
+
continue;
|
|
46
|
+
const c = getRotateCropImage(srcData, box);
|
|
47
|
+
edgeRect.push({
|
|
48
|
+
box,
|
|
49
|
+
image: c,
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
src.delete();
|
|
53
|
+
contours.delete();
|
|
54
|
+
hierarchy.delete();
|
|
55
|
+
return edgeRect;
|
|
56
|
+
}
|
|
57
|
+
function getMiniBoxes(contour) {
|
|
58
|
+
const boundingBox = cv.minAreaRect(contour);
|
|
59
|
+
const points = Array.from(boxPoints(boundingBox.center, boundingBox.size, boundingBox.angle)).sort((a, b) => a[0] - b[0]);
|
|
60
|
+
let index_1 = 0, index_2 = 1, index_3 = 2, index_4 = 3;
|
|
61
|
+
if (points[1][1] > points[0][1]) {
|
|
62
|
+
index_1 = 0;
|
|
63
|
+
index_4 = 1;
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
index_1 = 1;
|
|
67
|
+
index_4 = 0;
|
|
68
|
+
}
|
|
69
|
+
if (points[3][1] > points[2][1]) {
|
|
70
|
+
index_2 = 2;
|
|
71
|
+
index_3 = 3;
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
index_2 = 3;
|
|
75
|
+
index_3 = 2;
|
|
76
|
+
}
|
|
77
|
+
const box = [points[index_1], points[index_2], points[index_3], points[index_4]];
|
|
78
|
+
const side = Math.min(boundingBox.size.height, boundingBox.size.width);
|
|
79
|
+
return { points: box, sside: side };
|
|
80
|
+
}
|
|
81
|
+
function unclip(box) {
|
|
82
|
+
const unclip_ratio = 1.5;
|
|
83
|
+
const area = Math.abs(polygonPolygonArea(box));
|
|
84
|
+
const length = polygonPolygonLength(box);
|
|
85
|
+
const distance = (area * unclip_ratio) / length;
|
|
86
|
+
const tmpArr = [];
|
|
87
|
+
box.forEach((item) => {
|
|
88
|
+
const obj = {
|
|
89
|
+
X: 0,
|
|
90
|
+
Y: 0,
|
|
91
|
+
};
|
|
92
|
+
obj.X = item[0];
|
|
93
|
+
obj.Y = item[1];
|
|
94
|
+
tmpArr.push(obj);
|
|
95
|
+
});
|
|
96
|
+
const offset = new clipper.ClipperOffset();
|
|
97
|
+
offset.AddPath(tmpArr, clipper.JoinType.jtRound, clipper.EndType.etClosedPolygon);
|
|
98
|
+
const expanded = [];
|
|
99
|
+
offset.Execute(expanded, distance);
|
|
100
|
+
let expandedArr = [];
|
|
101
|
+
expanded[0] &&
|
|
102
|
+
expanded[0].forEach((item) => {
|
|
103
|
+
expandedArr.push([item.X, item.Y]);
|
|
104
|
+
});
|
|
105
|
+
expandedArr = [].concat(...expandedArr);
|
|
106
|
+
return expandedArr;
|
|
107
|
+
}
|
|
108
|
+
function orderPointsClockwise(pts) {
|
|
109
|
+
const rect = [
|
|
110
|
+
[0, 0],
|
|
111
|
+
[0, 0],
|
|
112
|
+
[0, 0],
|
|
113
|
+
[0, 0],
|
|
114
|
+
];
|
|
115
|
+
const s = pts.map((pt) => pt[0] + pt[1]);
|
|
116
|
+
rect[0] = pts[s.indexOf(Math.min(...s))];
|
|
117
|
+
rect[2] = pts[s.indexOf(Math.max(...s))];
|
|
118
|
+
const tmp = pts.filter((pt) => pt !== rect[0] && pt !== rect[2]);
|
|
119
|
+
const diff = tmp[1].map((e, i) => e - tmp[0][i]);
|
|
120
|
+
rect[1] = tmp[diff.indexOf(Math.min(...diff))];
|
|
121
|
+
rect[3] = tmp[diff.indexOf(Math.max(...diff))];
|
|
122
|
+
return rect;
|
|
123
|
+
}
|
|
124
|
+
function linalgNorm(p0, p1) {
|
|
125
|
+
return Math.sqrt(Math.pow(p0[0] - p1[0], 2) + Math.pow(p0[1] - p1[1], 2));
|
|
126
|
+
}
|
|
127
|
+
function int(num) {
|
|
128
|
+
return num > 0 ? Math.floor(num) : Math.ceil(num);
|
|
129
|
+
}
|
|
130
|
+
function getRotateCropImage(imageRaw, points) {
|
|
131
|
+
const img_crop_width = int(Math.max(linalgNorm(points[0], points[1]), linalgNorm(points[2], points[3])));
|
|
132
|
+
const img_crop_height = int(Math.max(linalgNorm(points[0], points[3]), linalgNorm(points[1], points[2])));
|
|
133
|
+
const pts_std = [
|
|
134
|
+
[0, 0],
|
|
135
|
+
[img_crop_width, 0],
|
|
136
|
+
[img_crop_width, img_crop_height],
|
|
137
|
+
[0, img_crop_height],
|
|
138
|
+
];
|
|
139
|
+
const srcTri = cv.matFromArray(4, 1, cv.CV_32FC2, flatten(points));
|
|
140
|
+
const dstTri = cv.matFromArray(4, 1, cv.CV_32FC2, flatten(pts_std));
|
|
141
|
+
// 获取到目标矩阵
|
|
142
|
+
const M = cv.getPerspectiveTransform(srcTri, dstTri);
|
|
143
|
+
const src = cvImread(imageRaw);
|
|
144
|
+
const dst = new cv.Mat();
|
|
145
|
+
const dsize = new cv.Size(img_crop_width, img_crop_height);
|
|
146
|
+
// 透视转换
|
|
147
|
+
cv.warpPerspective(src, dst, M, dsize, cv.INTER_CUBIC, cv.BORDER_REPLICATE, new cv.Scalar());
|
|
148
|
+
const dst_img_height = dst.matSize[0];
|
|
149
|
+
const dst_img_width = dst.matSize[1];
|
|
150
|
+
let dst_rot;
|
|
151
|
+
// 图像旋转
|
|
152
|
+
if (dst_img_height / dst_img_width >= 1.5) {
|
|
153
|
+
dst_rot = new cv.Mat();
|
|
154
|
+
const dsize_rot = new cv.Size(dst.rows, dst.cols);
|
|
155
|
+
const center = new cv.Point(dst.cols / 2, dst.cols / 2);
|
|
156
|
+
const M = cv.getRotationMatrix2D(center, 90, 1);
|
|
157
|
+
cv.warpAffine(dst, dst_rot, M, dsize_rot, cv.INTER_CUBIC, cv.BORDER_REPLICATE, new cv.Scalar());
|
|
158
|
+
}
|
|
159
|
+
src.delete();
|
|
160
|
+
srcTri.delete();
|
|
161
|
+
dstTri.delete();
|
|
162
|
+
if (dst_rot) {
|
|
163
|
+
dst.delete();
|
|
164
|
+
}
|
|
165
|
+
return cvImshow(dst_rot || dst);
|
|
166
|
+
}
|
|
167
|
+
function boxPoints(center, size, angle) {
|
|
168
|
+
const width = size.width;
|
|
169
|
+
const height = size.height;
|
|
170
|
+
const theta = (angle * Math.PI) / 180.0;
|
|
171
|
+
const cosTheta = Math.cos(theta);
|
|
172
|
+
const sinTheta = Math.sin(theta);
|
|
173
|
+
const cx = center.x;
|
|
174
|
+
const cy = center.y;
|
|
175
|
+
const dx = width * 0.5;
|
|
176
|
+
const dy = height * 0.5;
|
|
177
|
+
const rotatedPoints = [];
|
|
178
|
+
// Top-Left
|
|
179
|
+
const x1 = cx - dx * cosTheta + dy * sinTheta;
|
|
180
|
+
const y1 = cy - dx * sinTheta - dy * cosTheta;
|
|
181
|
+
rotatedPoints.push([x1, y1]);
|
|
182
|
+
// Top-Right
|
|
183
|
+
const x2 = cx + dx * cosTheta + dy * sinTheta;
|
|
184
|
+
const y2 = cy + dx * sinTheta - dy * cosTheta;
|
|
185
|
+
rotatedPoints.push([x2, y2]);
|
|
186
|
+
// Bottom-Right
|
|
187
|
+
const x3 = cx + dx * cosTheta - dy * sinTheta;
|
|
188
|
+
const y3 = cy + dx * sinTheta + dy * cosTheta;
|
|
189
|
+
rotatedPoints.push([x3, y3]);
|
|
190
|
+
// Bottom-Left
|
|
191
|
+
const x4 = cx - dx * cosTheta - dy * sinTheta;
|
|
192
|
+
const y4 = cy - dx * sinTheta + dy * cosTheta;
|
|
193
|
+
rotatedPoints.push([x4, y4]);
|
|
194
|
+
return rotatedPoints;
|
|
195
|
+
}
|
|
196
|
+
function polygonPolygonArea(polygon) {
|
|
197
|
+
let i = -1, n = polygon.length, a, b = polygon[n - 1], area = 0;
|
|
198
|
+
while (++i < n) {
|
|
199
|
+
a = b;
|
|
200
|
+
b = polygon[i];
|
|
201
|
+
area += a[1] * b[0] - a[0] * b[1];
|
|
202
|
+
}
|
|
203
|
+
return area / 2;
|
|
204
|
+
}
|
|
205
|
+
function polygonPolygonLength(polygon) {
|
|
206
|
+
let i = -1, n = polygon.length, b = polygon[n - 1], xa, ya, xb = b[0], yb = b[1], perimeter = 0;
|
|
207
|
+
while (++i < n) {
|
|
208
|
+
xa = xb;
|
|
209
|
+
ya = yb;
|
|
210
|
+
b = polygon[i];
|
|
211
|
+
xb = b[0];
|
|
212
|
+
yb = b[1];
|
|
213
|
+
xa -= xb;
|
|
214
|
+
ya -= yb;
|
|
215
|
+
perimeter += Math.hypot(xa, ya);
|
|
216
|
+
}
|
|
217
|
+
return perimeter;
|
|
218
|
+
}
|
|
219
|
+
function flatten(arr) {
|
|
220
|
+
return arr
|
|
221
|
+
.toString()
|
|
222
|
+
.split(',')
|
|
223
|
+
.map((item) => +item);
|
|
224
|
+
}
|
|
225
|
+
function cvImread(image) {
|
|
226
|
+
return cv.matFromImageData(image);
|
|
227
|
+
}
|
|
228
|
+
function cvImshow(mat) {
|
|
229
|
+
return new ImageRaw({ data: mat.data, width: mat.cols, height: mat.rows });
|
|
230
|
+
}
|
|
231
|
+
//# sourceMappingURL=splitIntoLineImages.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"splitIntoLineImages.js","sourceRoot":"","sources":["../../src/backend/splitIntoLineImages.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,sBAAsB,CAAA;AACrC,OAAO,OAAO,MAAM,YAAY,CAAA;AAChC,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAA;AAO1C,MAAM,CAAC,KAAK,UAAU,mBAAmB,CAAC,KAAmB,EAAE,WAAyB;IACtF,MAAM,CAAC,GAAG,KAAK,CAAC,KAAK,CAAA;IACrB,MAAM,CAAC,GAAG,KAAK,CAAC,MAAM,CAAA;IACtB,MAAM,OAAO,GAAG,WAAW,CAAA;IAE3B,MAAM,QAAQ,GAA4C,EAAE,CAAA;IAE5D,MAAM,GAAG,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAA;IAE3B,EAAE,CAAC,QAAQ,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE,CAAC,eAAe,EAAE,CAAC,CAAC,CAAA;IAC5C,MAAM,QAAQ,GAAG,IAAI,EAAE,CAAC,SAAS,EAAE,CAAA;IACnC,MAAM,SAAS,GAAG,IAAI,EAAE,CAAC,GAAG,EAAE,CAAA;IAE9B,EAAE,CAAC,YAAY,CAAC,GAAG,EAAE,QAAQ,EAAE,SAAS,EAAE,EAAE,CAAC,SAAS,EAAE,EAAE,CAAC,mBAAmB,CAAC,CAAA;IAE/E,KAAK,IAAI,CAAC,GAAG,CAAC,EAA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AAgB,CAAC,KAAK,CAAC,CAAA;AACnC,CAAC;AAED,SAAS,QAAQ,CAAC,GAAW;IAC3B,OAAO,IAAI,QAAQ,CAAC,EAAE,IAAI,EAAE,GAAG,CAAC,IAAI,EAAE,KAAK,EAAE,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,CAAC,IAAI,EAAE,CAAC,CAAA;AAC5E,CAAC"}
|
package/build/index.d.ts
ADDED
package/build/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,OAAO,CAAA;AAE3B,eAAe,GAAG,CAAA;AAElB,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AACnD,cAAc,yBAAyB,CAAA;AACvC,cAAc,wBAAwB,CAAA"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { InferenceSession as InferenceSessionCommon } from 'onnxruntime-common';
|
|
2
|
+
import type { ImageRawData, BrowserImageInput, ModelCreateOptions } from '../types/index.js';
|
|
3
|
+
import { ModelBase } from './ModelBase.js';
|
|
4
|
+
export declare class Detection extends ModelBase {
|
|
5
|
+
static create({ models, onnxOptions, ...restOptions }: ModelCreateOptions): Promise<Detection>;
|
|
6
|
+
run(input: string | ImageRawData | BrowserImageInput, { onnxOptions }?: {
|
|
7
|
+
onnxOptions?: InferenceSessionCommon.RunOptions;
|
|
8
|
+
}): Promise<{
|
|
9
|
+
lineImages: import("../types/index.js").LineImage[];
|
|
10
|
+
resizedImageWidth: any;
|
|
11
|
+
resizedImageHeight: any;
|
|
12
|
+
}>;
|
|
13
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import invariant from 'tiny-invariant';
|
|
2
|
+
import { ImageRaw, InferenceSession, defaultModels, splitIntoLineImages } from '../backend/index.js';
|
|
3
|
+
import { ModelBase } from './ModelBase.js';
|
|
4
|
+
const BASE_SIZE = 32;
|
|
5
|
+
export class Detection extends ModelBase {
|
|
6
|
+
static async create({ models, onnxOptions = {}, ...restOptions }) {
|
|
7
|
+
const detectionPath = models?.detectionPath || defaultModels?.detectionPath;
|
|
8
|
+
invariant(detectionPath, 'detectionPath is required');
|
|
9
|
+
const model = await InferenceSession.create(detectionPath, onnxOptions);
|
|
10
|
+
return new Detection({ model, options: restOptions });
|
|
11
|
+
}
|
|
12
|
+
async run(input, { onnxOptions = {} } = {}) {
|
|
13
|
+
// Use ImageRaw.from() factory method if available (browser), otherwise fallback to legacy handling
|
|
14
|
+
const image = typeof ImageRaw.from === 'function'
|
|
15
|
+
? await ImageRaw.from(input)
|
|
16
|
+
: typeof input === "string"
|
|
17
|
+
? await ImageRaw.open(input)
|
|
18
|
+
: new ImageRaw(input);
|
|
19
|
+
// Resize image to multiple of 32
|
|
20
|
+
// - image width and height must be a multiple of 32
|
|
21
|
+
// - bigger image -> more accurate result, but takes longer time
|
|
22
|
+
// inputImage = await Image.resize(image, multipleOfBaseSize(image, { maxSize: 960 }))
|
|
23
|
+
const inputImage = await image.resize(multipleOfBaseSize(image));
|
|
24
|
+
this.debugImage(inputImage, 'out1-multiple-of-base-size.jpg');
|
|
25
|
+
// Covert image data to model data
|
|
26
|
+
// - Using `(RGB / 255 - mean) / std` formula
|
|
27
|
+
// - omit reshapeOptions (mean/std) is more accurate, can creaet a run option for them
|
|
28
|
+
const modelData = this.imageToInput(inputImage, {
|
|
29
|
+
// mean: [0.485, 0.456, 0.406],
|
|
30
|
+
// std: [0.229, 0.224, 0.225],
|
|
31
|
+
});
|
|
32
|
+
// Run the model
|
|
33
|
+
// console.time('Detection')
|
|
34
|
+
const modelOutput = await this.runModel({ modelData, onnxOptions });
|
|
35
|
+
// console.timeEnd('Detection')
|
|
36
|
+
// Convert output data back to image data
|
|
37
|
+
// - output value is from 0 to 1, a probability, if value > 0.3, it is a text
|
|
38
|
+
// - returns a black and white image
|
|
39
|
+
const outputImage = outputToImage(modelOutput, 0.03);
|
|
40
|
+
this.debugImage(outputImage, 'out2-black-white.jpg');
|
|
41
|
+
// Find text boxes, split image into lines
|
|
42
|
+
// - findContours from the image
|
|
43
|
+
// - returns text boxes and line images
|
|
44
|
+
const lineImages = await splitIntoLineImages(outputImage, inputImage);
|
|
45
|
+
this.debugBoxImage(inputImage, lineImages, 'boxes.jpg');
|
|
46
|
+
return {
|
|
47
|
+
lineImages,
|
|
48
|
+
resizedImageWidth: inputImage.width,
|
|
49
|
+
resizedImageHeight: inputImage.height,
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
function multipleOfBaseSize(image, { maxSize } = {}) {
|
|
54
|
+
let width = image.width;
|
|
55
|
+
let height = image.height;
|
|
56
|
+
if (maxSize && Math.max(width, height) > maxSize) {
|
|
57
|
+
const ratio = width > height ? maxSize / width : maxSize / height;
|
|
58
|
+
width = width * ratio;
|
|
59
|
+
height = height * ratio;
|
|
60
|
+
}
|
|
61
|
+
const newWidth = Math.max(
|
|
62
|
+
// Math.round
|
|
63
|
+
// Math.ceil
|
|
64
|
+
Math.ceil(width / BASE_SIZE) * BASE_SIZE, BASE_SIZE);
|
|
65
|
+
const newHeight = Math.max(Math.ceil(height / BASE_SIZE) * BASE_SIZE, BASE_SIZE);
|
|
66
|
+
return { width: newWidth, height: newHeight };
|
|
67
|
+
}
|
|
68
|
+
function outputToImage(output, threshold) {
|
|
69
|
+
const height = output.dims[2];
|
|
70
|
+
const width = output.dims[3];
|
|
71
|
+
const data = new Uint8Array(width * height * 4);
|
|
72
|
+
for (const [outIndex, outValue] of output.data.entries()) {
|
|
73
|
+
const n = outIndex * 4;
|
|
74
|
+
const value = outValue > threshold ? 255 : 0;
|
|
75
|
+
data[n] = value; // R
|
|
76
|
+
data[n + 1] = value; // G
|
|
77
|
+
data[n + 2] = value; // B
|
|
78
|
+
data[n + 3] = 255; // A
|
|
79
|
+
}
|
|
80
|
+
return new ImageRaw({ data, width, height });
|
|
81
|
+
}
|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C,CAAC,GAAG,CAAC,CAAC,GAAG,KAAK,CAAA,CAAC,IAAI;QACxB,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,GAAG,CAAA,CAAC,IAAI;IACxB,CAAC;IACD,OAAO,IAAI,QAAQ,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC,CAAA;AAC9C,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type InferenceSession as InferenceSessionCommon, Tensor } from 'onnxruntime-common';
|
|
2
|
+
import type { ImageRaw, LineImage, ModelBaseConstructorArg, ModelBaseOptions, ModelData, ReshapeOptions } from '../types/index.js';
|
|
3
|
+
export declare class ModelBase {
|
|
4
|
+
#private;
|
|
5
|
+
options: ModelBaseOptions;
|
|
6
|
+
constructor({ model, options }: ModelBaseConstructorArg);
|
|
7
|
+
runModel({ modelData, onnxOptions, }: {
|
|
8
|
+
modelData: ModelData;
|
|
9
|
+
onnxOptions?: InferenceSessionCommon.RunOptions;
|
|
10
|
+
}): Promise<Tensor>;
|
|
11
|
+
imageToInput(image: ImageRaw, { mean, std }: ReshapeOptions): ModelData;
|
|
12
|
+
debugImage(image: ImageRaw | any, path: string): void;
|
|
13
|
+
debugBoxImage(sourceImage: ImageRaw | any, lineImages: LineImage[], path: string): Promise<void>;
|
|
14
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { Tensor } from 'onnxruntime-common';
|
|
2
|
+
export class ModelBase {
|
|
3
|
+
options;
|
|
4
|
+
#model;
|
|
5
|
+
constructor({ model, options }) {
|
|
6
|
+
this.#model = model;
|
|
7
|
+
this.options = options;
|
|
8
|
+
}
|
|
9
|
+
async runModel({ modelData, onnxOptions = {}, }) {
|
|
10
|
+
const input = this.#prepareInput(modelData);
|
|
11
|
+
const outputs = await this.#model.run({
|
|
12
|
+
[this.#model.inputNames[0]]: input,
|
|
13
|
+
}, onnxOptions);
|
|
14
|
+
const output = outputs[this.#model.outputNames[0]];
|
|
15
|
+
return output;
|
|
16
|
+
}
|
|
17
|
+
#prepareInput(modelData) {
|
|
18
|
+
const input = Float32Array.from(modelData.data);
|
|
19
|
+
return new Tensor('float32', input, [1, 3, modelData.height, modelData.width]);
|
|
20
|
+
}
|
|
21
|
+
imageToInput(image, { mean = [0, 0, 0], std = [1, 1, 1] }) {
|
|
22
|
+
const R = [];
|
|
23
|
+
const G = [];
|
|
24
|
+
const B = [];
|
|
25
|
+
for (let i = 0; i < image.data.length; i += 4) {
|
|
26
|
+
R.push((image.data[i] / 255 - mean[0]) / std[0]);
|
|
27
|
+
G.push((image.data[i + 1] / 255 - mean[1]) / std[1]);
|
|
28
|
+
B.push((image.data[i + 2] / 255 - mean[2]) / std[2]);
|
|
29
|
+
}
|
|
30
|
+
const newData = [...B, ...G, ...R];
|
|
31
|
+
return {
|
|
32
|
+
data: newData,
|
|
33
|
+
width: image.width,
|
|
34
|
+
height: image.height,
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
debugImage(image, path) {
|
|
38
|
+
const { debugOutputDir, isDebug } = this.options;
|
|
39
|
+
if (!isDebug || !debugOutputDir) {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
image.write(`${debugOutputDir}/${path}`);
|
|
43
|
+
}
|
|
44
|
+
async debugBoxImage(sourceImage, lineImages, path) {
|
|
45
|
+
const { debugOutputDir, isDebug } = this.options;
|
|
46
|
+
if (!isDebug || !debugOutputDir) {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
const boxImage = await sourceImage.drawBox(lineImages);
|
|
50
|
+
boxImage.write(`${debugOutputDir}/${path}`);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=ModelBase.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ModelBase.js","sourceRoot":"","sources":["../../src/models/ModelBase.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmD,MAAM,EAAE,MAAM,oBAAoB,CAAA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AI,CAAC,cAAc,EAAE,CAAC;YAChC,OAAM;QACR,CAAC;QACD,MAAM,QAAQ,GAAG,MAAM,WAAW,CAAC,OAAO,CAAC,UAAU,CAAC,CAAA;QACtD,QAAQ,CAAC,KAAK,CAAC,GAAG,cAAc,IAAI,IAAI,EAAE,CAAC,CAAA;IAC7C,CAAC;CACF"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { InferenceSession as InferenceSessionCommon, Tensor } from 'onnxruntime-common';
|
|
2
|
+
import type { Dictionary, Line, LineImage, ModelBaseConstructorArg, ModelCreateOptions } from '../types/index.js';
|
|
3
|
+
import { ModelBase } from './ModelBase.js';
|
|
4
|
+
export declare class Recognition extends ModelBase {
|
|
5
|
+
#private;
|
|
6
|
+
static create({ models, onnxOptions, ...restOptions }: ModelCreateOptions): Promise<Recognition>;
|
|
7
|
+
constructor(options: ModelBaseConstructorArg, dictionary: Dictionary);
|
|
8
|
+
run(lineImages: LineImage[], { onnxOptions }?: {
|
|
9
|
+
onnxOptions?: InferenceSessionCommon.RunOptions;
|
|
10
|
+
}): Promise<Line[]>;
|
|
11
|
+
decodeText(output: Tensor): Line[];
|
|
12
|
+
}
|