@gutenye/ocr-node
Version:
Guten OCR is a high accurate text detection (OCR) Javascript/Typescript library that runs on Node.js, Browser, React Native and C++. Based on PaddleOCR and ONNX runtime
31 lines (26 loc) • 872 B
text/typescript
import fs from 'node:fs/promises'
import BaseOcr, { registerBackend, type ModelCreateOptions } from '@gutenye/ocr-common'
import { splitIntoLineImages } from '@gutenye/ocr-common/splitIntoLineImages'
import defaultModels from '@gutenye/ocr-models/node'
import { InferenceSession } from 'onnxruntime-node'
import { FileUtils } from './FileUtils'
import { ImageRaw } from './ImageRaw'
registerBackend({
FileUtils,
ImageRaw,
InferenceSession,
splitIntoLineImages,
defaultModels,
})
// biome-ignore lint/complexity/noStaticOnlyClass: <explanation>
class Ocr extends BaseOcr {
static async create(options: ModelCreateOptions = {}) {
const ocr = await BaseOcr.create(options)
if (options.debugOutputDir) {
await fs.mkdir(options.debugOutputDir, { recursive: true })
}
return ocr
}
}
export * from '@gutenye/ocr-common'
export default Ocr