use of georegression.struct.curve.EllipseRotated_F64 in project BoofCV by lessthanoptimal.
the class TestKeyPointsCircleHexagonalGrid method createGrid.
public static Grid createGrid(int numRows, int numCols, double space, double radius) {
Grid grid = new Grid();
grid.rows = numRows;
grid.columns = numCols;
for (int row = 0; row < numRows; row++) {
for (int col = 0; col < numCols; col++) {
if (row % 2 == 0 && col % 2 == 1)
grid.ellipses.add(null);
else if (row % 2 == 1 && col % 2 == 0)
grid.ellipses.add(null);
else {
double x = col * space;
double y = row * space;
grid.ellipses.add(new EllipseRotated_F64(x, y, radius, radius, 0));
}
}
}
return grid;
}
use of georegression.struct.curve.EllipseRotated_F64 in project BoofCV by lessthanoptimal.
the class TestKeyPointsCircleRegularGrid method createGrid.
public static Grid createGrid(int numRows, int numCols, double space, double radius) {
Grid grid = new Grid();
grid.rows = numRows;
grid.columns = numCols;
for (int row = 0; row < numRows; row++) {
for (int col = 0; col < numCols; col++) {
double x = col * space;
double y = row * space;
grid.ellipses.add(new EllipseRotated_F64(x, y, radius, radius, 0));
}
}
return grid;
}
use of georegression.struct.curve.EllipseRotated_F64 in project BoofCV by lessthanoptimal.
the class ExampleFitEllipse method main.
public static void main(String[] args) {
// load and convert the image into a usable format
BufferedImage image = UtilImageIO.loadImage(UtilIO.pathExample("particles01.jpg"));
GrayF32 input = ConvertBufferedImage.convertFromSingle(image, null, GrayF32.class);
GrayU8 binary = new GrayU8(input.width, input.height);
// the mean pixel value is often a reasonable threshold when creating a binary image
double mean = ImageStatistics.mean(input);
// create a binary image by thresholding
ThresholdImageOps.threshold(input, binary, (float) mean, true);
// reduce noise with some filtering
GrayU8 filtered = BinaryImageOps.erode8(binary, 1, null);
filtered = BinaryImageOps.dilate8(filtered, 1, null);
// Find the contour around the shapes
List<Contour> contours = BinaryImageOps.contour(filtered, ConnectRule.EIGHT, null);
// Fit an ellipse to each external contour and draw the results
Graphics2D g2 = image.createGraphics();
g2.setStroke(new BasicStroke(3));
g2.setColor(Color.RED);
for (Contour c : contours) {
FitData<EllipseRotated_F64> ellipse = ShapeFittingOps.fitEllipse_I32(c.external, 0, false, null);
VisualizeShapes.drawEllipse(ellipse.shape, g2);
}
// ShowImages.showWindow(VisualizeBinaryData.renderBinary(filtered, false, null),"Binary",true);
ShowImages.showWindow(image, "Ellipses", true);
}
use of georegression.struct.curve.EllipseRotated_F64 in project BoofCV by lessthanoptimal.
the class TestBinaryEllipseDetector method distortedImage.
/**
* Input image is distorted
*/
@Test
public void distortedImage() {
List<EllipseRotated_F64> original = new ArrayList<>();
original.add(new EllipseRotated_F64(50, 65, 20, 10, 0.5));
original.add(new EllipseRotated_F64(90, 100, 25, 25, 0));
GrayU8 image = TestBinaryEllipseDetectorPixel.renderEllipses_F64(200, 210, original, 0);
GrayU8 binary = image.createSameShape();
ThresholdImageOps.threshold(image, binary, 30, true);
BinaryEllipseDetector<GrayU8> alg = create();
PixelTransform2_F32 distToUndist = new PixelTransformAffine_F32(new Affine2D_F32(1, 0, 0, 1, 5, 8));
PixelTransform2_F32 undistToDist = new PixelTransformAffine_F32(new Affine2D_F32(1, 0, 0, 1, -5, -8));
alg.setLensDistortion(distToUndist, undistToDist);
alg.process(image, binary);
// adjust the ellipses using the transform
List<EllipseRotated_F64> expected = new ArrayList<>();
for (EllipseRotated_F64 o : original) {
EllipseRotated_F64 e = new EllipseRotated_F64(o);
e.center.x += 5;
e.center.y += 8;
expected.add(e);
}
List<EllipseRotated_F64> found = alg.getFoundEllipses(null);
TestBinaryEllipseDetectorPixel.checkEquals_F64(expected, found, 1.0, 0.1);
}
use of georegression.struct.curve.EllipseRotated_F64 in project BoofCV by lessthanoptimal.
the class TestBinaryEllipseDetector method autoRefineToggle.
/**
* Turn off refinement and manually invoke it
*/
@Test
public void autoRefineToggle() {
List<EllipseRotated_F64> expected = new ArrayList<>();
expected.add(new EllipseRotated_F64(50, 65, 20, 10, 0.5));
expected.add(new EllipseRotated_F64(90, 100, 25, 25, 0));
GrayU8 image = TestBinaryEllipseDetectorPixel.renderEllipses_F64(200, 210, expected, 0);
GrayU8 binary = image.createSameShape();
ThresholdImageOps.threshold(image, binary, 30, true);
BinaryEllipseDetector<GrayU8> alg = create();
alg.setAutoRefine(false);
alg.process(image, binary);
List<EllipseRotated_F64> found = alg.getFoundEllipses(null);
List<EllipseRotated_F64> refined = new ArrayList<>();
for (EllipseRotated_F64 f : found) {
EllipseRotated_F64 r = new EllipseRotated_F64(f);
assertTrue(alg.refine(r));
assertTrue(f.a != r.a);
assertTrue(f.b != r.b);
assertTrue(f.phi != r.phi);
refined.add(r);
}
TestBinaryEllipseDetectorPixel.checkEquals_F64(refined, found, 1.0, 0.1);
}
Aggregations