OpenCV的drawKeypoints

时间:2018-12-17 12:24:48

标签: javascript opencv feature-detection opencv-features2d

drawKeypoints是一个免费功能吗?当我尝试使用它会引发以下错误

cv.drawKeypoints is not a function

我正在尝试编写此示例

https://opencv-python-tutroals.readthedocs.io/en/latest/py_tutorials/py_feature2d/py_orb/py_orb.html#orb

我已经按照此处所述构建了OpenCV Js

https://docs.opencv.org/3.4/d4/da1/tutorial_js_setup.html

然后将其附加到我的HTML

<script src="opencv.js"></script>

这是我使用的功能

function orbExample() {
            let imgElement = document.querySelector('#imageSrc');
            let img = cv.imread(imgElement);
            let color = new cv.Scalar(0,255,0, 1);

            // Initiate ORB detector
            let orb = new cv.ORB();
            let keyPoints = new cv.KeyPointVector;

            // find the keypoints with ORB
            orb.detect(img, keyPoints);

            let des = new cv.Mat();
            // compute the descriptors with ORB
            orb.compute(img, keyPoints, des);

            // draw only keypoints location,not size and orientation
            let img2 = new cv.Mat();

            cv.drawKeypoints(img, keyPoints, img2, color, 0);

            cv.imshow('opencvCanvas', img2);
        }

1 个答案:

答案 0 :(得分:0)

我认为您在加载opencv.js之前正在使用cv函数,请使用onload函数,该功能告诉您先加载opencv.js,然后再使用opencv函数。