2019-07-03 15:38:25 +00:00
|
|
|
// @flow
|
|
|
|
|
2019-12-17 21:08:39 +00:00
|
|
|
import * as bodyPix from '@tensorflow-models/body-pix';
|
2020-05-20 10:57:03 +00:00
|
|
|
|
2019-07-03 15:38:25 +00:00
|
|
|
import JitsiStreamBlurEffect from './JitsiStreamBlurEffect';
|
|
|
|
|
|
|
|
/**
|
2019-12-17 21:08:39 +00:00
|
|
|
* Creates a new instance of JitsiStreamBlurEffect. This loads the bodyPix model that is used to
|
|
|
|
* extract person segmentation.
|
2019-07-03 15:38:25 +00:00
|
|
|
*
|
|
|
|
* @returns {Promise<JitsiStreamBlurEffect>}
|
|
|
|
*/
|
2019-12-17 21:08:39 +00:00
|
|
|
export async function createBlurEffect() {
|
2019-07-03 15:38:25 +00:00
|
|
|
if (!MediaStreamTrack.prototype.getSettings && !MediaStreamTrack.prototype.getConstraints) {
|
2019-12-17 21:08:39 +00:00
|
|
|
throw new Error('JitsiStreamBlurEffect not supported!');
|
2019-07-03 15:38:25 +00:00
|
|
|
}
|
|
|
|
|
2019-12-17 21:08:39 +00:00
|
|
|
// An output stride of 16 and a multiplier of 0.5 are used for improved
|
|
|
|
// performance on a larger range of CPUs.
|
|
|
|
const bpModel = await bodyPix.load({
|
|
|
|
architecture: 'MobileNetV1',
|
|
|
|
outputStride: 16,
|
|
|
|
multiplier: 0.50,
|
|
|
|
quantBytes: 2
|
2019-09-24 13:50:11 +00:00
|
|
|
});
|
|
|
|
|
2019-12-17 21:08:39 +00:00
|
|
|
return new JitsiStreamBlurEffect(bpModel);
|
2019-07-03 15:38:25 +00:00
|
|
|
}
|