-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtypes.d.ts
More file actions
194 lines (155 loc) · 4.7 KB
/
types.d.ts
File metadata and controls
194 lines (155 loc) · 4.7 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
// types.d.ts
// Type definitions for multilingual-purejs-ocr
// Generated to provide TypeScript support for the pure JavaScript implementation.
import { InferenceSession, Tensor } from 'onnxruntime-node';
// =============================================================================
// Core Interfaces
// =============================================================================
export interface Box {
left: number;
top: number;
width: number;
height: number;
}
export type Polygon = number[][]; // Array of [x, y] points, e.g., [[x1, y1], [x2, y2], ...]
export interface TextElement {
text: string;
confidence: number;
frame: Box;
box: Polygon;
}
export interface Paragraph {
text: string;
confidence: number;
boundingBox: Box;
elements: TextElement[];
}
export interface OCRResult {
totalElements: number;
data: TextElement[];
totalParagraphs?: number;
paragraphs?: Paragraph[];
}
// =============================================================================
// Configuration Interfaces
// =============================================================================
export interface OnnxOptions {
executionProviders?: string[];
graphOptimizationLevel?: 'all' | 'basic' | 'extended' | 'off';
enableCpuMemArena?: boolean;
enableMemPattern?: boolean;
executionMode?: 'sequential' | 'parallel';
logSeverityLevel?: 0 | 1 | 2 | 3 | 4;
intraOpNumThreads?: number;
interOpNumThreads?: number;
}
export interface GroupingConfig {
VERTICAL_THRESHOLD_RATIO: number;
HORIZONTAL_THRESHOLD_RATIO: number;
MIN_OVERLAP_RATIO: number;
MAX_VERTICAL_OFFSET_RATIO: number;
}
export interface LanguageConfig {
MODEL: string;
DICT: string;
NAME: string;
}
export type SupportedLanguage = 'en' | 'ch' | 'ja' | 'ko' | 'latin';
export interface RecognitionLanguages {
en: LanguageConfig;
ch: LanguageConfig;
ja: LanguageConfig;
ko: LanguageConfig;
latin: LanguageConfig;
}
export interface DetectionConfig {
MODEL_PATH: string;
THRESHOLD: number;
MIN_BOX_SIZE: number;
MAX_BOX_SIZE: number;
UNCLIP_RATIO: number;
BASE_SIZE: number;
MAX_IMAGE_SIZE: number;
ONNX_OPTIONS: OnnxOptions;
}
export interface RecognitionConfig {
LANGUAGES: RecognitionLanguages;
DEFAULT_LANGUAGE: SupportedLanguage;
IMAGE_HEIGHT: number;
CONFIDENCE_THRESHOLD: number;
REMOVE_DUPLICATE_CHARS: boolean;
IGNORED_TOKENS: number[];
ONNX_OPTIONS: OnnxOptions;
}
export interface DefaultConfig {
DETECTION: DetectionConfig;
RECOGNITION: RecognitionConfig;
GROUPING: GroupingConfig;
}
export interface OcrOptions {
// Language
language?: SupportedLanguage;
// Detection
detectionThreshold?: number;
minBoxSize?: number;
maxBoxSize?: number;
unclipRatio?: number;
baseSize?: number;
maxImageSize?: number;
detectionModelPath?: string;
// Recognition
confidenceThreshold?: number;
imageHeight?: number;
removeDuplicateChars?: boolean;
recognitionModelPath?: string;
dictionaryPath?: string;
// Grouping
grouping?: Partial<GroupingConfig>;
// ONNX
detectionOnnxOptions?: Partial<OnnxOptions>;
recognitionOnnxOptions?: Partial<OnnxOptions>;
}
export interface DetectOptions {
grouped?: boolean;
onnxOptions?: Partial<OnnxOptions>;
}
// =============================================================================
// Ocr Class Declaration (with Static Methods)
// =============================================================================
declare class Ocr {
detect(imagePath: string, options?: DetectOptions): Promise<OCRResult>;
setGroupingConfig(config: Partial<GroupingConfig>): void;
getGroupingConfig(): GroupingConfig;
static getAvailableLanguages(): RecognitionLanguages;
static create(options?: OcrOptions): Promise<Ocr>;
}
export { Ocr };
// =============================================================================
// Internal Types (Exported for Completeness)
// =============================================================================
export interface DistanceResult {
horizontal: number;
vertical: number;
euclidean: number;
}
export interface LineImage {
box: Polygon;
image: any; // ImageRaw instance (internal)
}
export interface ModelData {
data: number[];
width: number;
height: number;
}
export interface DecodeResult {
text: string;
mean: number;
}
// Re-export for library users
export { InferenceSession, Tensor } from 'onnxruntime-node';
// Default config type
export const DEFAULT_CONFIG: DefaultConfig;
// Utility functions (typed for advanced users)
export function calculateDistance(box1: Box, box2: Box): DistanceResult;
export function groupTextElements(elements: TextElement[], config?: Partial<GroupingConfig>): Paragraph[][];
export function createParagraph(group: TextElement[]): Paragraph;