mindee 4.1.1 → 4.3.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/CHANGELOG.md +19 -0
- package/README.md +4 -1
- package/package.json +1 -1
- package/src/client.js +2 -8
- package/src/geometry/boundingBox.d.ts +7 -1
- package/src/geometry/boundingBox.js +11 -0
- package/src/geometry/boundingBoxUtils.d.ts +2 -2
- package/src/geometry/boundingBoxUtils.js +11 -28
- package/src/geometry/index.js +3 -1
- package/src/http/error.d.ts +1 -1
- package/src/http/error.js +2 -2
- package/src/parsing/common/inference.js +1 -2
- package/src/parsing/custom/index.d.ts +1 -1
- package/src/parsing/custom/index.js +2 -3
- package/src/parsing/custom/lineItems.d.ts +3 -16
- package/src/parsing/custom/lineItems.js +29 -37
- package/src/parsing/standard/base.d.ts +2 -2
- package/src/parsing/standard/base.js +2 -2
- package/src/parsing/standard/field.d.ts +10 -10
- package/src/parsing/standard/field.js +10 -10
- package/src/parsing/standard/position.js +12 -1
- package/src/product/barcodeReader/barcodeReaderV1.d.ts +16 -0
- package/src/product/barcodeReader/barcodeReaderV1.js +22 -0
- package/src/product/barcodeReader/barcodeReaderV1Document.d.ts +16 -0
- package/src/product/barcodeReader/barcodeReaderV1Document.js +37 -0
- package/src/product/barcodeReader/internal.d.ts +2 -0
- package/src/product/barcodeReader/internal.js +7 -0
- package/src/product/cropper/cropperV1.d.ts +4 -3
- package/src/product/cropper/cropperV1.js +4 -3
- package/src/product/cropper/cropperV1Document.d.ts +2 -6
- package/src/product/cropper/cropperV1Document.js +2 -19
- package/src/product/cropper/cropperV1Page.d.ts +12 -0
- package/src/product/cropper/cropperV1Page.js +26 -0
- package/src/product/cropper/internal.d.ts +1 -0
- package/src/product/cropper/internal.js +3 -1
- package/src/product/custom/customV1Document.d.ts +8 -1
- package/src/product/custom/customV1Document.js +9 -0
- package/src/product/custom/customV1Page.d.ts +8 -1
- package/src/product/custom/customV1Page.js +9 -0
- package/src/product/fr/carteVitale/carteVitaleV1Document.js +1 -1
- package/src/product/fr/idCard/idCardV1Document.js +1 -1
- package/src/product/fr/idCard/idCardV2.d.ts +17 -0
- package/src/product/fr/idCard/idCardV2.js +23 -0
- package/src/product/fr/idCard/idCardV2Document.d.ts +42 -0
- package/src/product/fr/idCard/idCardV2Document.js +98 -0
- package/src/product/fr/idCard/idCardV2Page.d.ts +14 -0
- package/src/product/fr/idCard/idCardV2Page.js +27 -0
- package/src/product/fr/idCard/internal.d.ts +1 -0
- package/src/product/fr/idCard/internal.js +3 -1
- package/src/product/fr/index.d.ts +1 -0
- package/src/product/fr/index.js +3 -1
- package/src/product/index.d.ts +8 -6
- package/src/product/index.js +16 -12
- package/src/product/internal.d.ts +2 -0
- package/src/product/internal.js +3 -1
- package/src/product/multiReceiptsDetector/internal.d.ts +2 -0
- package/src/product/multiReceiptsDetector/internal.js +7 -0
- package/src/product/multiReceiptsDetector/multiReceiptsDetectorV1.d.ts +16 -0
- package/src/product/multiReceiptsDetector/multiReceiptsDetectorV1.js +22 -0
- package/src/product/multiReceiptsDetector/multiReceiptsDetectorV1Document.d.ts +14 -0
- package/src/product/multiReceiptsDetector/multiReceiptsDetectorV1Document.js +28 -0
- package/src/product/passport/passportV1Document.js +1 -1
- package/src/product/proofOfAddress/proofOfAddressV1Document.js +2 -2
- package/src/product/us/bankCheck/bankCheckV1Page.js +1 -1
- package/src/product/us/index.d.ts +1 -0
- package/src/product/us/index.js +3 -1
- package/src/product/us/w9/internal.d.ts +3 -0
- package/src/product/us/w9/internal.js +9 -0
- package/src/product/us/w9/w9V1.d.ts +17 -0
- package/src/product/us/w9/w9V1.js +23 -0
- package/src/product/us/w9/w9V1Document.d.ts +10 -0
- package/src/product/us/w9/w9V1Document.js +15 -0
- package/src/product/us/w9/w9V1Page.d.ts +34 -0
- package/src/product/us/w9/w9V1Page.js +78 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,24 @@
|
|
|
1
1
|
# CHANGELOG
|
|
2
2
|
|
|
3
|
+
## v4.3.0 - 2023-09-19
|
|
4
|
+
### Changes
|
|
5
|
+
* :sparkles: add line items reconstruction for API builder
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
## v4.2.0 - 2023-09-15
|
|
9
|
+
### Changes
|
|
10
|
+
* :sparkles: add support for W9 V1
|
|
11
|
+
* :sparkles: add support for Barcode Reader V11
|
|
12
|
+
* :sparkles: add support for Multi Receipt Detector V1
|
|
13
|
+
* :sparkles: add support for FR Id Card V2
|
|
14
|
+
* :sparkles: add support for OTS Cropper V1
|
|
15
|
+
* :memo: update documentation
|
|
16
|
+
|
|
17
|
+
### Fixes
|
|
18
|
+
* :bug: fix missing position field display issues
|
|
19
|
+
* :bug: fix issues with asynchronous timeouts crashing in some instances
|
|
20
|
+
|
|
21
|
+
|
|
3
22
|
## v4.1.1 - 2023-09-04
|
|
4
23
|
### Changes
|
|
5
24
|
* :recycle: tweaked timer management in async
|
package/README.md
CHANGED
|
@@ -155,9 +155,12 @@ Complete details on the working of the library are available in the following gu
|
|
|
155
155
|
* [Node.js FR Carte Vitale OCR](https://developers.mindee.com/docs/nodejs-fr-carte-vitale-ocr)
|
|
156
156
|
* [Node.js FR ID Card OCR](https://developers.mindee.com/docs/nodejs-fr-id-card-ocr)
|
|
157
157
|
* [Node.js US Bank Check OCR](https://developers.mindee.com/docs/nodejs-us-bank-checks-ocr)
|
|
158
|
-
* [Node.js US
|
|
158
|
+
* [Node.js US W9 OCR](https://developers.mindee.com/docs/nodejs-us-driver-license-ocr)
|
|
159
|
+
* [Node.js US Driver License OCR](https://developers.mindee.com/docs/nodejs-us-w9-ocr)
|
|
160
|
+
* [Node.js Barcode Reader API](https://developers.mindee.com/docs/nodejs-barcode-reader-api)
|
|
159
161
|
* [Node.js Cropper API](https://developers.mindee.com/docs/nodejs-cropper-api)
|
|
160
162
|
* [Node.js Invoice Splitter API](https://developers.mindee.com/docs/nodejs-invoice-splitter-api)
|
|
163
|
+
* [Node.js Multi Receipts Detector API](https://developers.mindee.com/docs/nodejs-multi-receipts-detector-api)
|
|
161
164
|
|
|
162
165
|
You can also take a look at the **[Reference Documentation](https://mindee.github.io/mindee-api-nodejs/)**.
|
|
163
166
|
|
package/package.json
CHANGED
package/src/client.js
CHANGED
|
@@ -122,14 +122,8 @@ class Client {
|
|
|
122
122
|
initialDelaySec: 6,
|
|
123
123
|
delaySec: 3,
|
|
124
124
|
maxRetries: 10,
|
|
125
|
-
initialTimerOptions:
|
|
126
|
-
|
|
127
|
-
signal: undefined,
|
|
128
|
-
},
|
|
129
|
-
recurringTimerOptions: {
|
|
130
|
-
ref: false,
|
|
131
|
-
signal: undefined,
|
|
132
|
-
},
|
|
125
|
+
initialTimerOptions: undefined,
|
|
126
|
+
recurringTimerOptions: undefined,
|
|
133
127
|
}) {
|
|
134
128
|
__classPrivateFieldGet(this, _Client_instances, "m", _Client_validateAsyncParams).call(this, asyncParams);
|
|
135
129
|
const enqueueResponse = await this.enqueue(productClass, inputSource, asyncParams);
|
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
import { Point } from "./point";
|
|
2
2
|
/** A simple bounding box defined by 4 coordinates: xMin, yMin, xMax, yMax */
|
|
3
|
-
export
|
|
3
|
+
export declare class BBox {
|
|
4
|
+
xMin: number;
|
|
5
|
+
yMin: number;
|
|
6
|
+
xMax: number;
|
|
7
|
+
yMax: number;
|
|
8
|
+
constructor(xMin: number, yMin: number, xMax: number, yMax: number);
|
|
9
|
+
}
|
|
4
10
|
/** A bounding box defined by 4 points. */
|
|
5
11
|
export type BoundingBox = [Point, Point, Point, Point];
|
|
@@ -1,2 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BBox = void 0;
|
|
4
|
+
/** A simple bounding box defined by 4 coordinates: xMin, yMin, xMax, yMax */
|
|
5
|
+
class BBox {
|
|
6
|
+
constructor(xMin, yMin, xMax, yMax) {
|
|
7
|
+
this.xMin = xMin;
|
|
8
|
+
this.yMin = yMin;
|
|
9
|
+
this.xMax = xMax;
|
|
10
|
+
this.yMax = yMax;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
exports.BBox = BBox;
|
|
@@ -13,10 +13,10 @@ export declare function getBoundingBoxFromBBox(bbox: BBox): BoundingBox;
|
|
|
13
13
|
*/
|
|
14
14
|
export declare function mergeBbox(bbox1: BBox, bbox2: BBox): BBox;
|
|
15
15
|
/**
|
|
16
|
-
* Given a Polygon, calculate a
|
|
16
|
+
* Given a Polygon, calculate a BBox that encompasses all points.
|
|
17
17
|
*/
|
|
18
18
|
export declare function getBbox(polygon: Polygon): BBox;
|
|
19
19
|
/**
|
|
20
|
-
* Given polygons, calculate a
|
|
20
|
+
* Given polygons, calculate a BBox that encompasses all points.
|
|
21
21
|
*/
|
|
22
22
|
export declare function getBBoxForPolygons(polygons: Polygon[]): BBox;
|
|
@@ -1,17 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getBBoxForPolygons = exports.getBbox = exports.mergeBbox = exports.getBoundingBoxFromBBox = exports.getBoundingBox = void 0;
|
|
4
|
+
const boundingBox_1 = require("./boundingBox");
|
|
4
5
|
/**
|
|
5
6
|
* Given a Polygon, calculate a polygon that encompasses all points.
|
|
6
7
|
*/
|
|
7
8
|
function getBoundingBox(polygon) {
|
|
8
9
|
const bbox = getBbox(polygon);
|
|
9
|
-
return
|
|
10
|
-
[bbox[0], bbox[1]],
|
|
11
|
-
[bbox[2], bbox[1]],
|
|
12
|
-
[bbox[2], bbox[3]],
|
|
13
|
-
[bbox[0], bbox[3]],
|
|
14
|
-
];
|
|
10
|
+
return getBoundingBoxFromBBox(bbox);
|
|
15
11
|
}
|
|
16
12
|
exports.getBoundingBox = getBoundingBox;
|
|
17
13
|
/**
|
|
@@ -19,10 +15,10 @@ exports.getBoundingBox = getBoundingBox;
|
|
|
19
15
|
*/
|
|
20
16
|
function getBoundingBoxFromBBox(bbox) {
|
|
21
17
|
return [
|
|
22
|
-
[bbox
|
|
23
|
-
[bbox
|
|
24
|
-
[bbox
|
|
25
|
-
[bbox
|
|
18
|
+
[bbox.xMin, bbox.yMin],
|
|
19
|
+
[bbox.xMax, bbox.yMin],
|
|
20
|
+
[bbox.xMax, bbox.yMax],
|
|
21
|
+
[bbox.xMin, bbox.yMax],
|
|
26
22
|
];
|
|
27
23
|
}
|
|
28
24
|
exports.getBoundingBoxFromBBox = getBoundingBoxFromBBox;
|
|
@@ -30,37 +26,24 @@ exports.getBoundingBoxFromBBox = getBoundingBoxFromBBox;
|
|
|
30
26
|
* Given 2 bbox, merge them.
|
|
31
27
|
*/
|
|
32
28
|
function mergeBbox(bbox1, bbox2) {
|
|
33
|
-
return
|
|
34
|
-
Math.min(bbox1[0], bbox2[0]),
|
|
35
|
-
Math.min(bbox1[1], bbox2[1]),
|
|
36
|
-
Math.max(bbox1[2], bbox2[2]),
|
|
37
|
-
Math.max(bbox1[3], bbox2[3]),
|
|
38
|
-
];
|
|
29
|
+
return new boundingBox_1.BBox(Math.min(bbox1.xMin, bbox2.xMin), Math.min(bbox1.yMin, bbox2.yMin), Math.max(bbox1.xMax, bbox2.xMax), Math.max(bbox1.yMax, bbox2.yMax));
|
|
39
30
|
}
|
|
40
31
|
exports.mergeBbox = mergeBbox;
|
|
41
32
|
/**
|
|
42
|
-
* Given a Polygon, calculate a
|
|
33
|
+
* Given a Polygon, calculate a BBox that encompasses all points.
|
|
43
34
|
*/
|
|
44
35
|
function getBbox(polygon) {
|
|
45
36
|
const allY = polygon.map((point) => point[1]);
|
|
46
37
|
const allX = polygon.map((point) => point[0]);
|
|
47
|
-
|
|
48
|
-
const yMax = Math.max(...allY);
|
|
49
|
-
const xMin = Math.min(...allX);
|
|
50
|
-
const xMax = Math.max(...allX);
|
|
51
|
-
return [xMin, yMin, xMax, yMax];
|
|
38
|
+
return new boundingBox_1.BBox(Math.min(...allX), Math.min(...allY), Math.max(...allX), Math.max(...allY));
|
|
52
39
|
}
|
|
53
40
|
exports.getBbox = getBbox;
|
|
54
41
|
/**
|
|
55
|
-
* Given polygons, calculate a
|
|
42
|
+
* Given polygons, calculate a BBox that encompasses all points.
|
|
56
43
|
*/
|
|
57
44
|
function getBBoxForPolygons(polygons) {
|
|
58
45
|
const allY = polygons.flatMap((polygon) => polygon.map((point) => point[1]));
|
|
59
46
|
const allX = polygons.flatMap((polygon) => polygon.map((point) => point[0]));
|
|
60
|
-
|
|
61
|
-
const yMax = Math.max(...allY);
|
|
62
|
-
const xMin = Math.min(...allX);
|
|
63
|
-
const xMax = Math.max(...allX);
|
|
64
|
-
return [xMin, yMin, xMax, yMax];
|
|
47
|
+
return new boundingBox_1.BBox(Math.min(...allX), Math.min(...allY), Math.max(...allX), Math.max(...allY));
|
|
65
48
|
}
|
|
66
49
|
exports.getBBoxForPolygons = getBBoxForPolygons;
|
package/src/geometry/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.mergeBbox = exports.getBoundingBoxFromBBox = exports.getBoundingBox = exports.getBBoxForPolygons = exports.getBbox = exports.getMinMaxY = exports.getMinMaxX = exports.relativeY = exports.relativeX = exports.isPointInPolygonY = exports.isPointInPolygonX = exports.getCentroid = exports.compareOnY = exports.compareOnX = exports.Polygon = void 0;
|
|
3
|
+
exports.mergeBbox = exports.getBoundingBoxFromBBox = exports.getBoundingBox = exports.getBBoxForPolygons = exports.getBbox = exports.BBox = exports.getMinMaxY = exports.getMinMaxX = exports.relativeY = exports.relativeX = exports.isPointInPolygonY = exports.isPointInPolygonX = exports.getCentroid = exports.compareOnY = exports.compareOnX = exports.Polygon = void 0;
|
|
4
4
|
var polygon_1 = require("./polygon");
|
|
5
5
|
Object.defineProperty(exports, "Polygon", { enumerable: true, get: function () { return polygon_1.Polygon; } });
|
|
6
6
|
var polygonUtils_1 = require("./polygonUtils");
|
|
@@ -13,6 +13,8 @@ Object.defineProperty(exports, "relativeX", { enumerable: true, get: function ()
|
|
|
13
13
|
Object.defineProperty(exports, "relativeY", { enumerable: true, get: function () { return polygonUtils_1.relativeY; } });
|
|
14
14
|
Object.defineProperty(exports, "getMinMaxX", { enumerable: true, get: function () { return polygonUtils_1.getMinMaxX; } });
|
|
15
15
|
Object.defineProperty(exports, "getMinMaxY", { enumerable: true, get: function () { return polygonUtils_1.getMinMaxY; } });
|
|
16
|
+
var boundingBox_1 = require("./boundingBox");
|
|
17
|
+
Object.defineProperty(exports, "BBox", { enumerable: true, get: function () { return boundingBox_1.BBox; } });
|
|
16
18
|
var boundingBoxUtils_1 = require("./boundingBoxUtils");
|
|
17
19
|
Object.defineProperty(exports, "getBbox", { enumerable: true, get: function () { return boundingBoxUtils_1.getBbox; } });
|
|
18
20
|
Object.defineProperty(exports, "getBBoxForPolygons", { enumerable: true, get: function () { return boundingBoxUtils_1.getBBoxForPolygons; } });
|
package/src/http/error.d.ts
CHANGED
|
@@ -46,7 +46,7 @@ export declare class MindeeHttp413Error extends MindeeHttpError {
|
|
|
46
46
|
constructor(httpError: StringDict, url: string, code?: number);
|
|
47
47
|
}
|
|
48
48
|
/**
|
|
49
|
-
* Usually
|
|
49
|
+
* Usually corresponds to TooManyRequests errors.
|
|
50
50
|
* Arises whenever too many calls to the API are made in quick succession.
|
|
51
51
|
*/
|
|
52
52
|
export declare class MindeeHttp429Error extends MindeeHttpError {
|
package/src/http/error.js
CHANGED
|
@@ -168,7 +168,7 @@ class MindeeHttp413Error extends MindeeHttpError {
|
|
|
168
168
|
}
|
|
169
169
|
exports.MindeeHttp413Error = MindeeHttp413Error;
|
|
170
170
|
/**
|
|
171
|
-
* Usually
|
|
171
|
+
* Usually corresponds to TooManyRequests errors.
|
|
172
172
|
* Arises whenever too many calls to the API are made in quick succession.
|
|
173
173
|
*/
|
|
174
174
|
class MindeeHttp429Error extends MindeeHttpError {
|
|
@@ -195,7 +195,7 @@ exports.MindeeHttp500Error = MindeeHttp500Error;
|
|
|
195
195
|
class MindeeHttp504Error extends MindeeHttpError {
|
|
196
196
|
constructor(httpError, url, code) {
|
|
197
197
|
super(httpError, url, code);
|
|
198
|
-
this.name = "
|
|
198
|
+
this.name = "MindeeHttp504Error";
|
|
199
199
|
}
|
|
200
200
|
}
|
|
201
201
|
exports.MindeeHttp504Error = MindeeHttp504Error;
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ListFieldValue = exports.ListField = exports.ClassificationField = exports.getLineItems = exports.
|
|
3
|
+
exports.ListFieldValue = exports.ListField = exports.ClassificationField = exports.getLineItems = exports.CustomLine = void 0;
|
|
4
4
|
var lineItems_1 = require("./lineItems");
|
|
5
|
-
Object.defineProperty(exports, "
|
|
6
|
-
Object.defineProperty(exports, "LineItems", { enumerable: true, get: function () { return lineItems_1.LineItems; } });
|
|
5
|
+
Object.defineProperty(exports, "CustomLine", { enumerable: true, get: function () { return lineItems_1.CustomLine; } });
|
|
7
6
|
Object.defineProperty(exports, "getLineItems", { enumerable: true, get: function () { return lineItems_1.getLineItems; } });
|
|
8
7
|
var classificationField_1 = require("./classificationField");
|
|
9
8
|
Object.defineProperty(exports, "ClassificationField", { enumerable: true, get: function () { return classificationField_1.ClassificationField; } });
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { BBox, Polygon } from "../../geometry";
|
|
2
2
|
import { ListField, ListFieldValue } from "./listField";
|
|
3
|
-
export declare class
|
|
3
|
+
export declare class CustomLine {
|
|
4
4
|
/**
|
|
5
5
|
* Number of the current line.
|
|
6
6
|
* Starts at 1.
|
|
@@ -14,12 +14,7 @@ export declare class Line {
|
|
|
14
14
|
* The BBox of the current line.
|
|
15
15
|
*/
|
|
16
16
|
bbox: BBox;
|
|
17
|
-
|
|
18
|
-
* The height tolerance used to build the line.
|
|
19
|
-
* It helps when the height of a line can vary unexpectedly.
|
|
20
|
-
*/
|
|
21
|
-
heightTolerance: number;
|
|
22
|
-
constructor(rowNumber: number, heightTolerance: number);
|
|
17
|
+
constructor(rowNumber: number);
|
|
23
18
|
/**
|
|
24
19
|
* Extends the current bbox of the line with the bbox.
|
|
25
20
|
*/
|
|
@@ -28,14 +23,6 @@ export declare class Line {
|
|
|
28
23
|
* Extends the current bbox of the line with the polygon.
|
|
29
24
|
*/
|
|
30
25
|
extendWith(polygon: Polygon): void;
|
|
31
|
-
/**
|
|
32
|
-
* Check if the bbox fits the current line.
|
|
33
|
-
*/
|
|
34
|
-
contains(bbox: BBox): boolean;
|
|
35
26
|
updateField(name: string, fieldValue: ListFieldValue): void;
|
|
36
27
|
}
|
|
37
|
-
export declare
|
|
38
|
-
rows: Line[];
|
|
39
|
-
constructor(lines: Line[]);
|
|
40
|
-
}
|
|
41
|
-
export declare function getLineItems(anchorNames: string[], heightLineTolerance: number, fieldNamesTargeted: string[], fields: Map<string, ListField>): LineItems;
|
|
28
|
+
export declare function getLineItems(anchorNames: string[], fieldNames: string[], fields: Map<string, ListField>, heightLineTolerance: number): CustomLine[];
|
|
@@ -1,16 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getLineItems = exports.
|
|
3
|
+
exports.getLineItems = exports.CustomLine = void 0;
|
|
4
4
|
const handler_1 = require("../../errors/handler");
|
|
5
5
|
const errors_1 = require("../../errors");
|
|
6
6
|
const geometry_1 = require("../../geometry");
|
|
7
7
|
const listField_1 = require("./listField");
|
|
8
|
-
class
|
|
9
|
-
constructor(rowNumber
|
|
8
|
+
class CustomLine {
|
|
9
|
+
constructor(rowNumber) {
|
|
10
10
|
this.rowNumber = rowNumber;
|
|
11
|
-
this.bbox =
|
|
11
|
+
this.bbox = new geometry_1.BBox(1, 1, 0, 0);
|
|
12
12
|
this.fields = new Map();
|
|
13
|
-
this.heightTolerance = heightTolerance;
|
|
14
13
|
}
|
|
15
14
|
/**
|
|
16
15
|
* Extends the current bbox of the line with the bbox.
|
|
@@ -24,15 +23,6 @@ class Line {
|
|
|
24
23
|
extendWith(polygon) {
|
|
25
24
|
this.bbox = (0, geometry_1.mergeBbox)(this.bbox, (0, geometry_1.getBbox)(polygon));
|
|
26
25
|
}
|
|
27
|
-
/**
|
|
28
|
-
* Check if the bbox fits the current line.
|
|
29
|
-
*/
|
|
30
|
-
contains(bbox) {
|
|
31
|
-
if (Math.abs(bbox[1] - this.bbox[1]) <= this.heightTolerance) {
|
|
32
|
-
return true;
|
|
33
|
-
}
|
|
34
|
-
return Math.abs(this.bbox[1] - bbox[1]) <= this.heightTolerance;
|
|
35
|
-
}
|
|
36
26
|
updateField(name, fieldValue) {
|
|
37
27
|
if (!this.fields.has(name)) {
|
|
38
28
|
this.fields.set(name, fieldValue);
|
|
@@ -58,30 +48,23 @@ class Line {
|
|
|
58
48
|
}
|
|
59
49
|
}
|
|
60
50
|
}
|
|
61
|
-
exports.
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
this.rows = [];
|
|
65
|
-
this.rows = lines;
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
exports.LineItems = LineItems;
|
|
69
|
-
function getLineItems(anchorNames, heightLineTolerance, fieldNamesTargeted, fields) {
|
|
70
|
-
const fieldsToTransformIntoLines = new Map([...fields].filter(([k]) => fieldNamesTargeted.includes(k)));
|
|
51
|
+
exports.CustomLine = CustomLine;
|
|
52
|
+
function getLineItems(anchorNames, fieldNames, fields, heightLineTolerance) {
|
|
53
|
+
const fieldsToTransformIntoLines = new Map([...fields].filter(([k]) => fieldNames.includes(k)));
|
|
71
54
|
const anchorName = findBestAnchor(anchorNames, fieldsToTransformIntoLines);
|
|
72
|
-
const
|
|
73
|
-
|
|
55
|
+
const linesPrepared = prepare(anchorName, fieldsToTransformIntoLines, heightLineTolerance);
|
|
56
|
+
linesPrepared.forEach((currentLine) => {
|
|
74
57
|
fieldsToTransformIntoLines.forEach((field, fieldName) => {
|
|
75
58
|
field.values.forEach((listFieldValue) => {
|
|
76
59
|
const minYCurrentValue = (0, geometry_1.getMinMaxY)(listFieldValue.polygon).min;
|
|
77
|
-
if (minYCurrentValue < currentLine.bbox
|
|
78
|
-
minYCurrentValue >= currentLine.bbox
|
|
60
|
+
if (minYCurrentValue < currentLine.bbox.yMax &&
|
|
61
|
+
minYCurrentValue >= currentLine.bbox.yMin) {
|
|
79
62
|
currentLine.updateField(fieldName, listFieldValue);
|
|
80
63
|
}
|
|
81
64
|
});
|
|
82
65
|
});
|
|
83
66
|
});
|
|
84
|
-
return
|
|
67
|
+
return linesPrepared;
|
|
85
68
|
}
|
|
86
69
|
exports.getLineItems = getLineItems;
|
|
87
70
|
function findBestAnchor(possibleAnchorNames, fields) {
|
|
@@ -99,31 +82,40 @@ function findBestAnchor(possibleAnchorNames, fields) {
|
|
|
99
82
|
}
|
|
100
83
|
return anchorName;
|
|
101
84
|
}
|
|
85
|
+
/**
|
|
86
|
+
* Check if the bbox fits inside the line.
|
|
87
|
+
*/
|
|
88
|
+
function isBboxInLine(line, bbox, heightTolerance) {
|
|
89
|
+
if (Math.abs(bbox.yMin - line.bbox.yMin) <= heightTolerance) {
|
|
90
|
+
return true;
|
|
91
|
+
}
|
|
92
|
+
return Math.abs(line.bbox.yMin - bbox.yMin) <= heightTolerance;
|
|
93
|
+
}
|
|
102
94
|
function prepare(anchorName, fields, heightLineTolerance) {
|
|
103
|
-
const
|
|
95
|
+
const linesPrepared = [];
|
|
104
96
|
const anchorField = fields.get(anchorName);
|
|
105
97
|
if (anchorField === undefined || anchorField.values.length === 0) {
|
|
106
98
|
handler_1.errorHandler.throw(new errors_1.MindeeError("No lines have been detected."));
|
|
107
99
|
}
|
|
108
100
|
let currentLineNumber = 1;
|
|
109
|
-
let currentLine = new
|
|
101
|
+
let currentLine = new CustomLine(currentLineNumber);
|
|
110
102
|
if (anchorField !== undefined) {
|
|
111
103
|
let currentValue = anchorField.values[0];
|
|
112
104
|
currentLine.extendWith(currentValue.polygon);
|
|
113
105
|
for (let index = 1; index < anchorField.values.length; index++) {
|
|
114
106
|
currentValue = anchorField.values[index];
|
|
115
107
|
const currentFieldBbox = (0, geometry_1.getBbox)(currentValue.polygon);
|
|
116
|
-
if (!currentLine
|
|
117
|
-
|
|
108
|
+
if (!isBboxInLine(currentLine, currentFieldBbox, heightLineTolerance)) {
|
|
109
|
+
linesPrepared.push(currentLine);
|
|
118
110
|
currentLineNumber++;
|
|
119
|
-
currentLine = new
|
|
111
|
+
currentLine = new CustomLine(currentLineNumber);
|
|
120
112
|
}
|
|
121
113
|
currentLine.extendWithBbox(currentFieldBbox);
|
|
122
114
|
}
|
|
123
|
-
if (
|
|
115
|
+
if (linesPrepared.filter((line) => line.rowNumber === currentLineNumber)
|
|
124
116
|
.length === 0) {
|
|
125
|
-
|
|
117
|
+
linesPrepared.push(currentLine);
|
|
126
118
|
}
|
|
127
119
|
}
|
|
128
|
-
return
|
|
120
|
+
return linesPrepared;
|
|
129
121
|
}
|
|
@@ -16,8 +16,8 @@ export declare class BaseField {
|
|
|
16
16
|
pageId?: number;
|
|
17
17
|
/**
|
|
18
18
|
* @param {Object} prediction - Prediction object from HTTP response
|
|
19
|
-
* @param
|
|
20
|
-
* @param
|
|
19
|
+
* @param valueKey - Key to use in the prediction dict
|
|
20
|
+
* @param reconstructed - Is the object reconstructed (not extracted by the API)
|
|
21
21
|
*/
|
|
22
22
|
constructor({ prediction, valueKey, reconstructed, pageId, }: BaseFieldConstructor);
|
|
23
23
|
compare(other: BaseField): boolean;
|
|
@@ -7,8 +7,8 @@ exports.BaseField = void 0;
|
|
|
7
7
|
class BaseField {
|
|
8
8
|
/**
|
|
9
9
|
* @param {Object} prediction - Prediction object from HTTP response
|
|
10
|
-
* @param
|
|
11
|
-
* @param
|
|
10
|
+
* @param valueKey - Key to use in the prediction dict
|
|
11
|
+
* @param reconstructed - Is the object reconstructed (not extracted by the API)
|
|
12
12
|
*/
|
|
13
13
|
constructor({ prediction = {}, valueKey = "value", reconstructed = false, pageId = undefined, }) {
|
|
14
14
|
/** The value. */
|
|
@@ -24,23 +24,23 @@ export declare class Field extends BaseField {
|
|
|
24
24
|
/** The confidence score of the prediction. */
|
|
25
25
|
confidence: number;
|
|
26
26
|
/**
|
|
27
|
-
* @param
|
|
28
|
-
* @param
|
|
29
|
-
* @param
|
|
30
|
-
* @param
|
|
31
|
-
* @param
|
|
27
|
+
* @param prediction - Prediction object from HTTP response
|
|
28
|
+
* @param valueKey - Key to use in the prediction dict
|
|
29
|
+
* @param reconstructed - Does the object is reconstructed (not extracted by the API)
|
|
30
|
+
* @param pageId - Page ID for multi-page document
|
|
31
|
+
* @param extraFields - Extra fields to get from the prediction and to set as attribute of the Field
|
|
32
32
|
*/
|
|
33
33
|
constructor({ prediction, valueKey, reconstructed, pageId, }: FieldConstructor);
|
|
34
34
|
/**
|
|
35
|
-
@param
|
|
36
|
-
@param
|
|
37
|
-
@param
|
|
38
|
-
@returns
|
|
35
|
+
@param array1 first Array of Fields
|
|
36
|
+
@param array2 second Array of Fields
|
|
37
|
+
@param attr Attribute to compare
|
|
38
|
+
@returns true if all elements in array1 exist in array2 and vice-versa, false otherwise
|
|
39
39
|
*/
|
|
40
40
|
static compareArrays(array1: Field[], array2: Field[], attr?: string): boolean;
|
|
41
41
|
/**
|
|
42
42
|
* @param {Field[]} array - Array of Fields
|
|
43
|
-
* @returns {Number} product of all the fields
|
|
43
|
+
* @returns {Number} product of all the fields probability
|
|
44
44
|
*/
|
|
45
45
|
static arrayConfidence(array: Field[]): number;
|
|
46
46
|
}
|
|
@@ -8,11 +8,11 @@ const geometry_1 = require("../../geometry");
|
|
|
8
8
|
*/
|
|
9
9
|
class Field extends base_1.BaseField {
|
|
10
10
|
/**
|
|
11
|
-
* @param
|
|
12
|
-
* @param
|
|
13
|
-
* @param
|
|
14
|
-
* @param
|
|
15
|
-
* @param
|
|
11
|
+
* @param prediction - Prediction object from HTTP response
|
|
12
|
+
* @param valueKey - Key to use in the prediction dict
|
|
13
|
+
* @param reconstructed - Does the object is reconstructed (not extracted by the API)
|
|
14
|
+
* @param pageId - Page ID for multi-page document
|
|
15
|
+
* @param extraFields - Extra fields to get from the prediction and to set as attribute of the Field
|
|
16
16
|
*/
|
|
17
17
|
constructor({ prediction = {}, valueKey = "value", reconstructed = false, pageId, }) {
|
|
18
18
|
super({ prediction, valueKey, reconstructed, pageId });
|
|
@@ -28,10 +28,10 @@ class Field extends base_1.BaseField {
|
|
|
28
28
|
this.boundingBox = (0, geometry_1.getBoundingBox)(this.polygon);
|
|
29
29
|
}
|
|
30
30
|
/**
|
|
31
|
-
@param
|
|
32
|
-
@param
|
|
33
|
-
@param
|
|
34
|
-
@returns
|
|
31
|
+
@param array1 first Array of Fields
|
|
32
|
+
@param array2 second Array of Fields
|
|
33
|
+
@param attr Attribute to compare
|
|
34
|
+
@returns true if all elements in array1 exist in array2 and vice-versa, false otherwise
|
|
35
35
|
*/
|
|
36
36
|
static compareArrays(array1, array2, attr = "value") {
|
|
37
37
|
const list1 = array1.map((item) => item[attr]);
|
|
@@ -46,7 +46,7 @@ class Field extends base_1.BaseField {
|
|
|
46
46
|
}
|
|
47
47
|
/**
|
|
48
48
|
* @param {Field[]} array - Array of Fields
|
|
49
|
-
* @returns {Number} product of all the fields
|
|
49
|
+
* @returns {Number} product of all the fields probability
|
|
50
50
|
*/
|
|
51
51
|
static arrayConfidence(array) {
|
|
52
52
|
let total = 1.0;
|
|
@@ -16,7 +16,18 @@ class PositionField {
|
|
|
16
16
|
* Default string representation.
|
|
17
17
|
*/
|
|
18
18
|
toString() {
|
|
19
|
-
|
|
19
|
+
if (this.polygon && this.polygon.length > 0)
|
|
20
|
+
return `Polygon with ${this.polygon.length} points.`;
|
|
21
|
+
if (this.boundingBox && this.boundingBox.length > 0) {
|
|
22
|
+
return `Polygon with ${this.boundingBox.length} points.`;
|
|
23
|
+
}
|
|
24
|
+
if (this.rectangle && this.rectangle.length > 0) {
|
|
25
|
+
return `Polygon with ${this.rectangle.length} points.`;
|
|
26
|
+
}
|
|
27
|
+
if (this.quadrangle && this.quadrangle.length > 0) {
|
|
28
|
+
return `Polygon with ${this.quadrangle.length} points.`;
|
|
29
|
+
}
|
|
30
|
+
return "";
|
|
20
31
|
}
|
|
21
32
|
}
|
|
22
33
|
exports.PositionField = PositionField;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Inference, StringDict, Page } from "../../parsing/common";
|
|
2
|
+
import { BarcodeReaderV1Document } from "./barcodeReaderV1Document";
|
|
3
|
+
/**
|
|
4
|
+
* Inference prediction for Barcode Reader, API version 1.
|
|
5
|
+
*/
|
|
6
|
+
export declare class BarcodeReaderV1 extends Inference {
|
|
7
|
+
/** The endpoint's name. */
|
|
8
|
+
endpointName: string;
|
|
9
|
+
/** The endpoint's version. */
|
|
10
|
+
endpointVersion: string;
|
|
11
|
+
/** The document-level prediction. */
|
|
12
|
+
prediction: BarcodeReaderV1Document;
|
|
13
|
+
/** The document's pages. */
|
|
14
|
+
pages: Page<BarcodeReaderV1Document>[];
|
|
15
|
+
constructor(rawPrediction: StringDict);
|
|
16
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BarcodeReaderV1 = void 0;
|
|
4
|
+
const common_1 = require("../../parsing/common");
|
|
5
|
+
const barcodeReaderV1Document_1 = require("./barcodeReaderV1Document");
|
|
6
|
+
/**
|
|
7
|
+
* Inference prediction for Barcode Reader, API version 1.
|
|
8
|
+
*/
|
|
9
|
+
class BarcodeReaderV1 extends common_1.Inference {
|
|
10
|
+
constructor(rawPrediction) {
|
|
11
|
+
super(rawPrediction);
|
|
12
|
+
/** The endpoint's name. */
|
|
13
|
+
this.endpointName = "barcode_reader";
|
|
14
|
+
/** The endpoint's version. */
|
|
15
|
+
this.endpointVersion = "1";
|
|
16
|
+
/** The document's pages. */
|
|
17
|
+
this.pages = [];
|
|
18
|
+
this.prediction = new barcodeReaderV1Document_1.BarcodeReaderV1Document(rawPrediction["prediction"]);
|
|
19
|
+
this.pages = rawPrediction["pages"].map((page) => new common_1.Page(barcodeReaderV1Document_1.BarcodeReaderV1Document, page, page["id"], page["orientation"]));
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
exports.BarcodeReaderV1 = BarcodeReaderV1;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Prediction, StringDict } from "../../parsing/common";
|
|
2
|
+
import { StringField } from "../../parsing/standard";
|
|
3
|
+
/**
|
|
4
|
+
* Document data for Barcode Reader, API version 1.
|
|
5
|
+
*/
|
|
6
|
+
export declare class BarcodeReaderV1Document implements Prediction {
|
|
7
|
+
/** List of decoded 1D barcodes. */
|
|
8
|
+
codes1D: StringField[];
|
|
9
|
+
/** List of decoded 2D barcodes. */
|
|
10
|
+
codes2D: StringField[];
|
|
11
|
+
constructor(rawPrediction: StringDict, pageId?: number);
|
|
12
|
+
/**
|
|
13
|
+
* Default string representation.
|
|
14
|
+
*/
|
|
15
|
+
toString(): string;
|
|
16
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BarcodeReaderV1Document = void 0;
|
|
4
|
+
const common_1 = require("../../parsing/common");
|
|
5
|
+
const standard_1 = require("../../parsing/standard");
|
|
6
|
+
/**
|
|
7
|
+
* Document data for Barcode Reader, API version 1.
|
|
8
|
+
*/
|
|
9
|
+
class BarcodeReaderV1Document {
|
|
10
|
+
constructor(rawPrediction, pageId) {
|
|
11
|
+
/** List of decoded 1D barcodes. */
|
|
12
|
+
this.codes1D = [];
|
|
13
|
+
/** List of decoded 2D barcodes. */
|
|
14
|
+
this.codes2D = [];
|
|
15
|
+
rawPrediction["codes_1d"] &&
|
|
16
|
+
rawPrediction["codes_1d"].map((itemPrediction) => this.codes1D.push(new standard_1.StringField({
|
|
17
|
+
prediction: itemPrediction,
|
|
18
|
+
pageId: pageId,
|
|
19
|
+
})));
|
|
20
|
+
rawPrediction["codes_2d"] &&
|
|
21
|
+
rawPrediction["codes_2d"].map((itemPrediction) => this.codes2D.push(new standard_1.StringField({
|
|
22
|
+
prediction: itemPrediction,
|
|
23
|
+
pageId: pageId,
|
|
24
|
+
})));
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Default string representation.
|
|
28
|
+
*/
|
|
29
|
+
toString() {
|
|
30
|
+
const codes1D = this.codes1D.join("\n ");
|
|
31
|
+
const codes2D = this.codes2D.join("\n ");
|
|
32
|
+
const outStr = `:Barcodes 1D: ${codes1D}
|
|
33
|
+
:Barcodes 2D: ${codes2D}`.trimEnd();
|
|
34
|
+
return (0, common_1.cleanOutString)(outStr);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
exports.BarcodeReaderV1Document = BarcodeReaderV1Document;
|