The code examples are not working for opencv.js

asked 2019-11-01 01:19:23 -0600

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

berak gravatar image


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. 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.
        let begin =;
        // start processing.;
        cv.cvtColor(src, dst, cv.COLOR_RGBA2GRAY);
        cv.imshow('canvasOutput', dst);
        // schedule the next one.
        let delay = 1000/FPS - ( - begin);
        setTimeout(processVideo, delay);
    } catch (err) {

// schedule the first one.
setTimeout(processVideo, 0);
edit retag flag offensive close merge delete


maybe you should try with easier, tested examples first.

if streaming is not defined in your code, it will delete all Mats and stop the program.

berak gravatar imageberak ( 2019-11-01 02:40:40 -0600 )edit

i was trying out the example mentioned in the above link in the Try it section. Somehow it doesnot work out.

Nabhonil gravatar imageNabhonil ( 2019-11-02 23:47:14 -0600 )edit

doesnotwork -- sorry, but noone can help you like that.

berak gravatar imageberak ( 2019-11-03 05:25:18 -0600 )edit