Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save CezaryDanielNowak/caeb83260ac9fe1da4cf025825f5e074 to your computer and use it in GitHub Desktop.
Save CezaryDanielNowak/caeb83260ac9fe1da4cf025825f5e074 to your computer and use it in GitHub Desktop.
I'm getting an error: ERROR in ContextFF: WebGL1 and 2 are not enabled "GL_INCOMPATIBLE". But I might want to get back to this code in the future.
class _FaceDetector {
initPerformed = false;
loadPerformed = false;
constructor() {
const canvas = document.createElement('canvas');
this.canvas = canvas;
this.ctx = canvas.getContext('2d');
canvas.style.visibility = 'hidden';
canvas.id = 'jeeFaceFilterCanvas';
document.body.appendChild(canvas);
console.log('canvas created', canvas);
}
init() {
return new Promise((resolve, reject) => {
global.JEELIZFACEFILTER.init({
canvasId: 'jeeFaceFilterCanvas',
NNCPath: '/face-detection/neuralNets/', // path to JSON neural network model (NN_DEFAULT.json by default)
callbackReady: function(errCode, spec) {
console.log('callbackReady', arguments);
if (errCode){
console.log('AN ERROR HAPPENS. ERROR CODE =', errCode);
return reject(errCode);
}
// [init scene with spec...]
console.log('INFO: JEELIZFACEFILTER IS READY');
resolve();
}, //end callbackReady()
// called at each render iteration (drawing loop)
callbackTrack: function(detectState){
console.log('callbackTrack', detectState)
// Render your scene here
// [... do something with detectState]
} //end callbackTrack()
});
this.initPerformed = true;
});
}
detect(input) {
return new Promise((resolve, reject) => {
if (!this.loadPerformed) {
getScript(asset`face-detection/dist/jeelizFaceFilter.js`);
this.loadPerformed = true;
return this.detect(input).then(resolve, reject);
}
if (!global.JEELIZFACEFILTER) {
setTimeout(() => {
// not loaded yet. waiting
console.log('JEELIZFACEFILTER not loaded yet. waiting')
this.detect(input).then(resolve, reject);
}, 1000);
return;
}
if (!this.initPerformed) {
return this.init().then(() => {
return this.detect(input).then(resolve, reject);
}).catch(reject);
}
if (input instanceof HTMLVideoElement) {
this.canvas.width = input.videoWidth;
this.canvas.height = input.videoHeight;
this.ctx.drawImage(input, 0, 0);
}
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment