Ask Your Question

Revision history [back]

The code examples are not working for opencv.js

hi,

I have been trying out the code examples of the opencv.js which are mentioned in the docs. Have been trying out the code examples mentioned in the "GUI Features->Getting started with Videos".

Have been trying out this code it is throwing full of errors. I am sorry to say but the documentation is not up to the mark for a new person to start working on opencv.js. Errors are like it is not mentioned what is streaming variable is about. cap.read is throwing error saying that the video width is 0. Can someone help in providing a good example code?

let video = document.getElementById('videoInput'); let src = new cv.Mat(video.height, video.width, cv.CV_8UC4); let dst = new cv.Mat(video.height, video.width, cv.CV_8UC1); let cap = new cv.VideoCapture(video);

const FPS = 30; function processVideo() { try { if (!streaming) { // clean and stop. src.delete(); dst.delete(); return; } let begin = Date.now(); // start processing. cap.read(src); cv.cvtColor(src, dst, cv.COLOR_RGBA2GRAY); cv.imshow('canvasOutput', dst); // schedule the next one. let delay = 1000/FPS - (Date.now() - begin); setTimeout(processVideo, delay); } catch (err) { utils.printError(err); } };

// schedule the first one. setTimeout(processVideo, 0);

click to hide/show revision 2
None

updated 2019-11-01 01:34:54 -0600

berak gravatar image

The code examples are not working for opencv.js

hi,

I have been trying out the code examples of the opencv.js which are mentioned in the docs. Have been trying out the code examples mentioned in the "GUI Features->Getting started with Videos".

Have been trying out this code it is throwing full of errors. I am sorry to say but the documentation is not up to the mark for a new person to start working on opencv.js. Errors are like it is not mentioned what is streaming variable is about. cap.read is throwing error saying that the video width is 0. Can someone help in providing a good example code?

let video = document.getElementById('videoInput');
let src = new cv.Mat(video.height, video.width, cv.CV_8UC4);
let dst = new cv.Mat(video.height, video.width, cv.CV_8UC1);
let cap = new cv.VideoCapture(video);

cv.VideoCapture(video); const FPS = 30; function processVideo() { try { if (!streaming) { // clean and stop. src.delete(); dst.delete(); return; } let begin = Date.now(); // start processing. cap.read(src); cv.cvtColor(src, dst, cv.COLOR_RGBA2GRAY); cv.imshow('canvasOutput', dst); // schedule the next one. let delay = 1000/FPS - (Date.now() - begin); setTimeout(processVideo, delay); } catch (err) { utils.printError(err); } };

}; // schedule the first one. setTimeout(processVideo, 0);

0);