OpenCV在JavaScript中绘制轮廓

时间:2020-08-30 17:02:08

标签: javascript reactjs opencv opencv-contour

我正在尝试在javascript中绘制图像的轮廓,轮廓是点数组,不是从cv.findContours()获得的,这是我的代码:

    function drawImageOncanvas(url, contours) {
        var img = new Image();
        img.onload = function () {
            let src = cv.imread(img);
            if (contours !== undefined && contours !== null) {
                let matVec = new cv.MatVector();
                contours.forEach((contour) => {
                    const matContour = cv.matFromArray(
                        contour.length,
                        2,
                        cv.CV_8UC1,
                        [].concat(...contour)
                    );
                    matVec.push_back(matContour);
                });
                for (let i = 0; i < matVec.size(); ++i) {
                    let color = new cv.Scalar(0, 100, 0);
                    cv.drawContours(src, matVec, i, color, 1);
                }
            }
            cv.imshow('board', src);
            src.delete();
        };
        img.src = url;
    }

为了能够将轮廓传递到cv.drawContours(),首先我使用cv.matFromArray()matContour(点阵列)创建contour,然后推动每个matContourmatVec中(即MatVector的实例),最后将matVec传递给cv.drawContours(); 但是我在Uncaught 6795152上得到了cv.drawContours

有什么想法吗?

谢谢

0 个答案:

没有答案
相关问题