-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRecognitionModelAwsTextract.js
More file actions
56 lines (50 loc) · 1.67 KB
/
RecognitionModelAwsTextract.js
File metadata and controls
56 lines (50 loc) · 1.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/**
* @typedef {Object} RecognitionResult
* @property {boolean} success
* @property {string} [rawData]
* @property {string} format
* @property {Error} [error]
*/
import { OcrEngineAWSTextract } from './ocrEngineAwsTextract.js';
/**
* AWS Textract recognition model for use with Scribe.js.
*/
export class RecognitionModelTextract {
static config = {
name: 'AWS Textract',
outputFormat: 'textract',
};
/**
* Recognize text from an image using AWS Textract.
* @param {Uint8Array|ArrayBuffer} imageData - Image data
* @param {Object} [options]
* @param {boolean} [options.analyzeLayout=false] - Whether to enable layout analysis.
* Note that enabling layout analysis increases AWS costs.
* @param {boolean} [options.analyzeLayoutTables=false] - Whether to enable table analysis.
* Enabling table analysis automatically enables layout analysis.
* Note that enabling table analysis significantly increases AWS costs.
* @returns {Promise<RecognitionResult>}
*/
static async recognizeImage(imageData, options = {}) {
const data = imageData instanceof ArrayBuffer ? new Uint8Array(imageData) : imageData;
const result = await OcrEngineAWSTextract.recognizeImageSync(data, {
analyzeLayout: options.analyzeLayout ?? false,
analyzeLayoutTables: options.analyzeLayoutTables ?? false,
});
if (result.success) {
return {
success: true,
rawData: JSON.stringify(result.data),
format: 'textract',
};
}
return {
success: false,
error: new Error(result.error),
format: 'textract',
};
}
static async checkAvailability() {
return { available: true };
}
}