Creating an app and want to stop Posenet when its job is done
private sketch(p: any) {
p.setup = () => {
this.poseNet = ml5.poseNet(p.createCapture(p.VIDEO), {
outputStride: 8
});
this.poseNet.on('pose', (results) => {
//DO SOMETHING WITH results[0]
});
};
}
Already tried setting diverse vars to null
StopKI() {
// Terminate PoseNet when done
this.p5 = null;
this.poseNet = null;
console.log('KI stopped');
}
The posenet responds to detections in the video element. If you remove the video element the detection and callbacks will probably stop?
In the source code the detection function keeps calling itself if the video element exists
So removing the video element might hopefully stop the repeating loop. I don't see a more elegant solution in the source code
UPDATE
I found that the
poseNet.on(...)
event listener can be canceled by callingRemoveListener
and passing the same callback function. It seems to work in the online P5 web editor: