Skip to content
Open
Show file tree
Hide file tree
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
8 changes: 7 additions & 1 deletion src/easyocr.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { spawn, ChildProcess } from 'child_process';
import { existsSync } from 'fs';
import path from 'path';

interface OCRResult {
Expand All @@ -19,7 +20,12 @@ export class EasyOCR {
private pythonProcess: ChildProcess | null = null;

constructor() {
this.pythonPath = 'python3';
// Use the venv python created by setup-python-env.js during preinstall,
// falling back to system python3 if the venv doesn't exist.
const venvBin = process.platform === 'win32' ? 'Scripts' : 'bin';
const venvExe = process.platform === 'win32' ? 'python.exe' : 'python';
const venvPython = path.join(__dirname, '..', 'venv', venvBin, venvExe);
this.pythonPath = existsSync(venvPython) ? venvPython : 'python3';
this.scriptPath = path.join(__dirname, 'easyocr_script.py');
}

Expand Down
2 changes: 1 addition & 1 deletion src/easyocr_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

def init_reader(languages):
global reader
reader = easyocr.Reader(languages)
reader = easyocr.Reader(languages, verbose=False)
return json.dumps({"status": "success", "message": "Reader initialized"})

def read_text(image_path):
Expand Down