From 287d7e2be1d695a80fb176a4d308b113d639dcf2 Mon Sep 17 00:00:00 2001 From: Rishabh Shukla <42492389+blurry-x-face@users.noreply.github.com> Date: Wed, 26 Jan 2022 04:35:32 +0530 Subject: [PATCH] fix blob analysis to work in node (#1589) Co-authored-by: h Co-authored-by: Harsh Khandeparkar <34770591+HarshKhandeparkar@users.noreply.github.com> Co-authored-by: Jeffrey Warren --- src/modules/BlobAnalysis/Module.js | 12 +++++++++--- src/modules/_nomodule/gl-context.js | 26 ++++++++++++++------------ 2 files changed, 23 insertions(+), 15 deletions(-) diff --git a/src/modules/BlobAnalysis/Module.js b/src/modules/BlobAnalysis/Module.js index efd9367d..4aa20064 100644 --- a/src/modules/BlobAnalysis/Module.js +++ b/src/modules/BlobAnalysis/Module.js @@ -10,9 +10,15 @@ module.exports = function BlobAnalysis(options, UI){ var step = this; - function extraManipulation(pixels){ - - pixels = require('./BlobAnalysis')(pixels); + function extraManipulation(pixels, setRenderState, generateOutput){ + setRenderState(false); + if (!options.inBrowser) { + require('../_nomodule/gl-context')(input, callback, step, options); + } else{ + pixels = require('./BlobAnalysis')(pixels); + setRenderState(true); + generateOutput(); + } return pixels; } diff --git a/src/modules/_nomodule/gl-context.js b/src/modules/_nomodule/gl-context.js index 6a615cd5..4f1c86d6 100644 --- a/src/modules/_nomodule/gl-context.js +++ b/src/modules/_nomodule/gl-context.js @@ -15,19 +15,21 @@ module.exports = function runInBrowserContext(input, callback, step, options) { is not available otherwise */ page.goto('https://google.com').then(() => { page.addScriptTag({ path: require('path').join(__dirname, '../../../dist/image-sequencer.js') }).then(() => { - page.evaluate((options) => { - return new Promise((resolve, reject) => { - var sequencer = ImageSequencer(); - sequencer.loadImage(options.input.src); - sequencer.addSteps(options.modOptions.step, options.modOptions); - sequencer.run(function cb(out) { - resolve(sequencer.steps[1].output.src); + page.addScriptTag({path: require('path').join(__dirname, '../../../node_modules/opencv.js/opencv.js')}).then(() => { + page.evaluate((options) => { + return new Promise((resolve, reject) => { + var sequencer = ImageSequencer(); + sequencer.loadImage(options.input.src); + sequencer.addSteps(options.modOptions.step, options.modOptions); + sequencer.run(function cb(out) { + resolve(sequencer.steps[1].output.src); + }); + }); + }, obj).then(el => { + browser.close().then(() => { + step.output = { src: el, format: input.format }; + callback(); }); - }); - }, obj).then(el => { - browser.close().then(() => { - step.output = { src: el, format: input.format }; - callback(); }); }); });