I’m working on a visual for Black History Month and don’t know why the sliders are not changing the way that openCV canny is working. I have tried referencing them directly. The two sliders are called T1 and T2.
The change only happens if I pause and re-start the video, which causes the requestAnimationFrame() to be canceled via cancelAnimationFrame() and restarted.
function tick() {
vid.cap.read(vid.src)
cv.cvtColor(vid.src, vid.gry, cv.COLOR_RGBA2GRAY, cv.CV_8UC1)
cv.Canny(vid.gry, vid.gry, T1, T2, 3);
cv.imshow('canvasOutput', vid.gry);
vid.event = requestAnimationFrame(tick);
};
Update: I have added an invalidation promise to the play function, that stops the tick() animation loop when a slider is changed, but I can’t use the invalidation promise to restart the play() function.
function play () {
if (vid.event != null) {
cancelAnimationFrame(vid.event)
vid.event = null
}
vid.streaming = true;
vid.stopped = false;
const width = video.width;
const height = video.height;
vid.src = new cv.Mat(height, width, cv.CV_8UC4);
vid.dst = new cv.Mat(height, width, cv.CV_8UC1);
vid.gry = new cv.Mat(height, width, cv.CV_8UC1);
vid.cap = new cv.VideoCapture(video);
tick(); // start requestAnimationFrame event
invalidation.then(() => {
cancelAnimationFrame(vid.event);
vid.event = null
vid.streaming = false
vid.stopped = true
// play() // doesn't work
}) // .then(play()) // doesn't work too
}