Opencv.js How to draw a subset of contours?

≯℡__Kan透↙ 提交于 2021-01-29 05:16:30

问题


Using Opencv.js I have acquired the contours in an image.

using some selection function I have collected a subset of these contours.

Say they are in the list of contours:

var suitableContours = [];

I need to know draw these contours using opencv.

If this were python I could do

cv.drawContours(img, [suitableContours[cnt]], 0, [255, 0, 0, 255], 2);

Assume by the point I want to draw the contours I don't have access to the original image nor the mask nor the original contour list, only the selected contours.

How can I draw these contours?

The above code results in: BindingError: Cannot pass "[object Object],[object Object]" as a MatVector


回答1:


From https://docs.opencv.org/3.4/d5/daa/tutorial_js_contours_begin.html

Try something like this:

let color = new cv.Scalar(255,0,0,255);
for (let i = 0; i < suitableContours.size(); ++i) {
    cv.drawContours(src, suitableContours, i, color, 1, cv.LINE_8, hierarchy, 100);
}
cv.imshow('canvasOutput', src);


来源:https://stackoverflow.com/questions/56298228/opencv-js-how-to-draw-a-subset-of-contours

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!