Closed martinbooth closed 3 weeks ago
Hi @martinbooth , you asked for a very good case. I have therefore added a new structure in the new version (0.2.4
): PointVectorOfVectors
i.e. now we can create a vector of point vectors and put it as a parameter of the findContours
function.
const contours = OpenCV.createObject(ObjectType.PointVectorOfVectors);
OpenCV.invoke(
'findContours',
grayChannel,
contours,
RetrievalModes.RETR_TREE,
ContourApproximationModes.CHAIN_APPROX_SIMPLE
);
Of course we can also convert to an array of arrays of objects:
const contoursVector = OpenCV.toJSValue(contours);
Or simply copy a specific element into a PointVector and use it in functions such as contourArea
or boundingRect
.
for (let i = 0; i < contoursVector.array.length; i++) {
const contour = OpenCV.copyObjectFromVector(contours, i);
const { value: area } = OpenCV.invoke('contourArea', contour, false);
if (area > 3000) {
// console.log(OpenCV.toJSValue(contour))
const rect = OpenCV.invoke('boundingRect', contour);
}
}
If you have other problems, feel free to reopen this thread or add new issues. Thanks!
In your example, you are using findBoundingRect to get a bounding rectangle of points... is there anyway to get the actual points in the contour? it seems contour is typed as Mat, and the only thing possible to do with that is convert it to a buffer