in vision/textDetection.js [219:268]
async function main(inputDir) {
const index = new Index();
try {
const files = await fs.readdir(inputDir);
// Get a list of all files in the directory (filter out other directories)
const allImageFiles = (
await Promise.all(
files.map(async file => {
const filename = path.join(inputDir, file);
const stats = await fs.stat(filename);
if (!stats.isDirectory()) {
return filename;
}
})
)
).filter(f => !!f);
// Figure out which files have already been processed
let imageFilesToProcess = (
await Promise.all(
allImageFiles.map(async filename => {
const processed = await index.documentIsProcessed(filename);
if (!processed) {
// Forward this filename on for further processing
return filename;
}
})
)
).filter(file => !!file);
// The batch endpoint won't handle
if (imageFilesToProcess.length > 15) {
console.log(
'Maximum of 15 images allowed. Analyzing the first 15 found.'
);
imageFilesToProcess = imageFilesToProcess.slice(0, 15);
}
// Analyze any remaining unprocessed files
if (imageFilesToProcess.length > 0) {
console.log('Files to process: ');
await getTextFromFiles(index, imageFilesToProcess);
}
console.log('All files processed!');
} catch (e) {
console.error(e);
}
index.quit();
}