Tastenkunst / brfv4_javascript_examples

BRFv4 - HTML5/Javascript - examples project. Reference implementation for all other platform example packages.
463 stars 148 forks source link

BRFv4_JS_TK210219_v4.2.0_trial.js in a web Worker? #58

Open luispuig opened 5 years ago

luispuig commented 5 years ago

I am trying to use this trial in a web Worker, we need to improve the performance before moving to a commercial license.

Following a few issues (https://github.com/Tastenkunst/brfv4_javascript_examples/issues/12) (https://github.com/Tastenkunst/brfv4_javascript_examples/issues/45)

I added:

// BRF/brf_wasm/BRFv4_JS_TK210219_v4.2.0_trial.js
require('os') // added
require('https') // added
...
var ENVIRONMENT_IS_WORKER = true; //modified
...
module.exports = initializeBRF // added

But when I initializeBRF({...}) an error is thrown:

image

The same error whith JS and WASM versions.

luispuig commented 5 years ago

@MarcelKlammer any idea? thanks.

MarcelKlammer commented 5 years ago

I didn't look into that in much detail.

But a simple test.js that does roughly this:

var brfv4 = brfv4 || {

  ENVIRONMENT: "WORKER"
};

self.addEventListener('message', function(e) {

  console.log("w", e);
  //self.postMessage(e.data);

}, false);

importScripts("BRFv4_JS_TK190218_v4.0.5_trial.js");

initializeBRF(brfv4);

seem to produce no error while loading as a worker.

I don't know when I will have the time to look into it more deeply.

MarcelKlammer commented 5 years ago

Just added minimalWebcamWorker.html + BRFv4_JS_TK210219_v4.2.0_trial.worker.js

Please take a look and let me know, if that works for you.

luispuig commented 5 years ago

@MarcelKlammer thanks for the example.

It seems to load, but it fails when I try to config it:

  resolution = new brfv4.Rectangle(0, 0, 640, 480);
  BRFManager = new brfv4.BRFManager();
  BRFManager.init(resolution, resolution, 'com.tastenkunst.brfv4.js.examples.minimal.webcam');
  BRFManager.setMode(brfv4.BRFMode.FACE_TRACKING);
  BRFManager.setNumFacesToTrack(1);
  BRFManager.setFaceDetectionRoi(resolution);

  const size = Math.min(640, 480);
  BRFManager.setFaceDetectionParams(size * 0.3, size * 1.0, 12, 8);
  BRFManager.setFaceTrackingStartParams(size * 0.3, size * 1.0, 22, 26, 22);
  BRFManager.setFaceTrackingResetParams(size * 0.25, size * 1.0, 40, 55, 32);

image

I can try to isolate the example in a public repository if it makes easy for you to help us.

NOTE: Our version is newer: 4.2.0

Thanks!

MarcelKlammer commented 5 years ago

Please see my other comment.

I added a working (pun!) worker example. Update the repo and see the files:

minimalWebcamWorker.html BRFv4_JS_TK210219_v4.2.0_trial.worker.js

luispuig commented 5 years ago

I didn't understand the comment, sorry :)

I see the example that seems very very interesting: https://github.com/Tastenkunst/brfv4_javascript_examples/blob/master/minimalWebcamWorker.html

I will look into it the first thing in the morning. Thanks!