Search in sources :

Example 6 with GrowQueue_F64

use of org.ddogleg.struct.GrowQueue_F64 in project BoofCV by lessthanoptimal.

the class FiducialDetection method parseImage.

void parseImage(int index, String[] args) {
    boolean robust = true;
    List<String> paths = new ArrayList<>();
    GrowQueue_F64 sizes = new GrowQueue_F64();
    double borderWidth = 0.25;
    for (; index < args.length; index++) {
        String arg = args[index];
        if (!arg.startsWith("--")) {
            throw new RuntimeException("Expected flags for image fiducial");
        }
        splitFlag(arg);
        if (flagName.compareToIgnoreCase("Robust") == 0) {
            robust = Boolean.parseBoolean(parameters);
        } else if (flagName.compareToIgnoreCase("Image") == 0) {
            String[] words = parameters.split(":");
            if (words.length != 2)
                throw new RuntimeException("Expected two for width and image path");
            sizes.add(Double.parseDouble(words[0]));
            paths.add(words[1]);
        } else if (flagName.compareToIgnoreCase("Border") == 0) {
            borderWidth = Double.parseDouble(parameters);
        } else {
            throw new RuntimeException("Unknown image option " + flagName);
        }
    }
    if (paths.isEmpty())
        throw new RuntimeException("Need to specify patterns");
    System.out.println("image: robust = " + robust + " total patterns = " + paths.size() + " border = " + borderWidth);
    ConfigFiducialImage config = new ConfigFiducialImage();
    config.borderWidthFraction = borderWidth;
    ConfigThreshold configThreshold;
    if (robust)
        configThreshold = ConfigThreshold.local(ThresholdType.LOCAL_MEAN, 21);
    else
        configThreshold = ConfigThreshold.fixed(DEFAULT_THRESHOLD);
    SquareImage_to_FiducialDetector<GrayU8> detector = FactoryFiducial.squareImage(config, configThreshold, GrayU8.class);
    for (int i = 0; i < paths.size(); i++) {
        BufferedImage buffered = UtilImageIO.loadImage(paths.get(i));
        if (buffered == null)
            throw new RuntimeException("Can't find pattern " + paths.get(i));
        GrayU8 pattern = new GrayU8(buffered.getWidth(), buffered.getHeight());
        ConvertBufferedImage.convertFrom(buffered, pattern);
        detector.addPatternImage(pattern, 125, sizes.get(i));
    }
    this.detector = detector;
}
Also used : ArrayList(java.util.ArrayList) GrowQueue_F64(org.ddogleg.struct.GrowQueue_F64) ConfigFiducialImage(boofcv.factory.fiducial.ConfigFiducialImage) BufferedImage(java.awt.image.BufferedImage) ConvertBufferedImage(boofcv.io.image.ConvertBufferedImage) ConfigThreshold(boofcv.factory.filter.binary.ConfigThreshold) GrayU8(boofcv.struct.image.GrayU8)

Example 7 with GrowQueue_F64

use of org.ddogleg.struct.GrowQueue_F64 in project BoofCV by lessthanoptimal.

the class VisualizeTldDetectionApp method drawFerns.

private void drawFerns(Graphics2D g2, int shift) {
    double max = 0;
    double min = Double.MAX_VALUE;
    GrowQueue_F64 value = tracker.getDetection().getStorageMetric();
    java.util.List<ImageRectangle> rects = tracker.getDetection().getStorageRect();
    for (int i = 0; i < value.size; i++) {
        double r = -value.get(i);
        if (r > max) {
            max = r;
        }
        if (r < min) {
            min = r;
        }
    }
    double range = max - min;
    for (int i = 0; i < value.size; i++) {
        double r = value.get(i);
        ImageRectangle rect = rects.get(i);
        int v = (int) (255 * (r - min) / range);
        int rgb = v << shift;
        drawRectangle(g2, rect, new Color(rgb), 3);
    }
}
Also used : ImageRectangle(boofcv.struct.ImageRectangle) GrowQueue_F64(org.ddogleg.struct.GrowQueue_F64)

Example 8 with GrowQueue_F64

use of org.ddogleg.struct.GrowQueue_F64 in project BoofCV by lessthanoptimal.

the class ShapeFittingOps method averageCircle_F64.

/**
 * Computes a circle which has it's center at the mean position of the provided points and radius is equal to the
 * average distance of each point from the center.  While fast to compute the provided circle is not a best
 * fit circle by any reasonable metric, except for special cases.
 *
 * @param points (Input) Set of unordered points. Not modified.
 * @param optional (Optional) Used internally to store the distance of each point from the center.  Can be null.
 * @param outputStorage (Output/Optional) Storage for results.  If null then a new circle instance will be returned.
 * @return The found circle fit.
 */
public static FitData<Circle2D_F64> averageCircle_F64(List<Point2D_F64> points, GrowQueue_F64 optional, FitData<Circle2D_F64> outputStorage) {
    if (outputStorage == null) {
        outputStorage = new FitData<>(new Circle2D_F64());
    }
    if (optional == null) {
        optional = new GrowQueue_F64();
    }
    Circle2D_F64 circle = outputStorage.shape;
    int N = points.size();
    // find center of the circle by computing the mean x and y
    double sumX = 0, sumY = 0;
    for (int i = 0; i < N; i++) {
        Point2D_F64 p = points.get(i);
        sumX += p.x;
        sumY += p.y;
    }
    optional.reset();
    double centerX = circle.center.x = sumX / (double) N;
    double centerY = circle.center.y = sumY / (double) N;
    double meanR = 0;
    for (int i = 0; i < N; i++) {
        Point2D_F64 p = points.get(i);
        double dx = p.x - centerX;
        double dy = p.y - centerY;
        double r = Math.sqrt(dx * dx + dy * dy);
        optional.push(r);
        meanR += r;
    }
    meanR /= N;
    circle.radius = meanR;
    // compute radius variance
    double variance = 0;
    for (int i = 0; i < N; i++) {
        double diff = optional.get(i) - meanR;
        variance += diff * diff;
    }
    outputStorage.error = variance / N;
    return outputStorage;
}
Also used : Circle2D_F64(georegression.struct.trig.Circle2D_F64) Point2D_F64(georegression.struct.point.Point2D_F64) GrowQueue_F64(org.ddogleg.struct.GrowQueue_F64)

Aggregations

GrowQueue_F64 (org.ddogleg.struct.GrowQueue_F64)8 Circle2D_F64 (georegression.struct.trig.Circle2D_F64)4 ArrayList (java.util.ArrayList)3 Test (org.junit.Test)3 BrightFeature (boofcv.struct.feature.BrightFeature)2 ScalePoint (boofcv.struct.feature.ScalePoint)2 Point2D_F64 (georegression.struct.point.Point2D_F64)2 Point2D_I32 (georegression.struct.point.Point2D_I32)2 ConfigFiducialImage (boofcv.factory.fiducial.ConfigFiducialImage)1 ConfigThreshold (boofcv.factory.filter.binary.ConfigThreshold)1 ConvertBufferedImage (boofcv.io.image.ConvertBufferedImage)1 ImageRectangle (boofcv.struct.ImageRectangle)1 GrayF32 (boofcv.struct.image.GrayF32)1 GrayU8 (boofcv.struct.image.GrayU8)1 BufferedImage (java.awt.image.BufferedImage)1