const videoEl = document.getElementsByClassName('input_video')[0];
selfSegObj = new SelfieSegmentation({locateFile: (file) => {
return `https://cdn.jsdelivr.net/npm/@mediapipe/selfie_segmentation/${file}`;
}});
selfSegObj.setOptions({
modelSelection: 1,
selfieMode: false,
effect: 'mask',
});
selfSegObj.onResults(selfieSegResults);
camObj = new Camera(videoEl, {
onFrame: async () => {
await selfSegObj.send({image: videoEl});
},
width: 1280,
height: 720
});
camObj.start();
function selfieSegResults(results) {
const canvasEl = document.getElementsByClassName('output_canvas')[0];
var canvasContext = canvasEl.getContext('2d');
canvasContext.clearRect(0, 0, canvasEl.width, canvasEl.height);
canvasContext.save();
canvasContext.drawImage(results.segmentationMask, 0, 0, canvasEl.width, canvasEl.height);
}
After switching tabs, the "selfieSegResults" callback function within the SelfieSegmentation object may not be triggered.
If you have any suggestions or alternative solutions to ensure that segmented image data can still be obtained even when changing Chrome tabs, please share your insights!