Load background detection network only when required

This commit is contained in:
Pierre HUBERT 2021-01-30 20:08:27 +01:00
parent 08091425f1
commit 9bee589dc4

View File

@ -962,19 +962,25 @@ class CallWindow extends CustomEvents {
canvasTarget.height = videoTarget.height; canvasTarget.height = videoTarget.height;
bodyPix.load({ // Process images
multiplier: 0.75,
stride: 32,
quantBytes: 4
}).then( net => {
(async () => { (async () => {
try { try {
while(videoTrack.readyState == "live") while(videoTrack.readyState == "live")
{ {
if (this.blurBackground) { if (this.blurBackground) {
const segmentation = await net.segmentPerson(videoTarget);
// Load network if required
if (!this.backgroundDetectionNetwork)
{
this.backgroundDetectionNetwork = await bodyPix.load({
multiplier: 0.75,
stride: 32,
quantBytes: 4
});
}
const segmentation = await this.backgroundDetectionNetwork.segmentPerson(videoTarget);
const backgroundBlurAmount = 6; const backgroundBlurAmount = 6;
const edgeBlurAmount = 2; const edgeBlurAmount = 2;
@ -996,7 +1002,6 @@ class CallWindow extends CustomEvents {
console.error("Failure", e); console.error("Failure", e);
} }
})(); })();
});
stream = canvasTarget.captureStream(); stream = canvasTarget.captureStream();