Search in sources :

Example 1 with Point2D_F32

use of georegression.struct.point.Point2D_F32 in project BoofCV by lessthanoptimal.

the class DisplayPinholeCalibrationPanel method drawFeatures.

private void drawFeatures(Graphics2D g2, double scale) {
    g2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE);
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    CalibrationObservation set = features;
    Point2D_F32 adj = new Point2D_F32();
    if (showOrder) {
        List<Point2D_F64> adjusted;
        if (showUndistorted) {
            adjusted = new ArrayList<>();
            for (PointIndex2D_F64 p : set.points) {
                remove_p_to_p.compute((float) p.x, (float) p.y, adj);
                adjusted.add(new Point2D_F64(adj.x, adj.y));
            }
        } else {
            adjusted = (List) set.points;
        }
        renderOrder(g2, scale, adjusted);
    }
    if (showPoints) {
        g2.setColor(Color.BLACK);
        g2.setStroke(new BasicStroke(3));
        for (PointIndex2D_F64 p : set.points) {
            if (showUndistorted) {
                remove_p_to_p.compute((float) p.x, (float) p.y, adj);
            } else {
                adj.set((float) p.x, (float) p.y);
            }
            VisualizeFeatures.drawCross(g2, adj.x * scale, adj.y * scale, 4);
        }
        g2.setStroke(new BasicStroke(1));
        g2.setColor(Color.RED);
        for (PointIndex2D_F64 p : set.points) {
            if (showUndistorted) {
                remove_p_to_p.compute((float) p.x, (float) p.y, adj);
            } else {
                adj.set((float) p.x, (float) p.y);
            }
            VisualizeFeatures.drawCross(g2, adj.x * scale, adj.y * scale, 4);
        }
    }
    if (showAll) {
        for (CalibrationObservation l : allFeatures) {
            for (PointIndex2D_F64 p : l.points) {
                if (showUndistorted) {
                    remove_p_to_p.compute((float) p.x, (float) p.y, adj);
                } else {
                    adj.set((float) p.x, (float) p.y);
                }
                VisualizeFeatures.drawPoint(g2, adj.x * scale, adj.y * scale, 2, Color.BLUE, false);
            }
        }
    }
    if (showNumbers) {
        if (showUndistorted)
            drawNumbers(g2, set, remove_p_to_p, scale);
        else
            drawNumbers(g2, set, null, scale);
    }
    if (showErrors && results != null) {
        for (int i = 0; i < set.size(); i++) {
            PointIndex2D_F64 p = set.get(i);
            if (showUndistorted) {
                remove_p_to_p.compute((float) p.x, (float) p.y, adj);
            } else {
                adj.set((float) p.x, (float) p.y);
            }
            double r = scale * errorScale * results.pointError[i];
            if (r < 1)
                continue;
            g2.setStroke(new BasicStroke(4));
            g2.setColor(Color.BLACK);
            VisualizeFeatures.drawCircle(g2, adj.x * scale, adj.y * scale, r);
            g2.setStroke(new BasicStroke(2.5f));
            g2.setColor(Color.ORANGE);
            VisualizeFeatures.drawCircle(g2, adj.x * scale, adj.y * scale, r);
        }
    }
}
Also used : Point2D_F64(georegression.struct.point.Point2D_F64) PointIndex2D_F64(boofcv.struct.geo.PointIndex2D_F64) Point2D_F32(georegression.struct.point.Point2D_F32) CalibrationObservation(boofcv.alg.geo.calibration.CalibrationObservation)

Example 2 with Point2D_F32

use of georegression.struct.point.Point2D_F32 in project BoofCV by lessthanoptimal.

the class ImageDeformPointMLS_F32 method interpolateDeformedPoint.

/**
 * Samples the 4 grid points around v and performs bilinear interpolation
 *
 * @param v_x Grid coordinate x-axis, undistorted
 * @param v_y Grid coordinate y-axis, undistorted
 * @param deformed Distorted grid coordinate in image pixels
 */
void interpolateDeformedPoint(float v_x, float v_y, Point2D_F32 deformed) {
    // sample the closest point and x+1,y+1
    int x0 = (int) v_x;
    int y0 = (int) v_y;
    int x1 = x0 + 1;
    int y1 = y0 + 1;
    // make sure the 4 sample points are in bounds
    if (x1 >= gridCols)
        x1 = gridCols - 1;
    if (y1 >= gridRows)
        y1 = gridRows - 1;
    // weight along each axis
    float ax = v_x - x0;
    float ay = v_y - y0;
    // bilinear weight for each sample point
    float w00 = (1.0f - ax) * (1.0f - ay);
    float w01 = ax * (1.0f - ay);
    float w11 = ax * ay;
    float w10 = (1.0f - ax) * ay;
    // apply weights to each sample point
    Point2D_F32 d00 = getGrid(y0, x0).deformed;
    Point2D_F32 d01 = getGrid(y0, x1).deformed;
    Point2D_F32 d10 = getGrid(y1, x0).deformed;
    Point2D_F32 d11 = getGrid(y1, x1).deformed;
    deformed.set(0, 0);
    deformed.x += w00 * d00.x;
    deformed.x += w01 * d01.x;
    deformed.x += w11 * d11.x;
    deformed.x += w10 * d10.x;
    deformed.y += w00 * d00.y;
    deformed.y += w01 * d01.y;
    deformed.y += w11 * d11.y;
    deformed.y += w10 * d10.y;
}
Also used : Point2D_F32(georegression.struct.point.Point2D_F32)

Example 3 with Point2D_F32

use of georegression.struct.point.Point2D_F32 in project BoofCV by lessthanoptimal.

the class ImageDistortCache_SB method applyOnlyInside.

public void applyOnlyInside() {
    float maxWidth = srcImg.getWidth() - 1;
    float maxHeight = srcImg.getHeight() - 1;
    for (int y = y0; y < y1; y++) {
        int indexDst = dstImg.startIndex + dstImg.stride * y + x0;
        for (int x = x0; x < x1; x++, indexDst++) {
            Point2D_F32 s = map[indexDst];
            if (s.x >= 0 && s.x <= maxWidth && s.y >= 0 && s.y <= maxHeight) {
                assign(indexDst, interp.get(s.x, s.y));
            }
        }
    }
}
Also used : Point2D_F32(georegression.struct.point.Point2D_F32)

Example 4 with Point2D_F32

use of georegression.struct.point.Point2D_F32 in project BoofCV by lessthanoptimal.

the class ImageDistortCache_SB method init.

private void init(Input srcImg, Output dstImg) {
    if (dirty || width != dstImg.width || height != dstImg.height) {
        width = dstImg.width;
        height = dstImg.height;
        map = new Point2D_F32[width * height];
        for (int i = 0; i < map.length; i++) {
            map[i] = new Point2D_F32();
        }
        int index = 0;
        for (int y = 0; y < height; y++) {
            for (int x = 0; x < width; x++) {
                dstToSrc.compute(x, y);
                map[index++].set(dstToSrc.distX, dstToSrc.distY);
            }
        }
        dirty = false;
    } else if (dstImg.width != width || dstImg.height != height)
        throw new IllegalArgumentException("Unexpected dstImg dimension");
    this.srcImg = srcImg;
    this.dstImg = dstImg;
    interp.setImage(srcImg);
}
Also used : Point2D_F32(georegression.struct.point.Point2D_F32)

Example 5 with Point2D_F32

use of georegression.struct.point.Point2D_F32 in project BoofCV by lessthanoptimal.

the class TestImageDeformPointMLS_F32 method multipleCallsToFixate.

/**
 * Should produce identical results when fixate is called multiple times
 */
@Test
public void multipleCallsToFixate() {
    for (TypeDeformMLS type : TypeDeformMLS.values()) {
        ImageDeformPointMLS_F32 alg = new ImageDeformPointMLS_F32(type);
        alg.configure(width, height, rows, cols);
        alg.addControl(5, 5);
        alg.addControl(10, 20);
        alg.addControl(30, 50);
        alg.addControl(16, 0);
        alg.setDistorted(0, 10, 12);
        alg.setDistorted(1, 14, 30);
        alg.setDistorted(2, 25, 45);
        alg.setDistorted(3, 20, 8);
        alg.fixateUndistorted();
        alg.fixateDistorted();
        Point2D_F32 expected = new Point2D_F32();
        alg.compute(4, 4, expected);
        Point2D_F32 found = new Point2D_F32();
        alg.fixateDistorted();
        alg.compute(4, 4, found);
        assertTrue(found.distance(expected) <= GrlConstants.TEST_F32);
        alg.fixateUndistorted();
        alg.fixateDistorted();
        alg.compute(4, 4, found);
        assertTrue(found.distance(expected) <= GrlConstants.TEST_F32);
    }
}
Also used : Point2D_F32(georegression.struct.point.Point2D_F32) Test(org.junit.Test)

Aggregations

Point2D_F32 (georegression.struct.point.Point2D_F32)98 Test (org.junit.Test)36 Point3D_F32 (georegression.struct.point.Point3D_F32)10 Point2Transform2_F32 (boofcv.struct.distort.Point2Transform2_F32)9 LineSegment2D_F32 (georegression.struct.line.LineSegment2D_F32)8 ArrayList (java.util.ArrayList)8 Point2D_F64 (georegression.struct.point.Point2D_F64)7 FMatrixRMaj (org.ejml.data.FMatrixRMaj)7 CameraPinholeRadial (boofcv.struct.calib.CameraPinholeRadial)5 LineParametric2D_F32 (georegression.struct.line.LineParametric2D_F32)5 Point2Transform3_F32 (boofcv.struct.distort.Point2Transform3_F32)4 Point3Transform2_F32 (boofcv.struct.distort.Point3Transform2_F32)4 GrayF32 (boofcv.struct.image.GrayF32)4 ClosestPoint2D_F32 (georegression.metric.ClosestPoint2D_F32)4 PointToPixelTransform_F32 (boofcv.alg.distort.PointToPixelTransform_F32)3 CameraPinhole (boofcv.struct.calib.CameraPinhole)3 GrayU8 (boofcv.struct.image.GrayU8)3 PixelTransformCached_F32 (boofcv.alg.distort.PixelTransformCached_F32)2 PinholePtoN_F32 (boofcv.alg.distort.pinhole.PinholePtoN_F32)2 CalibrationObservation (boofcv.alg.geo.calibration.CalibrationObservation)2