Boofcv研究:直线目标检测
public class LineDetection {
private static final float edgeThreshold = 25;
private static final int maxLines = 10;
private static ListDisplayPanel listPanel = new ListDisplayPanel();
public static<T extends ImageGray, D extends ImageGray>
void detectLines( BufferedImage image ,
Class<T> imageType ,
Class<D> derivType )
{
T input = ConvertBufferedImage.convertFromSingle(image, null, imageType );
DetectLineHoughPolar<T,D> detector = FactoryDetectLineAlgs.houghPolar(
new ConfigHoughPolar(3, 30, 2, Math.PI / 180,edgeThreshold, maxLines), imageType, derivType);
List<LineParametric2D_F32> found = detector.detect(input);
ImageLinePanel gui = new ImageLinePanel();
gui.setBackground(image);
gui.setLines(found);
gui.setPreferredSize(new Dimension(image.getWidth(),image.getHeight()));
listPanel.addItem(gui, "Found Lines");
}
public static<T extends ImageGray, D extends ImageGray>
void detectLineSegments( BufferedImage image ,
Class<T> imageType ,
Class<D> derivType )
{
T input = ConvertBufferedImage.convertFromSingle(image, null, imageType );
DetectLineSegmentsGridRansac<T,D> detector = FactoryDetectLineAlgs.lineRansac(40, 30, 2.36, true, imageType, derivType);
List<LineSegment2D_F32> found = detector.detect(input);
ImageLinePanel gui = new ImageLinePanel();
gui.setBackground(image);
gui.setLineSegments(found);
gui.setPreferredSize(new Dimension(image.getWidth(),image.getHeight()));
listPanel.addItem(gui, "Found Line Segments");
}
public static void main( String args[] ) {
BufferedImage input = UtilImageIO.loadImage(UtilIO.pathExample("D:\\JavaProject\\Boofcv\\example\\simple_objects.jpg"));
detectLines(input, GrayU8.class, GrayS16.class);
detectLineSegments(input, GrayF32.class, GrayF32.class);
ShowImages.showWindow(listPanel, "Detected Lines", true);
}
}