Blob contours are irregular and hard to process in code; it's easier to work with boxFit rectangles.
But the contour's outer points can be accessed by an OpMode. The result is a list of (X, Y) coordinates, with origin at the top left corner of the camera's image. X increases to the right, Y increases downward.
Select and read the Blocks or Java section below:
Blocks The following Blocks Function retrieves, stores and displays a List of all the vertex Points of the contour of the instant Blob being processed by the OpMode.
The List can be as short as 4 values, or dozens of values for jagged contours.
Note that the .points Block (used above for boxFit corners) retrieves and stores the List within the same Block. This .ContourPoints Block only retrieves the List, to be assigned to a separate variable Block.
(Figure: Getting the list of contour points)
The .ContourPoints and Point.x and Point.y Blocks are in the "Vision/ColorBlobLocator/Blob data" toolbox.
The Function uses its own For Loop to cycle through the myContourPoints List, of undetermined length (could be very long).
This Function operates inside the Sample OpMode's For Loop of all Blob results. The instant myBlob is the one being processed by that outer For Loop.
Java This Java code retrieves, stores and displays a List of all the vertex Points of the contour of the instant Blob being processed by the OpMode.
import org.opencv.core.Point;
.
.
// Display getContourPoints(), an array of the contour's many (X, Y) vertices
Point[] myContourPoints;
myContourPoints = b.getContourPoints();
int j = 0;
for(Point thisContourPoint : myContourPoints)
{
telemetry.addLine(String.format("contour vertex %d (%d,%d)",
j, (int) thisContourPoint.x, (int) thisContourPoint.y));
j += 1;
}
This Function operates inside the Sample OpMode's For Loop of all Blob results. The instant Blob b is the one being processed by that outer For Loop.
Not covered here is one feature available in Java only:
MatOfPoint myContour = getContour()
This method returns a matrix unique to the OpenCV library. The matrix object can convert itself to an array, as follows:
MatOfPoint myContour;
Point[] myContourPoints;
myContour = b.getContour();
myContourPoints = myContour.toArray();
This code seems to give the same set of points as getContourPoints() shown above.