Search in sources :

Example 1 with ConfigHoughPolar

use of boofcv.factory.feature.detect.line.ConfigHoughPolar 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 2 with ConfigHoughPolar

use of boofcv.factory.feature.detect.line.ConfigHoughPolar 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)

Aggregations

ConfigHoughPolar (boofcv.factory.feature.detect.line.ConfigHoughPolar)2 ImageLinePanel (boofcv.gui.feature.ImageLinePanel)2 LineParametric2D_F32 (georegression.struct.line.LineParametric2D_F32)2 ConvertBufferedImage (boofcv.io.image.ConvertBufferedImage)1 Point2D_F64 (georegression.struct.point.Point2D_F64)1 BufferedImage (java.awt.image.BufferedImage)1