Compare commits

..

8 Commits

  1. 25
      docs/image-format.md
  2. 18
      package-lock.json
  3. 4
      package.json
  4. 1
      src/constants/PSM.js
  5. 13
      src/index.d.ts
  6. 15
      src/worker-script/index.js

25
docs/image-format.md

@ -1,17 +1,18 @@ @@ -1,17 +1,18 @@
# Image Format
Support Format: **bmp, jpg, png, pbm**
The main Tesseract.js functions (ex. recognize, detect) take an `image` parameter. The image formats and data types supported are listed below.
The main Tesseract.js functions (ex. recognize, detect) take an `image` parameter, which should be something that is like an image. What's considered "image-like" differs depending on whether it is being run from the browser or through NodeJS.
Support Image Formats: **bmp, jpg, png, pbm, webp**
On a browser, an image can be:
- an `img` or `canvas` element
- a `File` object (from a file `<input>`)
- a `Blob` object
- a path or URL to an accessible image
- a base64 encoded image fits `data:image\/([a-zA-Z]*);base64,([^"]*)` regexp
For browser and Node, supported data types are:
- string with base64 encoded image (fits `data:image\/([a-zA-Z]*);base64,([^"]*)` regexp)
- buffer
In Node.js, an image can be
- a path to a local image
- a Buffer storing binary image
- a base64 encoded image fits `data:image\/([a-zA-Z]*);base64,([^"]*)` regexp
For browser only, supported data types are:
- `File` or `Blob` object
- `img` or `canvas` element
For Node only, supported data types are:
- string containing a path to local image
Note: images must be a supported image format **and** a supported data type. For example, a buffer containing a png image is supported. A buffer containing raw pixel data is not supported.

18
package-lock.json generated

@ -1,12 +1,12 @@ @@ -1,12 +1,12 @@
{
"name": "tesseract.js",
"version": "3.0.2",
"version": "3.0.3",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "tesseract.js",
"version": "3.0.2",
"version": "3.0.3",
"hasInstallScript": true,
"license": "Apache-2.0",
"dependencies": {
@ -20,7 +20,7 @@ @@ -20,7 +20,7 @@
"opencollective-postinstall": "^2.0.2",
"regenerator-runtime": "^0.13.3",
"resolve-url": "^0.2.1",
"tesseract.js-core": "^3.0.1",
"tesseract.js-core": "^3.0.2",
"wasm-feature-detect": "^1.2.11",
"zlibjs": "^0.3.1"
},
@ -8500,9 +8500,9 @@ @@ -8500,9 +8500,9 @@
}
},
"node_modules/tesseract.js-core": {
"version": "3.0.1",
"resolved": "https://registry.npmjs.org/tesseract.js-core/-/tesseract.js-core-3.0.1.tgz",
"integrity": "sha512-kcEGcZG4Vl8tmdsPgLacPYoXFRo8IhG9SQxTLbK/6vG+aVTwD89voIJs1KgL3x+RcWDR7sNmd2sMVcpgcLBMMg=="
"version": "3.0.2",
"resolved": "https://registry.npmjs.org/tesseract.js-core/-/tesseract.js-core-3.0.2.tgz",
"integrity": "sha512-2fD76ka9nO/C616R0fq+M9Zu91DA3vEfyozp0jlxaJOBmpfeprtgRP3cqVweZh2darE1kK/DazoxZ65g7WU99Q=="
},
"node_modules/test-exclude": {
"version": "6.0.0",
@ -15989,9 +15989,9 @@ @@ -15989,9 +15989,9 @@
}
},
"tesseract.js-core": {
"version": "3.0.1",
"resolved": "https://registry.npmjs.org/tesseract.js-core/-/tesseract.js-core-3.0.1.tgz",
"integrity": "sha512-kcEGcZG4Vl8tmdsPgLacPYoXFRo8IhG9SQxTLbK/6vG+aVTwD89voIJs1KgL3x+RcWDR7sNmd2sMVcpgcLBMMg=="
"version": "3.0.2",
"resolved": "https://registry.npmjs.org/tesseract.js-core/-/tesseract.js-core-3.0.2.tgz",
"integrity": "sha512-2fD76ka9nO/C616R0fq+M9Zu91DA3vEfyozp0jlxaJOBmpfeprtgRP3cqVweZh2darE1kK/DazoxZ65g7WU99Q=="
},
"test-exclude": {
"version": "6.0.0",

4
package.json

@ -1,6 +1,6 @@ @@ -1,6 +1,6 @@
{
"name": "tesseract.js",
"version": "3.0.2",
"version": "3.0.3",
"description": "Pure Javascript Multilingual OCR",
"main": "src/index.js",
"types": "src/index.d.ts",
@ -70,7 +70,7 @@ @@ -70,7 +70,7 @@
"opencollective-postinstall": "^2.0.2",
"regenerator-runtime": "^0.13.3",
"resolve-url": "^0.2.1",
"tesseract.js-core": "^3.0.1",
"tesseract.js-core": "^3.0.2",
"wasm-feature-detect": "^1.2.11",
"zlibjs": "^0.3.1"
},

1
src/constants/PSM.js

@ -15,4 +15,5 @@ module.exports = { @@ -15,4 +15,5 @@ module.exports = {
SINGLE_CHAR: '10',
SPARSE_TEXT: '11',
SPARSE_TEXT_OSD: '12',
RAW_LINE: '13',
};

13
src/index.d.ts vendored

@ -19,8 +19,8 @@ declare namespace Tesseract { @@ -19,8 +19,8 @@ declare namespace Tesseract {
readText(path: string, jobId?: string): Promise<ConfigResult>
removeText(path: string, jobId?: string): Promise<ConfigResult>
FS(method: string, args: any[], jobId?: string): Promise<ConfigResult>
loadLanguage(langs?: string, jobId?: string): Promise<ConfigResult>
initialize(langs?: string, oem?: OEM, jobId?: string): Promise<ConfigResult>
loadLanguage(langs?: string | Lang[], jobId?: string): Promise<ConfigResult>
initialize(langs?: string | Lang[], oem?: OEM, jobId?: string): Promise<ConfigResult>
setParameters(params: Partial<WorkerParams>, jobId?: string): Promise<ConfigResult>
recognize(image: ImageLike, options?: Partial<RecognizeOptions>, jobId?: string): Promise<RecognizeResult>
detect(image: ImageLike, jobId?: string): Promise<DetectResult>
@ -28,6 +28,11 @@ declare namespace Tesseract { @@ -28,6 +28,11 @@ declare namespace Tesseract {
getPDF(title?: string, textonly?: boolean, jobId?: string):Promise<GetPDFResult>
}
interface Lang {
code: string;
data: unknown;
}
interface WorkerOptions {
corePath: string
langPath: string
@ -84,13 +89,13 @@ declare namespace Tesseract { @@ -84,13 +89,13 @@ declare namespace Tesseract {
width: number
height: number
}
const enum OEM {
enum OEM {
TESSERACT_ONLY,
LSTM_ONLY,
TESSERACT_LSTM_COMBINED,
DEFAULT,
}
const enum PSM {
enum PSM {
OSD_ONLY = '0',
AUTO_OSD = '1',
AUTO_ONLY = '2',

15
src/worker-script/index.js

@ -144,15 +144,7 @@ res) => { @@ -144,15 +144,7 @@ res) => {
res.progress({ workerId, status: 'loaded language traineddata', progress: 1 });
res.resolve(langs);
} catch (err) {
if (isWebWorker && err instanceof DOMException) {
/*
* For some reason google chrome throw DOMException in loadLang,
* while other browser is OK, for now we ignore this exception
* and hopefully to find the root cause one day.
*/
} else {
res.reject(err.toString());
}
res.reject(err.toString());
}
};
@ -185,7 +177,10 @@ const initialize = ({ @@ -185,7 +177,10 @@ const initialize = ({
api.End();
}
api = new TessModule.TessBaseAPI();
api.Init(null, langs, oem);
const status = api.Init(null, langs, oem);
if (status === -1) {
res.reject('initialization failed');
}
params = defaultParams;
setParameters({ payload: { params } });
res.progress({

Loading…
Cancel
Save