How to use image-js - 10 common examples

To help you get started, we’ve selected a few image-js examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github image-js / mrz-detection / src / __tests__ / readMrz.js View on Github external
'use strict';

const path = require('path');

const Image = require('image-js').Image;

const { getMrz, readMrz } = require('../..');

it(
  'test the extraction of MRZ characters on an identity card',
  async () => {
    const img = await Image.load(path.join(__dirname, 'fixtures/id1.jpg'));
    let mrzImage = getMrz(img);
    // mrzImage.save('./test.jpg');
    let { mrz } = await readMrz(mrzImage);
    expect(mrz).toMatchSnapshot();
  },
  15000
);

it(
github image-js / mrz-detection / run / writeCharacters.js View on Github external
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];
github image-js / mrz-detection / src / classifier / detection.js View on Github external
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);
github image-js / mrz-detection / run / getStatistics_old.js View on Github external
'use strict';

const fs = require('fs');
const IJS = require('image-js').Image;
const parse = require('mrz').parse;
const tableify = require('tableify');
const { join } = require('path');

const runMRZ = require('../src/runMRZ');
const loadFontFingerprint = require('../src/util/loadFontData');
const symbols = require('../src/util/symbolClasses').MRZ; // SYMBOLS MRZ NUMBERS

const codes = {
  PREPROCESS_ERROR: {
    code: 0,
    save: 'preprocess'
  },
  CORRECT: {
    code: 1,
    save: 'correct'
github image-js / mrz-detection / src / util / readWrite.js View on Github external
'use strict';

const path = require('path');

const fs = require('fs-extra');
const IJS = require('image-js').Image;

const extensions = ['.png', '.jpeg', '.jpg'];

async function writeImages(images) {
  if (!Array.isArray(images)) {
    images = [images];
  }
  // eslint-disable-next-line no-await-in-loop
  for (let entry of images) {
    const { image, filePath, ...metadata } = entry;
    if (!image || !filePath) {
      throw new Error('image and filePath props are mandatory');
    }

    const baseDir = path.resolve(path.dirname(filePath));
    await fs.mkdirp(baseDir);
github image-js / mrz-detection / run / fullMRZDetection.js View on Github external
'use strict';

const fs = require('fs');
const { join } = require('path');

const IJS = require('image-js').Image;
const tableify = require('tableify');
const { loadAllFontData, runFontAnalysis } = require('ocr-tools');
const mkdirp = require('mkdirp');
const rimraf = require('rimraf');

var {
  codes,
  fingerprintOptions,
  roiOptions,
  getFunctions
} = require('./MRZDetection');

// options
const maskOptions = {
  invert: true,
  algorithm: 'isodata'
github rai-project / mlmodelscope / src / components / InferenceResult / ReadRawImageResults.js View on Github external
function read_rawimage_results(features) {
  // ignore data for now and use results
  // const compressed_data = results.responses[0].features[0].raw_image.compressed_data;
  const compressed_data = features[0].raw_image.compressed_data;
  const binary_compressed_data = base64ToUint8Array(compressed_data);
  const jsonBuf = snappyjs.uncompress(binary_compressed_data);

  var enc = new TextDecoder("utf-8");
  const json = enc.decode(jsonBuf);

  var imagedata = JSON.parse(json);
  var width = results.responses[0].features[0].raw_image.width
  var height = results.responses[0].features[0].raw_image.height
  var img = new Image(width, height, imagedata, {kind: "RGB"})
  var rgbaimg = img.rgba8();
  return rgbaimg.toDataURL();
}
github image-js / mrz-detection / run / readMrz.js View on Github external
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]) {
github image-js / mrz-detection / run / getMrz.js View on Github external
} 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);
  }
}
github image-js / mrz-detection / run / writeCharacters.js View on Github external
'use strict';

const { join, resolve, extname, parse: parsePath } = require('path');

const { getLinesFromImage } = require('ocr-tools');
const fs = require('fs-extra');
const minimist = require('minimist');
const IJS = require('image-js').Image;

const { writeImages } = require('../src/util/readWrite');
const roiOptions = require('../src/roiOptions');

const argv = minimist(process.argv.slice(2));

exec().catch(console.error);

async function exec() {
  let outDir;
  const expected = await getExpected();

  if (!argv.outDir) {
    throw new Error('you must specify an output director with --outDir');
  } else {
    outDir = resolve(argv.outDir);

image-js

Image processing and manipulation in JavaScript

MIT
Latest version published 4 months ago

Package Health Score

76 / 100
Full package analysis