Search in sources :

Example 61 with Point2D_F32

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

the class CommonDetectCalibrationApp method drawNumbers.

public static void drawNumbers(Graphics2D g2, List<Point2D_F64> foundTarget, Point2Transform2_F32 transform, double scale) {
    Font regular = new Font("Serif", Font.PLAIN, 16);
    g2.setFont(regular);
    g2.setStroke(new BasicStroke(2));
    FontRenderContext frc = g2.getFontRenderContext();
    Point2D_F32 adj = new Point2D_F32();
    AffineTransform at = new AffineTransform();
    AffineTransform origTran = g2.getTransform();
    for (int i = 0; i < foundTarget.size(); i++) {
        Point2D_F64 p = foundTarget.get(i);
        if (transform != null) {
            transform.compute((float) p.x, (float) p.y, adj);
        } else {
            adj.set((float) p.x, (float) p.y);
        }
        String text = String.format("%2d", i);
        GlyphVector gv = regular.createGlyphVector(frc, text);
        at.setToTranslation(adj.x * scale, adj.y * scale);
        at.concatenate(origTran);
        g2.setTransform(at);
        for (int j = 0; j < gv.getNumGlyphs(); j++) {
            g2.setColor(Color.BLACK);
            g2.draw(gv.getGlyphOutline(j));
            g2.setColor(Color.GREEN);
            g2.fill(gv.getGlyphOutline(j));
        }
    }
    g2.setTransform(origTran);
}
Also used : GlyphVector(java.awt.font.GlyphVector) Point2D_F64(georegression.struct.point.Point2D_F64) AffineTransform(java.awt.geom.AffineTransform) Point2D_F32(georegression.struct.point.Point2D_F32) FontRenderContext(java.awt.font.FontRenderContext)

Example 62 with Point2D_F32

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

the class GeneralDetectLineTests method obviousLine.

private <T extends ImageGray<T>> void obviousLine(Class<T> imageType) {
    T input = GeneralizedImageOps.createSingleBand(imageType, width, height);
    GImageMiscOps.fillRectangle(input, 30, 0, 0, lineLocation, height);
    DetectLine<T> alg = createAlg(imageType);
    List<LineParametric2D_F32> found = alg.detect(input);
    assertTrue(found.size() >= 1);
    // see if at least one of the lines is within tolerance
    boolean foundMatch = false;
    for (LineParametric2D_F32 l : found) {
        Point2D_F32 p = l.getPoint();
        double angle = l.getAngle();
        if (Math.abs(p.x - lineLocation) < toleranceLocation && ((UtilAngle.dist(Math.PI / 2, angle) <= toleranceAngle) || (UtilAngle.dist(-Math.PI / 2, angle) <= toleranceAngle))) {
            foundMatch = true;
            break;
        }
    }
    assertTrue(foundMatch);
}
Also used : Point2D_F32(georegression.struct.point.Point2D_F32) LineParametric2D_F32(georegression.struct.line.LineParametric2D_F32)

Example 63 with Point2D_F32

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

the class TestShapeFittingOps method createEllipse_F32.

public static List<Point2D_F32> createEllipse_F32(EllipseRotated_F32 ellipse, int numPoints) {
    List<Point2D_F32> sequence = new ArrayList<>();
    for (int i = 0; i < numPoints; i++) {
        double theta = 2.0 * Math.PI * i / numPoints;
        Point2D_F32 p = new Point2D_F32();
        UtilEllipse_F32.computePoint((float) theta, ellipse, p);
        sequence.add(p);
    }
    return sequence;
}
Also used : ArrayList(java.util.ArrayList) Point2D_F32(georegression.struct.point.Point2D_F32)

Example 64 with Point2D_F32

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

the class LocalWeightedHistogramRotRect method computeHistogramBorder.

/**
 * Computes the histogram and skips pixels which are outside the image border
 */
protected void computeHistogramBorder(T image, RectangleRotate_F32 region) {
    for (int i = 0; i < samplePts.size(); i++) {
        Point2D_F32 p = samplePts.get(i);
        squareToImageSample(p.x, p.y, region);
        // make sure its inside the image
        if (!BoofMiscOps.checkInside(image, imageX, imageY)) {
            sampleHistIndex[i] = -1;
        } else {
            // use the slower interpolation which can handle the border
            interpolate.get(imageX, imageY, value);
            int indexHistogram = computeHistogramBin(value);
            sampleHistIndex[i] = indexHistogram;
            histogram[indexHistogram] += weights[i];
        }
    }
}
Also used : Point2D_F32(georegression.struct.point.Point2D_F32)

Example 65 with Point2D_F32

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

the class TrackerMeanShiftComaniciu2003 method updateLocation.

/**
 * Updates the region's location using the standard mean-shift algorithm
 */
protected void updateLocation(T image, RectangleRotate_F32 region) {
    double bestHistScore = Double.MAX_VALUE;
    float bestX = -1, bestY = -1;
    for (int i = 0; i < maxIterations; i++) {
        calcHistogram.computeHistogram(image, region);
        float[] histogram = calcHistogram.getHistogram();
        updateWeights(histogram);
        // the histogram fit doesn't always improve with each mean-shift iteration
        // save the best one and use it later on
        double histScore = distanceHistogram(keyHistogram, histogram);
        if (histScore < bestHistScore) {
            bestHistScore = histScore;
            bestX = region.cx;
            bestY = region.cy;
        }
        List<Point2D_F32> samples = calcHistogram.getSamplePts();
        int[] sampleHistIndex = calcHistogram.getSampleHistIndex();
        // Compute equation 13
        float meanX = 0;
        float meanY = 0;
        float totalWeight = 0;
        for (int j = 0; j < samples.size(); j++) {
            Point2D_F32 samplePt = samples.get(j);
            int histIndex = sampleHistIndex[j];
            if (histIndex < 0)
                continue;
            // compute the weight derived from the Bhattacharyya coefficient.  Equation 10.
            float w = weightHistogram[histIndex];
            meanX += w * samplePt.x;
            meanY += w * samplePt.y;
            totalWeight += w;
        }
        meanX /= totalWeight;
        meanY /= totalWeight;
        // convert to image pixels
        calcHistogram.squareToImageSample(meanX, meanY, region);
        meanX = calcHistogram.imageX;
        meanY = calcHistogram.imageY;
        // see if the change is below the threshold
        boolean done = Math.abs(meanX - region.cx) <= minimumChange && Math.abs(meanY - region.cy) <= minimumChange;
        region.cx = meanX;
        region.cy = meanY;
        if (done) {
            break;
        }
    }
    // use the best location found
    region.cx = bestX;
    region.cy = bestY;
}
Also used : Point2D_F32(georegression.struct.point.Point2D_F32)

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