Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async function processFile(imagePath) {
let shouldAdd = getCharacterCounter(argv.maxCount);
try {
const parsedPath = parsePath(imagePath);
const image = await IJS.load(imagePath);
const result = getLinesFromImage(image, {
roiOptions,
fingerprintOptions: {}
});
const name = parsedPath.base.replace(parsedPath.ext, '');
const asExpected = matchesExpected(name, result.lines);
if (asExpected) {
console.log('looks good, write chars');
for (let i = 0; i < result.lines.length; i++) {
const line = result.lines[i];
// eslint-disable-next-line no-await-in-loop
for (let j = 0; j < line.rois.length; j++) {
const char = asExpected ? expected[name][i][j] : '';
if (asExpected && !shouldAdd(char)) continue;
const roi = line.rois[j];
randomColors: true
};
const swtOptions = {
scaleInvariant: false,
breakdown: false,
size: 5,
aspectRatio: 5,
lowThresh: 100,
highThresh: 300,
heightRatio: 2,
distanceRatio: 4,
thicknessRatio: 2.0,
};
var testImage = (await Image.load(filename));/*.gaussianFilter({
radius: 2
});*/
// getAllMethods(testImage);
console.log(`filename: ${filename}`);
console.time("SWT time");
var rois = strokeWidthTransform(testImage, swtOptions);
console.timeEnd("SWT time")
drawRois(testImage, rois);
var masks = new Array(rois.length);
for (var i = 0; i < rois.length; ++i) {
masks[i] = testImage.extract(rois[i].getMask()).grey();
}
var predictions = new Array(masks.length);
async function processFile(imagePath) {
try {
stats.total += 1;
const parsedPath = parsePath(imagePath);
const result = await readMrz(await IJS.load(imagePath), {
debug: true,
saveName: join(parsedPath.dir, '../multiMask/', parsedPath.base)
});
console.log(result);
const parsed = parse(result);
stats.couldParse += 1;
console.log('valid', parsed.valid);
if (!parsed.valid) {
console.log(parsed.details.filter((d) => !d.valid).map((d) => d.error));
} else {
stats.valid += 1;
}
console.log(imagePath);
const nameWithoutExt = parsedPath.base.replace(parsedPath.ext, '');
console.log(nameWithoutExt);
if (expected[nameWithoutExt]) {
} else if (argv.dir) {
const dirname = path.resolve(argv.dir);
const files = (await fs.readdir(dirname)).filter((f) => {
f = f.toLowerCase();
return f.endsWith('jpg') || f.endsWith('png') || f.endsWith('jpeg');
});
const out = path.join(dirname, 'out');
const toSave = [];
await fs.emptyDir(out);
for (let file of files) {
console.log(`process ${file}`);
const imagePath = path.join(dirname, file);
console.time(imagePath);
const result = {};
try {
getMrz(await Image.load(imagePath), {
debug: true,
out: result
});
} catch (e) {
console.error(e);
}
console.timeEnd(imagePath);
await saveImages(imagePath, result, out);
toSave.push([imagePath, result]);
}
await saveReports(toSave, out);
}
}
var promises = files.map((elem) => IJS.load(readPath + elem));
var table = [];