mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-04-01 09:01:45 +08:00
add definition of tesseract.js (#11978)
* add definition of tesseract.js * change `type` to `interface` as much as possible
This commit is contained in:
committed by
Masahiro Wakame
parent
a9ebd4adc4
commit
35f82623a1
63
tesseract.js/tesseract.js-tests.ts
Normal file
63
tesseract.js/tesseract.js-tests.ts
Normal file
@@ -0,0 +1,63 @@
|
||||
/// <reference path="tesseract.js.d.ts" />
|
||||
|
||||
import * as TesseractLib from 'tesseract.js';
|
||||
|
||||
TesseractLib.recognize("./demo.png", {
|
||||
lang: 'chi_sim',
|
||||
}).progress(function (p) {
|
||||
console.log('progress', p);
|
||||
}).then(function (result) {
|
||||
console.log(result.text)
|
||||
});
|
||||
|
||||
TesseractLib.detect("./demo.png").then(function (result) {
|
||||
console.log(result)
|
||||
});
|
||||
|
||||
TesseractLib.recognize("./demo.png")
|
||||
.progress(message => console.log(message))
|
||||
.catch(err => console.error(err))
|
||||
.then(result => console.log(result))
|
||||
.finally(resultOrError => console.log(resultOrError));
|
||||
|
||||
var job1 = TesseractLib.recognize("./demo.png");
|
||||
job1.progress(message => console.log(message));
|
||||
job1.catch(err => console.error(err));
|
||||
job1.then(result => console.log(result));
|
||||
job1.finally(resultOrError => console.log(resultOrError));
|
||||
|
||||
TesseractLib.create({
|
||||
workerPath: '/path/to/worker.js',
|
||||
langPath: 'https://cdn.rawgit.com/naptha/tessdata/gh-pages/3.02/',
|
||||
corePath: 'https://cdn.rawgit.com/naptha/tesseract.js-core/0.1.0/index.js',
|
||||
});
|
||||
|
||||
Tesseract.recognize("./demo.png", {
|
||||
lang: 'chi_sim',
|
||||
}).progress(function (p) {
|
||||
console.log('progress', p);
|
||||
}).then(function (result) {
|
||||
console.log(result.text)
|
||||
});
|
||||
|
||||
Tesseract.detect("./demo.png").then(function (result) {
|
||||
console.log(result)
|
||||
});
|
||||
|
||||
Tesseract.recognize("./demo.png")
|
||||
.progress(message => console.log(message))
|
||||
.catch(err => console.error(err))
|
||||
.then(result => console.log(result))
|
||||
.finally(resultOrError => console.log(resultOrError));
|
||||
|
||||
var job2 = Tesseract.recognize("./demo.png");
|
||||
job2.progress(message => console.log(message));
|
||||
job2.catch(err => console.error(err));
|
||||
job2.then(result => console.log(result));
|
||||
job2.finally(resultOrError => console.log(resultOrError));
|
||||
|
||||
Tesseract.create({
|
||||
workerPath: '/path/to/worker.js',
|
||||
langPath: 'https://cdn.rawgit.com/naptha/tessdata/gh-pages/3.02/',
|
||||
corePath: 'https://cdn.rawgit.com/naptha/tesseract.js-core/0.1.0/index.js',
|
||||
});
|
||||
149
tesseract.js/tesseract.js.d.ts
vendored
Normal file
149
tesseract.js/tesseract.js.d.ts
vendored
Normal file
@@ -0,0 +1,149 @@
|
||||
// Type definitions for tesseract.js
|
||||
// Project: https://github.com/naptha/tesseract.js
|
||||
// Definitions by: York Yao <https://github.com/plantain-00/>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
/// <reference path="../node/node.d.ts" />
|
||||
|
||||
declare module Tesseract {
|
||||
type ImageLike = string | HTMLImageElement | HTMLCanvasElement | HTMLVideoElement
|
||||
| CanvasRenderingContext2D | File | Blob | ImageData | Buffer;
|
||||
interface Progress {
|
||||
status: string;
|
||||
progress: number;
|
||||
loaded?: number;
|
||||
}
|
||||
interface Block {
|
||||
paragraphs: Paragraph;
|
||||
text: string;
|
||||
confidence: number;
|
||||
baseline: Baseline;
|
||||
bbox: Bbox;
|
||||
blocktype: string;
|
||||
polygon: any;
|
||||
page: Page;
|
||||
lines: Line[];
|
||||
words: Word[];
|
||||
symbols: Symbol[];
|
||||
}
|
||||
interface Baseline {
|
||||
x0: number;
|
||||
y0: number;
|
||||
x1: number;
|
||||
y1: number;
|
||||
has_baseline: boolean;
|
||||
}
|
||||
interface Bbox {
|
||||
x0: number;
|
||||
y0: number;
|
||||
x1: number;
|
||||
y1: number;
|
||||
}
|
||||
interface Line {
|
||||
words: Word[];
|
||||
text: string;
|
||||
confidence: number;
|
||||
baseline: Baseline;
|
||||
bbox: Bbox;
|
||||
paragraph: Paragraph;
|
||||
block: Block;
|
||||
page: Page;
|
||||
symbols: Symbol[];
|
||||
}
|
||||
interface Paragraph {
|
||||
lines: Line[];
|
||||
text: string;
|
||||
confidence: number;
|
||||
baseline: Baseline;
|
||||
bbox: Bbox;
|
||||
is_ltr: boolean;
|
||||
block: Block;
|
||||
page: Page;
|
||||
words: Word[];
|
||||
symbols: Symbol[];
|
||||
}
|
||||
interface Symbol {
|
||||
choices: Choice[];
|
||||
image: any;
|
||||
text: string;
|
||||
confidence: number;
|
||||
baseline: Baseline;
|
||||
bbox: Bbox;
|
||||
is_superscript: boolean;
|
||||
is_subscript: boolean;
|
||||
is_dropcap: boolean;
|
||||
word: Word;
|
||||
line: Line;
|
||||
paragraph: Paragraph;
|
||||
block: Block;
|
||||
page: Page;
|
||||
}
|
||||
interface Choice {
|
||||
text: string;
|
||||
confidence: number;
|
||||
}
|
||||
interface Word {
|
||||
symbols: Symbol[];
|
||||
choices: Choice[];
|
||||
text: string;
|
||||
confidence: number;
|
||||
baseline: Baseline;
|
||||
bbox: Bbox;
|
||||
is_numeric: boolean;
|
||||
in_dictionary: boolean;
|
||||
direction: string;
|
||||
language: string;
|
||||
is_bold: boolean;
|
||||
is_italic: boolean;
|
||||
is_underlined: boolean;
|
||||
is_monospace: boolean;
|
||||
is_serif: boolean;
|
||||
is_smallcaps: boolean;
|
||||
font_size: number;
|
||||
font_id: number;
|
||||
font_name: string;
|
||||
line: Line;
|
||||
paragraph: Paragraph;
|
||||
block: Block;
|
||||
page: Page;
|
||||
}
|
||||
interface Page {
|
||||
blocks: Block[];
|
||||
confidence: number;
|
||||
html: string;
|
||||
lines: Line[];
|
||||
oem: string;
|
||||
paragraphs: Paragraph[];
|
||||
psm: string;
|
||||
symbols: Symbol[];
|
||||
text: string;
|
||||
version: string;
|
||||
words: Word[];
|
||||
}
|
||||
interface TesseractJob {
|
||||
then: (callback: (result: Page) => void) => TesseractJob;
|
||||
progress: (callback: (progress: Progress) => void) => TesseractJob;
|
||||
catch: (callback: (error: Error) => void) => TesseractJob;
|
||||
finally: (callback: (resultOrError: Error | Page) => void) => TesseractJob;
|
||||
error?: (error: Error) => TesseractJob;
|
||||
}
|
||||
|
||||
interface TesseractStatic {
|
||||
recognize(image: ImageLike): TesseractJob;
|
||||
recognize(image: ImageLike, options: any): TesseractJob;
|
||||
detect(image: ImageLike): TesseractJob;
|
||||
|
||||
create(paths: {
|
||||
workerPath: string;
|
||||
langPath: string;
|
||||
corePath: string;
|
||||
}): TesseractStatic;
|
||||
}
|
||||
}
|
||||
|
||||
declare module "tesseract.js" {
|
||||
var Tesseract: Tesseract.TesseractStatic
|
||||
export = Tesseract;
|
||||
}
|
||||
|
||||
declare var Tesseract: Tesseract.TesseractStatic;
|
||||
Reference in New Issue
Block a user