-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_ocr.js
More file actions
33 lines (28 loc) · 940 Bytes
/
test_ocr.js
File metadata and controls
33 lines (28 loc) · 940 Bytes
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
import Tesseract from 'tesseract.js';
import path from 'path';
// Use the user-provided receipt image
const imagePath = 'd:\\Money Planner\\test_receipt.png';
console.log('Testing OCR on:', imagePath);
console.log('---');
Tesseract.recognize(
imagePath,
'chi_tra+eng',
{
logger: m => {
if (m.status === 'recognizing text') {
process.stdout.write(`\rProgress: ${Math.round(m.progress * 100)}%`);
}
}
}
).then(({ data: { text } }) => {
console.log('\n\n=== RAW OCR TEXT ===');
console.log(text);
console.log('=== END RAW TEXT ===\n');
// Now test parsing
const lines = text.split('\n').map(l => l.trim()).filter(l => l.length > 0);
console.log('=== PARSED LINES ===');
lines.forEach((line, i) => console.log(`${i}: "${line}"`));
console.log('=== END LINES ===\n');
}).catch(err => {
console.error('OCR Error:', err);
});