Search in sources :

Example 71 with Polygon2D_F64

use of georegression.struct.shapes.Polygon2D_F64 in project BoofCV by lessthanoptimal.

the class SquareGridTools method orderSquareCorners.

/**
 * Adjust the corners in the square's polygon so that they are aligned along the grids overall
 * length
 *
 * @return true if valid grid or false if not
 */
public boolean orderSquareCorners(SquareGrid grid) {
    // the first pass interleaves every other row
    for (int row = 0; row < grid.rows; row++) {
        for (int col = 0; col < grid.columns; col++) {
            orderNodeGrid(grid, row, col);
            Polygon2D_F64 square = grid.get(row, col).square;
            for (int i = 0; i < 4; i++) {
                square.vertexes.data[i] = ordered[i];
            }
        }
    }
    return true;
}
Also used : Polygon2D_F64(georegression.struct.shapes.Polygon2D_F64)

Example 72 with Polygon2D_F64

use of georegression.struct.shapes.Polygon2D_F64 in project BoofCV by lessthanoptimal.

the class SquareGridTools method orderNode.

/**
 * Fills the ordered list with the corners in target node in canonical order.
 *
 * @param pointingX true if 'node' is pointing along the x-axis from target.  false for point along y-axis
 */
protected void orderNode(SquareNode target, SquareNode node, boolean pointingX) {
    int index0 = findIntersection(target, node);
    int index1 = (index0 + 1) % 4;
    int index2 = (index0 + 2) % 4;
    int index3 = (index0 + 3) % 4;
    if (index0 < 0)
        throw new RuntimeException("Couldn't find intersection.  Probable bug");
    lineCenters.a = target.center;
    lineCenters.b = node.center;
    UtilLine2D_F64.convert(lineCenters, general);
    Polygon2D_F64 poly = target.square;
    if (pointingX) {
        if (sign(general, poly.get(index0)) > 0) {
            ordered[1] = poly.get(index1);
            ordered[2] = poly.get(index0);
        } else {
            ordered[1] = poly.get(index0);
            ordered[2] = poly.get(index1);
        }
        if (sign(general, poly.get(index2)) > 0) {
            ordered[3] = poly.get(index2);
            ordered[0] = poly.get(index3);
        } else {
            ordered[3] = poly.get(index3);
            ordered[0] = poly.get(index2);
        }
    } else {
        if (sign(general, poly.get(index0)) > 0) {
            ordered[2] = poly.get(index1);
            ordered[3] = poly.get(index0);
        } else {
            ordered[2] = poly.get(index0);
            ordered[3] = poly.get(index1);
        }
        if (sign(general, poly.get(index2)) > 0) {
            ordered[0] = poly.get(index2);
            ordered[1] = poly.get(index3);
        } else {
            ordered[0] = poly.get(index3);
            ordered[1] = poly.get(index2);
        }
    }
}
Also used : Polygon2D_F64(georegression.struct.shapes.Polygon2D_F64)

Example 73 with Polygon2D_F64

use of georegression.struct.shapes.Polygon2D_F64 in project BoofCV by lessthanoptimal.

the class SquaresIntoCrossClusters method computeNodeInfo.

void computeNodeInfo(List<DetectPolygonFromContour.Info> squares) {
    for (int i = 0; i < squares.size(); i++) {
        SquareNode n = nodes.grow();
        n.reset();
        DetectPolygonFromContour.Info info = squares.get(i);
        Polygon2D_F64 polygon = info.polygon;
        // see if every corner touches a border
        if (info.borderCorners.size() > 0) {
            boolean allBorder = true;
            for (int j = 0; j < info.borderCorners.size(); j++) {
                if (!info.borderCorners.get(j)) {
                    allBorder = false;
                    break;
                }
            }
            if (allBorder) {
                nodes.removeTail();
                continue;
            }
        }
        // The center is used when visualizing results
        UtilPoint2D_F64.mean(polygon.vertexes.data, 0, polygon.size(), n.center);
        for (int j = 0, k = polygon.size() - 1; j < polygon.size(); k = j, j++) {
            double l = polygon.get(j).distance(polygon.get(k));
            n.largestSide = Math.max(n.largestSide, l);
        }
        n.square = polygon;
        n.touch = info.borderCorners;
        n.updateArrayLength();
    }
}
Also used : DetectPolygonFromContour(boofcv.alg.shapes.polygon.DetectPolygonFromContour) Polygon2D_F64(georegression.struct.shapes.Polygon2D_F64)

Example 74 with Polygon2D_F64

use of georegression.struct.shapes.Polygon2D_F64 in project BoofCV by lessthanoptimal.

the class VideoSequenceSimulator method convexFill.

private void convexFill(Polygon2D_I32 poly, ImageGray image, double value) {
    int minX = Integer.MAX_VALUE;
    int maxX = Integer.MIN_VALUE;
    int minY = Integer.MAX_VALUE;
    int maxY = Integer.MIN_VALUE;
    for (int i = 0; i < poly.size(); i++) {
        Point2D_I32 p = poly.vertexes.data[i];
        if (p.y < minY) {
            minY = p.y;
        } else if (p.y > maxY) {
            maxY = p.y;
        }
        if (p.x < minX) {
            minX = p.x;
        } else if (p.x > maxX) {
            maxX = p.x;
        }
    }
    ImageRectangle bounds = new ImageRectangle(minX, minY, maxX, maxY);
    BoofMiscOps.boundRectangleInside(image, bounds);
    Point2D_F64 p = new Point2D_F64();
    Polygon2D_F64 poly64 = new Polygon2D_F64(4);
    for (int i = 0; i < 4; i++) poly64.vertexes.data[i].set(poly.vertexes.data[i].x, poly.vertexes.data[i].y);
    for (int y = bounds.y0; y < bounds.y1; y++) {
        p.y = y;
        for (int x = bounds.x0; x < bounds.x1; x++) {
            p.x = x;
            if (Intersection2D_F64.containConvex(poly64, p)) {
                GeneralizedImageOps.set(image, x, y, value);
            }
        }
    }
}
Also used : Point2D_F64(georegression.struct.point.Point2D_F64) Point2D_I32(georegression.struct.point.Point2D_I32) ImageRectangle(boofcv.struct.ImageRectangle) Polygon2D_F64(georegression.struct.shapes.Polygon2D_F64)

Example 75 with Polygon2D_F64

use of georegression.struct.shapes.Polygon2D_F64 in project BoofCV by lessthanoptimal.

the class ExampleFiducialBinary method main.

public static void main(String[] args) {
    String directory = UtilIO.pathExample("fiducial/binary");
    // load the lens distortion parameters and the input image
    CameraPinholeRadial param = CalibrationIO.load(new File(directory, "intrinsic.yaml"));
    LensDistortionNarrowFOV lensDistortion = new LensDistortionRadialTangential(param);
    BufferedImage input = UtilImageIO.loadImage(directory, "image0000.jpg");
    // BufferedImage input = UtilImageIO.loadImage(directory , "image0001.jpg");
    // BufferedImage input = UtilImageIO.loadImage(directory , "image0002.jpg");
    GrayF32 original = ConvertBufferedImage.convertFrom(input, true, ImageType.single(GrayF32.class));
    // Detect the fiducial
    FiducialDetector<GrayF32> detector = FactoryFiducial.squareBinary(new ConfigFiducialBinary(0.1), ConfigThreshold.local(ThresholdType.LOCAL_MEAN, 21), GrayF32.class);
    // new ConfigFiducialBinary(0.1), ConfigThreshold.fixed(100),GrayF32.class);
    detector.setLensDistortion(lensDistortion, param.width, param.height);
    detector.detect(original);
    // print the results
    Graphics2D g2 = input.createGraphics();
    Se3_F64 targetToSensor = new Se3_F64();
    Point2D_F64 locationPixel = new Point2D_F64();
    Polygon2D_F64 bounds = new Polygon2D_F64();
    for (int i = 0; i < detector.totalFound(); i++) {
        detector.getCenter(i, locationPixel);
        detector.getBounds(i, bounds);
        g2.setColor(new Color(50, 50, 255));
        g2.setStroke(new BasicStroke(10));
        VisualizeShapes.drawPolygon(bounds, true, 1.0, g2);
        if (detector.hasUniqueID())
            System.out.println("Target ID = " + detector.getId(i));
        if (detector.hasMessage())
            System.out.println("Message   = " + detector.getMessage(i));
        System.out.println("2D Image Location = " + locationPixel);
        if (detector.is3D()) {
            detector.getFiducialToCamera(i, targetToSensor);
            System.out.println("3D Location:");
            System.out.println(targetToSensor);
            VisualizeFiducial.drawCube(targetToSensor, param, detector.getWidth(i), 3, g2);
            VisualizeFiducial.drawLabelCenter(targetToSensor, param, "" + detector.getId(i), g2);
        } else {
            VisualizeFiducial.drawLabel(locationPixel, "" + detector.getId(i), g2);
        }
    }
    ShowImages.showWindow(input, "Fiducials", true);
}
Also used : ConfigFiducialBinary(boofcv.factory.fiducial.ConfigFiducialBinary) LensDistortionNarrowFOV(boofcv.alg.distort.LensDistortionNarrowFOV) BufferedImage(java.awt.image.BufferedImage) ConvertBufferedImage(boofcv.io.image.ConvertBufferedImage) Polygon2D_F64(georegression.struct.shapes.Polygon2D_F64) LensDistortionRadialTangential(boofcv.alg.distort.radtan.LensDistortionRadialTangential) GrayF32(boofcv.struct.image.GrayF32) CameraPinholeRadial(boofcv.struct.calib.CameraPinholeRadial) Point2D_F64(georegression.struct.point.Point2D_F64) File(java.io.File) Se3_F64(georegression.struct.se.Se3_F64)

Aggregations

Polygon2D_F64 (georegression.struct.shapes.Polygon2D_F64)79 Test (org.junit.Test)40 Point2D_F64 (georegression.struct.point.Point2D_F64)13 ArrayList (java.util.ArrayList)9 GrayU8 (boofcv.struct.image.GrayU8)6 Rectangle2D_I32 (georegression.struct.shapes.Rectangle2D_I32)6 ConvertBufferedImage (boofcv.io.image.ConvertBufferedImage)5 BufferedImage (java.awt.image.BufferedImage)5 GrowQueue_B (org.ddogleg.struct.GrowQueue_B)5 Point2D_I32 (georegression.struct.point.Point2D_I32)4 PixelTransformAffine_F32 (boofcv.alg.distort.PixelTransformAffine_F32)3 DetectPolygonFromContour (boofcv.alg.shapes.polygon.DetectPolygonFromContour)3 GrayF32 (boofcv.struct.image.GrayF32)3 Affine2D_F32 (georegression.struct.affine.Affine2D_F32)3 Se3_F64 (georegression.struct.se.Se3_F64)3 Rectangle2D_F64 (georegression.struct.shapes.Rectangle2D_F64)3 File (java.io.File)3 LensDistortionNarrowFOV (boofcv.alg.distort.LensDistortionNarrowFOV)2 LensDistortionRadialTangential (boofcv.alg.distort.radtan.LensDistortionRadialTangential)2 SquareNode (boofcv.alg.fiducial.calib.squares.SquareNode)2