Skip to content

Instantly share code, notes, and snippets.

@khaong
Last active January 6, 2021 22:41
Show Gist options
  • Save khaong/1cef8002dea2e49777a0664f3688b9dd to your computer and use it in GitHub Desktop.
Save khaong/1cef8002dea2e49777a0664f3688b9dd to your computer and use it in GitHub Desktop.
add to image-util-e2e-specs.js
it('should produce image results', async function () {
const fs = require('fs/promises');
const output_images_path = path.resolve(__dirname, '..', '..', 'build', 'output');
try { await fs.mkdir(output_images_path); } catch (error) {}
/* this is what works on my local setup, adjust as necessary for opencv4nodejs require */
const packageName = 'opencv4nodejs';
const globalPackageName = path.resolve(process.env.npm_config_prefix, 'lib', 'node_modules', packageName);
const cv = require(globalPackageName);
const {results, visualization} = await getImageOccurrences(originalImage, numberImage, {visualize: true, threshold: 0.8});
const fullHighlightedImage = await cv.imdecodeAsync(visualization);
await cv.imwriteAsync(path.resolve(output_images_path, 'full-highlights.png'), fullHighlightedImage);
for (let i = 0; i < results.length; i++) {
const highlightedImage = await cv.imdecodeAsync(results[i].visualization);
await cv.imwriteAsync(path.resolve(output_images_path, `highlight-${i}.png`), highlightedImage);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment