Search in sources :

Example 11 with LineParametric2D_F32

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

the class LineImageOps method pruneSimilarLines.

/**
 * Prunes similar looking lines, but keeps the lines with the most intensity.
 *
 * @param lines
 * @param intensity
 * @param toleranceAngle
 * @return
 */
public static List<LineParametric2D_F32> pruneSimilarLines(List<LineParametric2D_F32> lines, float[] intensity, float toleranceAngle, float toleranceDist, int imgWidth, int imgHeight) {
    int[] indexSort = new int[intensity.length];
    QuickSort_F32 sort = new QuickSort_F32();
    sort.sort(intensity, 0, lines.size(), indexSort);
    float[] theta = new float[lines.size()];
    List<LineSegment2D_F32> segments = new ArrayList<>(lines.size());
    for (int i = 0; i < lines.size(); i++) {
        LineParametric2D_F32 l = lines.get(i);
        theta[i] = UtilAngle.atanSafe(l.getSlopeY(), l.getSlopeX());
        segments.add(convert(l, imgWidth, imgHeight));
    }
    for (int i = segments.size() - 1; i >= 0; i--) {
        LineSegment2D_F32 a = segments.get(indexSort[i]);
        if (a == null)
            continue;
        for (int j = i - 1; j >= 0; j--) {
            LineSegment2D_F32 b = segments.get(indexSort[j]);
            if (b == null)
                continue;
            if (UtilAngle.distHalf(theta[indexSort[i]], theta[indexSort[j]]) > toleranceAngle)
                continue;
            Point2D_F32 p = Intersection2D_F32.intersection(a, b, null);
            if (p != null && p.x >= 0 && p.y >= 0 && p.x < imgWidth && p.y < imgHeight) {
                segments.set(indexSort[j], null);
            } else {
                float distA = Distance2D_F32.distance(a, b.a);
                float distB = Distance2D_F32.distance(a, b.b);
                if (distA <= toleranceDist || distB < toleranceDist) {
                    segments.set(indexSort[j], null);
                }
            }
        }
    }
    List<LineParametric2D_F32> ret = new ArrayList<>();
    for (int i = 0; i < segments.size(); i++) {
        if (segments.get(i) != null) {
            ret.add(lines.get(i));
        }
    }
    return ret;
}
Also used : QuickSort_F32(org.ddogleg.sorting.QuickSort_F32) LineSegment2D_F32(georegression.struct.line.LineSegment2D_F32) ArrayList(java.util.ArrayList) Point2D_F32(georegression.struct.point.Point2D_F32) ClosestPoint2D_F32(georegression.metric.ClosestPoint2D_F32) LineParametric2D_F32(georegression.struct.line.LineParametric2D_F32)

Example 12 with LineParametric2D_F32

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

the class LineImageOps method pruneRelativeIntensity.

public static List<LineParametric2D_F32> pruneRelativeIntensity(List<LineParametric2D_F32> lines, float[] intensity, float fraction) {
    int[] indexSort = new int[intensity.length];
    QuickSort_F32 sort = new QuickSort_F32();
    sort.sort(intensity, 0, lines.size(), indexSort);
    float threshold = intensity[indexSort[lines.size() - 1]] * fraction;
    List<LineParametric2D_F32> ret = new ArrayList<>();
    for (int i = 0; i < lines.size(); i++) {
        if (intensity[i] >= threshold) {
            ret.add(lines.get(i));
        }
    }
    return ret;
}
Also used : QuickSort_F32(org.ddogleg.sorting.QuickSort_F32) ArrayList(java.util.ArrayList) LineParametric2D_F32(georegression.struct.line.LineParametric2D_F32)

Example 13 with LineParametric2D_F32

use of georegression.struct.line.LineParametric2D_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 14 with LineParametric2D_F32

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

the class ExampleLineDetection method detectLines.

/**
 * Detects lines inside the image using different types of Hough detectors
 *
 * @param image Input image.
 * @param imageType Type of image processed by line detector.
 * @param derivType Type of image derivative.
 */
public static <T extends ImageGray<T>, D extends ImageGray<D>> void detectLines(BufferedImage image, Class<T> imageType, Class<D> derivType) {
    // convert the line into a single band image
    T input = ConvertBufferedImage.convertFromSingle(image, null, imageType);
    // Comment/uncomment to try a different type of line detector
    DetectLineHoughPolar<T, D> detector = FactoryDetectLineAlgs.houghPolar(new ConfigHoughPolar(3, 30, 2, Math.PI / 180, edgeThreshold, maxLines), imageType, derivType);
    // DetectLineHoughFoot<T,D> detector = FactoryDetectLineAlgs.houghFoot(
    // new ConfigHoughFoot(3, 8, 5, edgeThreshold,maxLines), imageType, derivType);
    // DetectLineHoughFootSubimage<T,D> detector = FactoryDetectLineAlgs.houghFootSub(
    // new ConfigHoughFootSubimage(3, 8, 5, edgeThreshold,maxLines, 2, 2), imageType, derivType);
    List<LineParametric2D_F32> found = detector.detect(input);
    // display the results
    ImageLinePanel gui = new ImageLinePanel();
    gui.setBackground(image);
    gui.setLines(found);
    gui.setPreferredSize(new Dimension(image.getWidth(), image.getHeight()));
    listPanel.addItem(gui, "Found Lines");
}
Also used : ConfigHoughPolar(boofcv.factory.feature.detect.line.ConfigHoughPolar) ImageLinePanel(boofcv.gui.feature.ImageLinePanel) LineParametric2D_F32(georegression.struct.line.LineParametric2D_F32)

Example 15 with LineParametric2D_F32

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

the class TestHoughTransformLinePolar method obviousLines.

/**
 * See if it can detect an obvious line in the image
 */
@Test
public void obviousLines() {
    GrayU8 image = new GrayU8(width, height);
    for (int i = 0; i < height; i++) {
        image.set(5, i, 1);
    }
    NonMaxSuppression extractor = FactoryFeatureExtractor.nonmax(new ConfigExtract(4, 5, 0, true));
    HoughTransformLinePolar alg = new HoughTransformLinePolar(extractor, 40, 180);
    alg.transform(image);
    FastQueue<LineParametric2D_F32> lines = alg.extractLines();
    assertTrue(lines.size() > 0);
    for (int i = 0; i < lines.size(); i++) {
        LineParametric2D_F32 l = lines.get(i);
        assertEquals(l.p.x, 5, 0.1);
        assertEquals(Math.abs(l.slope.x), 0, 1e-4);
        assertEquals(Math.abs(l.slope.y), 1, 0.1);
    }
}
Also used : ConfigExtract(boofcv.abst.feature.detect.extract.ConfigExtract) NonMaxSuppression(boofcv.abst.feature.detect.extract.NonMaxSuppression) GrayU8(boofcv.struct.image.GrayU8) LineParametric2D_F32(georegression.struct.line.LineParametric2D_F32) Test(org.junit.Test)

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