Difference between revisions of "Example Detect Lines"

From BoofCV
Jump to navigationJump to search
(Updated for v0.16)
m
(4 intermediate revisions by the same user not shown)
Line 11: Line 11:


Example Code:
Example Code:
* [https://github.com/lessthanoptimal/BoofCV/blob/v0.16/examples/src/boofcv/examples/features/ExampleLineDetection.java ExampleLineDetection.java]
* [https://github.com/lessthanoptimal/BoofCV/blob/v0.27/examples/src/boofcv/examples/features/ExampleLineDetection.java ExampleLineDetection.java]


Concepts:
Concepts:
Line 17: Line 17:
* Line segment detection
* Line segment detection


Relevant Applets:
Relevant Examples:
* [[Applet Line Detected| Line Detectors]]
* [[Example_Non_Maximum_Suppression| Non-Maximum Suppression]]
* [[Applet_Video_Line_Detection| Lines detected in a video sequence]]


= Example Code =
= Example Code =
Line 30: Line 29:
// adjust the maximum number of found lines in the image
// adjust the maximum number of found lines in the image
private static final int maxLines = 10;
private static final int maxLines = 10;
private static ListDisplayPanel listPanel = new ListDisplayPanel();


/**
/**
Line 38: Line 39:
* @param derivType Type of image derivative.
* @param derivType Type of image derivative.
*/
*/
public static<T extends ImageSingleBand, D extends ImageSingleBand>
public static<T extends ImageGray<T>, D extends ImageGray<D>>
void detectLines( BufferedImage image ,  
void detectLines( BufferedImage image ,  
  Class<T> imageType ,
  Class<T> imageType ,
Line 47: Line 48:


// Comment/uncomment to try a different type of line detector
// Comment/uncomment to try a different type of line detector
DetectLineHoughPolar<T,D> detector = FactoryDetectLineAlgs.houghPolar(3, 30, 2, Math.PI / 180,
DetectLineHoughPolar<T,D> detector = FactoryDetectLineAlgs.houghPolar(
edgeThreshold, maxLines, imageType, derivType);
new ConfigHoughPolar(3, 30, 2, Math.PI / 180,edgeThreshold, maxLines), imageType, derivType);
// DetectLineHoughFoot<T,D> detector = FactoryDetectLineAlgs.houghFoot(3, 8, 5, edgeThreshold,
// DetectLineHoughFoot<T,D> detector = FactoryDetectLineAlgs.houghFoot(
// maxLines, imageType, derivType);
// new ConfigHoughFoot(3, 8, 5, edgeThreshold,maxLines), imageType, derivType);
// DetectLineHoughFootSubimage<T,D> detector = FactoryDetectLineAlgs.houghFootSub(3, 8, 5, edgeThreshold,
// DetectLineHoughFootSubimage<T,D> detector = FactoryDetectLineAlgs.houghFootSub(
// maxLines, 2, 2, imageType, derivType);
// new ConfigHoughFootSubimage(3, 8, 5, edgeThreshold,maxLines, 2, 2), imageType, derivType);


List<LineParametric2D_F32> found = detector.detect(input);
List<LineParametric2D_F32> found = detector.detect(input);
Line 62: Line 63:
gui.setPreferredSize(new Dimension(image.getWidth(),image.getHeight()));
gui.setPreferredSize(new Dimension(image.getWidth(),image.getHeight()));


ShowImages.showWindow(gui,"Found Lines");
listPanel.addItem(gui, "Found Lines");
}
}


Line 72: Line 73:
* @param derivType Type of image derivative.
* @param derivType Type of image derivative.
*/
*/
public static<T extends ImageSingleBand, D extends ImageSingleBand>
public static<T extends ImageGray<T>, D extends ImageGray<D>>
void detectLineSegments( BufferedImage image ,
void detectLineSegments( BufferedImage image ,
Class<T> imageType ,
Class<T> imageType ,
Line 91: Line 92:
gui.setPreferredSize(new Dimension(image.getWidth(),image.getHeight()));
gui.setPreferredSize(new Dimension(image.getWidth(),image.getHeight()));


ShowImages.showWindow(gui,"Found Line Segments");
listPanel.addItem(gui, "Found Line Segments");
}
}
public static void main( String args[] ) {
public static void main( String args[] ) {
BufferedImage input = UtilImageIO.loadImage("../data/evaluation/simple_objects.jpg");
BufferedImage input = UtilImageIO.loadImage(UtilIO.pathExample("simple_objects.jpg"));


detectLines(input,ImageUInt8.class,ImageSInt16.class);
detectLines(input, GrayU8.class, GrayS16.class);


// line segment detection is still under development and only works for F32 images right now
// line segment detection is still under development and only works for F32 images right now
detectLineSegments(input, ImageFloat32.class, ImageFloat32.class);
detectLineSegments(input, GrayF32.class, GrayF32.class);
 
ShowImages.showWindow(listPanel, "Detected Lines", true);
}
}
}
}
</syntaxhighlight>
</syntaxhighlight>

Revision as of 08:41, 17 August 2017

Lines are commonly found in man made environments. They can often be detected in location where other feature cannot due to the environments sparsity. Typical applications are for location targets and for evaluating the 3D structure of a building. Mathematically, a line has no end points and a line detector in BoofCV does not detect end points either. BoofCV does provide ways to detect line segments, which are lines with a beginning and end.

Line and line segment detection is still under development. No highly abstract and simplified interface is provided yet. Even though its under development still, these algorithms are still effective at detecting lines and line segments.

Example Code:

Concepts:

  • Line detection
  • Line segment detection

Relevant Examples:

Example Code

public class ExampleLineDetection {

	// adjusts edge threshold for identifying pixels belonging to a line
	private static final float edgeThreshold = 25;
	// adjust the maximum number of found lines in the image
	private static final int maxLines = 10;

	private static ListDisplayPanel listPanel = new ListDisplayPanel();

	/**
	 * 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");
	}

	/**
	 * Detects segments inside the image
	 *
	 * @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 detectLineSegments( 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
		DetectLineSegmentsGridRansac<T,D> detector = FactoryDetectLineAlgs.lineRansac(40, 30, 2.36, true, imageType, derivType);

		List<LineSegment2D_F32> found = detector.detect(input);

		// display the results
		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("simple_objects.jpg"));

		detectLines(input, GrayU8.class, GrayS16.class);

		// line segment detection is still under development and only works for F32 images right now
		detectLineSegments(input, GrayF32.class, GrayF32.class);

		ShowImages.showWindow(listPanel, "Detected Lines", true);
	}
}