问题
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