#!/usr/bin/env node
const path = require('path');
const sharp = require('sharp');
const { createWorker } = require('tesseract.js');
const [,, imagePath] = process.argv;
const image = path.resolve('C:\\Users\\c\\attendance-system\\server\\Untitled.png');
console.log(`Processing and recognizing ${image}`);
(async () => {
// Process the image
const processedImage = 'processed.png';
await sharp(image)
.grayscale()
.toFile(processedImage);
// Perform OCR on the processed image
const worker = await createWorker("eng", 1, {
logger: m => console.log(m),
});
await worker.setParameters({
tessedit_char_whitelist: '0123456789',
});
const { data: { text } } = await worker.recognize(processedImage);
console.log("Recognized text:")
console.log(text);
await worker.terminate();
})();