Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
await this.ready;
await tf.nextFrame();
if (this.video && this.video.readyState === 0) {
await new Promise(resolve => {
this.video.onloadeddata = () => resolve();
});
}
this.config.outputStride = segmentationOptions.outputStride || this.config.outputStride;
this.config.segmentationThreshold = segmentationOptions.segmentationThreshold || this.config.segmentationThreshold;
const segmentation = await this.model.estimatePersonSegmentation(imgToSegment, this.config.outputStride, this.config.segmentationThreshold)
const result = {};
result.maskBackground = bp.toMaskImageData(segmentation, true);
result.maskPerson = bp.toMaskImageData(segmentation, false);
result.raw = segmentation;
if (p5Utils.checkP5()) {
const blob1 = await p5Utils.rawToBlob(result.maskBackground.data, segmentation.width, segmentation.height);
const blob2 = await p5Utils.rawToBlob(result.maskPerson.data, segmentation.width, segmentation.height);
const p5Image1 = await p5Utils.blobToP5Image(blob1);
const p5Image2 = await p5Utils.blobToP5Image(blob2);
result.maskBackground = p5Image1;
result.maskPerson = p5Image2;
}
return result;
}
await tf.nextFrame();
if (this.video && this.video.readyState === 0) {
await new Promise(resolve => {
this.video.onloadeddata = () => resolve();
});
}
this.config.outputStride = segmentationOptions.outputStride || this.config.outputStride;
this.config.segmentationThreshold = segmentationOptions.segmentationThreshold || this.config.segmentationThreshold;
const segmentation = await this.model.estimatePersonSegmentation(imgToSegment, this.config.outputStride, this.config.segmentationThreshold)
const result = {};
result.maskBackground = bp.toMaskImageData(segmentation, true);
result.maskPerson = bp.toMaskImageData(segmentation, false);
result.raw = segmentation;
if (p5Utils.checkP5()) {
const blob1 = await p5Utils.rawToBlob(result.maskBackground.data, segmentation.width, segmentation.height);
const blob2 = await p5Utils.rawToBlob(result.maskPerson.data, segmentation.width, segmentation.height);
const p5Image1 = await p5Utils.blobToP5Image(blob1);
const p5Image2 = await p5Utils.blobToP5Image(blob2);
result.maskBackground = p5Image1;
result.maskPerson = p5Image2;
}
return result;
}