|
1 | 1 | #!/usr/bin/env node
|
2 | 2 | const path = require('path');
|
3 | 3 | const fs = require('fs');
|
4 |
| -const { createWorker } = require('../../'); |
| 4 | +const { createWorker } = require('../..'); |
5 | 5 |
|
6 | 6 | const [,, imagePath] = process.argv;
|
7 | 7 | const image = path.resolve(__dirname, (imagePath || '../data/meditations.jpg'));
|
8 | 8 |
|
9 | 9 | console.log(`Recognizing ${image}`);
|
10 | 10 |
|
11 |
| -// Tesseract.js returns images (imageColor, imageGrey, imageBinary) as strings |
| 11 | +// Tesseract.js returns images (imageColor, imageGrey, imageBinary) as strings |
12 | 12 | // to be used as source tags.
|
13 |
| -// This function converts to Uint8Array data for saving to disk. |
| 13 | +// This function converts to Uint8Array data for saving to disk. |
14 | 14 | const convertImage = (imageSrc) => {
|
15 | 15 | const data = atob(imageSrc.split(',')[1])
|
16 |
| - .split('') |
17 |
| - .map((c) => c.charCodeAt(0)); |
| 16 | + .split('') |
| 17 | + .map((c) => c.charCodeAt(0)); |
18 | 18 |
|
19 | 19 | return new Uint8Array(data);
|
20 |
| -} |
| 20 | +}; |
21 | 21 |
|
22 | 22 | (async () => {
|
23 | 23 | const worker = await createWorker();
|
24 |
| - const { data: { imageColor, imageGrey, imageBinary } } = await worker.recognize(image, {rotateAuto: true}, {imageColor: true, imageGrey: true, imageBinary: true}); |
25 |
| - |
| 24 | + const { data: { imageColor, imageGrey, imageBinary } } = await worker.recognize(image, |
| 25 | + { rotateAuto: true }, { imageColor: true, imageGrey: true, imageBinary: true }); |
| 26 | + |
26 | 27 | console.log('Saving intermediate images: imageColor.png, imageGrey.png, imageBinary.png');
|
27 | 28 |
|
28 | 29 | fs.writeFileSync('imageColor.png', convertImage(imageColor));
|
|
0 commit comments