Search in sources :

Example 1 with LineParametric2D_F32

use of georegression.struct.line.LineParametric2D_F32 in project BoofCV by lessthanoptimal.

the class GeneralDetectLineTests method subImages.

private <T extends ImageGray<T>> void subImages(Class<T> imageType) {
    T input = GeneralizedImageOps.createSingleBand(imageType, width, height);
    GImageMiscOps.fillRectangle(input, 30, 0, 0, lineLocation, height);
    T sub = BoofTesting.createSubImageOf(input);
    List<LineParametric2D_F32> foundA = createAlg(imageType).detect(input);
    List<LineParametric2D_F32> foundB = createAlg(imageType).detect(sub);
    // the output should be exactly identical
    assertEquals(foundA.size(), foundB.size());
    for (int i = 0; i < foundA.size(); i++) {
        LineParametric2D_F32 a = foundA.get(i);
        LineParametric2D_F32 b = foundB.get(i);
        assertTrue(a.slope.x == b.slope.x);
        assertTrue(a.slope.y == b.slope.y);
        assertTrue(a.p.x == b.p.x);
        assertTrue(a.p.y == b.p.y);
    }
}
Also used : LineParametric2D_F32(georegression.struct.line.LineParametric2D_F32)

Example 2 with LineParametric2D_F32

use of georegression.struct.line.LineParametric2D_F32 in project BoofCV by lessthanoptimal.

the class DetectLineHoughFootSubimage method processSubimage.

private void processSubimage(int x0, int y0, int x1, int y1, List<LineParametric2D_F32> found) {
    D derivX = (D) this.derivX.subimage(x0, y0, x1, y1);
    D derivY = (D) this.derivY.subimage(x0, y0, x1, y1);
    GrayU8 binary = this.binary.subimage(x0, y0, x1, y1);
    alg.transform(derivX, derivY, binary);
    FastQueue<LineParametric2D_F32> lines = alg.extractLines();
    float[] intensity = alg.getFoundIntensity();
    for (int i = 0; i < lines.size; i++) {
        // convert from the sub-image coordinate system to original image coordinate system
        LineParametric2D_F32 l = lines.get(i).copy();
        l.p.x += x0;
        l.p.y += y0;
        found.add(l);
        post.add(l, intensity[i]);
    }
}
Also used : GrayU8(boofcv.struct.image.GrayU8) LineParametric2D_F32(georegression.struct.line.LineParametric2D_F32)

Example 3 with LineParametric2D_F32

use of georegression.struct.line.LineParametric2D_F32 in project BoofCV by lessthanoptimal.

the class DetectLineHoughPolar method detect.

@Override
public List<LineParametric2D_F32> detect(I input) {
    // see if the input image shape has changed.
    if (derivX.width != input.width || derivY.height != input.height) {
        double r = Math.sqrt(input.width * input.width + input.height * input.height);
        int numBinsRange = (int) Math.ceil(r / resolutionRange);
        int numBinsAngle = (int) Math.ceil(Math.PI / resolutionAngle);
        alg = new HoughTransformLinePolar(extractor, numBinsRange, numBinsAngle);
        derivX.reshape(input.width, input.height);
        derivY.reshape(input.width, input.height);
        intensity.reshape(input.width, input.height);
        binary.reshape(input.width, input.height);
        // angle.reshape(input.width, input.height);
        // direction.reshape(input.width, input.height);
        suppressed.reshape(input.width, input.height);
    }
    gradient.process(input, derivX, derivY);
    GGradientToEdgeFeatures.intensityAbs(derivX, derivY, intensity);
    // non-max suppression reduces the number of line pixels, reducing the number of false positives
    // When too many pixels are flagged, then more curves randomly cross over in transform space causing
    // false positives
    // GGradientToEdgeFeatures.direction(derivX, derivY, angle);
    // GradientToEdgeFeatures.discretizeDirection4(angle, direction);
    // GradientToEdgeFeatures.nonMaxSuppression4(intensity,direction, suppressed);
    GGradientToEdgeFeatures.nonMaxSuppressionCrude4(intensity, derivX, derivY, suppressed);
    ThresholdImageOps.threshold(suppressed, binary, thresholdEdge, false);
    alg.transform(binary);
    FastQueue<LineParametric2D_F32> lines = alg.extractLines();
    List<LineParametric2D_F32> ret = new ArrayList<>();
    for (int i = 0; i < lines.size; i++) ret.add(lines.get(i));
    ret = pruneLines(input, ret);
    return ret;
}
Also used : ArrayList(java.util.ArrayList) HoughTransformLinePolar(boofcv.alg.feature.detect.line.HoughTransformLinePolar) LineParametric2D_F32(georegression.struct.line.LineParametric2D_F32)

Example 4 with LineParametric2D_F32

use of georegression.struct.line.LineParametric2D_F32 in project BoofCV by lessthanoptimal.

the class VisualizeHoughPolar method process.

public void process(BufferedImage image) {
    I input = GeneralizedImageOps.createSingleBand(imageType, image.getWidth(), image.getHeight());
    I blur = GeneralizedImageOps.createSingleBand(imageType, image.getWidth(), image.getHeight());
    ConvertBufferedImage.convertFromSingle(image, input, imageType);
    GBlurImageOps.gaussian(input, blur, -1, 2, null);
    DetectLineHoughPolar<I, D> alg = FactoryDetectLineAlgs.houghPolar(new ConfigHoughPolar(5, 10, 2, Math.PI / 180, 25, 10), imageType, derivType);
    List<LineParametric2D_F32> lines = alg.detect(blur);
    ImageLinePanel gui = new ImageLinePanel();
    gui.setBackground(image);
    gui.setLines(lines);
    gui.setPreferredSize(new Dimension(image.getWidth(), image.getHeight()));
    BufferedImage renderedTran = VisualizeImageData.grayMagnitude(alg.getTransform().getTransform(), null, -1);
    BufferedImage renderedBinary = VisualizeBinaryData.renderBinary(alg.getBinary(), false, null);
    // Draw the location of lines onto the magnitude image
    Graphics2D g2 = renderedTran.createGraphics();
    g2.setColor(Color.RED);
    Point2D_F64 location = new Point2D_F64();
    for (LineParametric2D_F32 l : lines) {
        alg.getTransform().lineToCoordinate(l, location);
        int r = 6;
        int w = r * 2 + 1;
        int x = (int) (location.x + 0.5);
        int y = (int) (location.y + 0.5);
        // System.out.println(x+" "+y+"  "+renderedTran.getWidth()+" "+renderedTran.getHeight());
        g2.drawOval(x - r, y - r, w, w);
    }
    ShowImages.showWindow(renderedBinary, "Detected Edges");
    ShowImages.showWindow(renderedTran, "Parameter Space");
    ShowImages.showWindow(gui, "Detected Lines");
}
Also used : ConfigHoughPolar(boofcv.factory.feature.detect.line.ConfigHoughPolar) Point2D_F64(georegression.struct.point.Point2D_F64) ImageLinePanel(boofcv.gui.feature.ImageLinePanel) BufferedImage(java.awt.image.BufferedImage) ConvertBufferedImage(boofcv.io.image.ConvertBufferedImage) LineParametric2D_F32(georegression.struct.line.LineParametric2D_F32)

Example 5 with LineParametric2D_F32

use of georegression.struct.line.LineParametric2D_F32 in project BoofCV by lessthanoptimal.

the class GridRansacLineDetector method convertToLineSegment.

/**
 * Lines are found in polar form and this coverts them into line segments by finding
 * the extreme points of points on the line.
 *
 * @param matchSet Set of points belonging to the line.
 * @param model Detected line.
 * @return Line segement.
 */
private LineSegment2D_F32 convertToLineSegment(List<Edgel> matchSet, LinePolar2D_F32 model) {
    float minT = Float.MAX_VALUE;
    float maxT = -Float.MAX_VALUE;
    LineParametric2D_F32 line = UtilLine2D_F32.convert(model, (LineParametric2D_F32) null);
    Point2D_F32 p = new Point2D_F32();
    for (Edgel e : matchSet) {
        p.set(e.x, e.y);
        float t = ClosestPoint2D_F32.closestPointT(line, e);
        if (minT > t)
            minT = t;
        if (maxT < t)
            maxT = t;
    }
    LineSegment2D_F32 segment = new LineSegment2D_F32();
    segment.a.x = line.p.x + line.slope.x * minT;
    segment.a.y = line.p.y + line.slope.y * minT;
    segment.b.x = line.p.x + line.slope.x * maxT;
    segment.b.y = line.p.y + line.slope.y * maxT;
    return segment;
}
Also used : LineSegment2D_F32(georegression.struct.line.LineSegment2D_F32) Edgel(boofcv.alg.feature.detect.line.gridline.Edgel) Point2D_F32(georegression.struct.point.Point2D_F32) ClosestPoint2D_F32(georegression.metric.ClosestPoint2D_F32) LineParametric2D_F32(georegression.struct.line.LineParametric2D_F32)

Aggregations

LineParametric2D_F32 (georegression.struct.line.LineParametric2D_F32)15 Point2D_F32 (georegression.struct.point.Point2D_F32)5 ArrayList (java.util.ArrayList)4 ClosestPoint2D_F32 (georegression.metric.ClosestPoint2D_F32)3 LineSegment2D_F32 (georegression.struct.line.LineSegment2D_F32)3 ConfigExtract (boofcv.abst.feature.detect.extract.ConfigExtract)2 NonMaxSuppression (boofcv.abst.feature.detect.extract.NonMaxSuppression)2 ConfigHoughPolar (boofcv.factory.feature.detect.line.ConfigHoughPolar)2 ImageLinePanel (boofcv.gui.feature.ImageLinePanel)2 GrayU8 (boofcv.struct.image.GrayU8)2 Point2D_F64 (georegression.struct.point.Point2D_F64)2 Point2D_I16 (georegression.struct.point.Point2D_I16)2 QuickSort_F32 (org.ddogleg.sorting.QuickSort_F32)2 HoughTransformLinePolar (boofcv.alg.feature.detect.line.HoughTransformLinePolar)1 Edgel (boofcv.alg.feature.detect.line.gridline.Edgel)1 ConvertBufferedImage (boofcv.io.image.ConvertBufferedImage)1 BufferedImage (java.awt.image.BufferedImage)1 Test (org.junit.Test)1