Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stricter-types #51

Merged
merged 1 commit into from
Jun 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions src/ocr-engine.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import initTesseractCore from "../build/tesseract-core";
import initTesseractCore, {MainModule, OCREngine as WASMOCREngine} from "../build/tesseract-core";

import { imageDataFromBitmap } from "./utils";

Expand Down Expand Up @@ -88,8 +88,8 @@ export type ProgressListener = (progress: number) => void;
* Instances are constructed using {@link createOCREngine}.
*/
export class OCREngine {
private _tesseractLib: any;
private _engine: any;
private _tesseractLib: MainModule;
private _engine: WASMOCREngine;
private _modelLoaded: boolean;
private _imageLoaded: boolean;
private _progressChannel?: MessagePort;
Expand All @@ -103,7 +103,7 @@ export class OCREngine {
* @param progressChannel - Channel used to report progress
* updates when OCREngine is run on a background thread
*/
constructor(tessLib: any, progressChannel?: MessagePort) {
constructor(tessLib: MainModule, progressChannel?: MessagePort) {
this._tesseractLib = tessLib;
this._engine = new tessLib.OCREngine();
this._modelLoaded = false;
Expand All @@ -115,8 +115,7 @@ export class OCREngine {
* Shut down the OCR engine and free up resources.
*/
destroy() {
this._engine.delete();
this._engine = null;
this._engine?.delete();
}

/**
Expand All @@ -129,7 +128,7 @@ export class OCREngine {
if (!result.success) {
throw new Error(`Unable to get variable ${name}`);
}
return result.value;
return result.value.toString();
}

/**
Expand Down