-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathocr.js
More file actions
34 lines (28 loc) · 1.01 KB
/
ocr.js
File metadata and controls
34 lines (28 loc) · 1.01 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
const { createWorker } = require('tesseract.js');
const fs = require('fs');
const path = require('path');
const slidesDir = path.join(__dirname, 'gambar_input');
async function run() {
const files = fs.readdirSync(slidesDir).filter(f => f.endsWith('.png')).sort();
if (files.length === 0) {
console.log("No PNG files found in gambar_input/");
return;
}
console.log("Initializing Tesseract worker...");
const worker = await createWorker('ind'); // Load Indonesian language pack
for (const file of files) {
console.log(`\n======================================`);
console.log(`FILE: ${file}`);
console.log(`======================================`);
const filePath = path.join(slidesDir, file);
try {
const { data: { text } } = await worker.recognize(filePath);
console.log(text);
} catch (err) {
console.error(`Error processing ${file}:`, err.message);
}
}
await worker.terminate();
console.log("\nOCR processing completed!");
}
run().catch(console.error);