Difference between revisions of "Example Detect Interest Points"

From BoofCV
Jump to navigationJump to search
(Updated for v0.3)
m
 
(17 intermediate revisions by the same user not shown)
Line 1: Line 1:
= Detect Interest Point Example =
<center>
<center>
<gallery widths=600px heights=250px>
<gallery widths=600px heights=250px>
Line 9: Line 7:
Interest points are a general term in computer vision for points in the image that can detected and are relevant for higher level processing.  Interest points are commonly used by image stabilization and structure from motion applications to track how the image changes from frame to frame.  The following example shows how interest points can be detected easily using the InterestPointDetector<T> interface.
Interest points are a general term in computer vision for points in the image that can detected and are relevant for higher level processing.  Interest points are commonly used by image stabilization and structure from motion applications to track how the image changes from frame to frame.  The following example shows how interest points can be detected easily using the InterestPointDetector<T> interface.


InterestPointDetector is a generalized interface that allows the user to switch between different types of interest points.  Functions are provided that can be used to test if it provides scale and/or orientation information on the interest point.  The disadvantages of using this interface is that it prevents tight coupling between algorithms, leading to excessive computations.   
InterestPointDetector is a generalized interface that allows the user to switch between different types of interest points.  Functions are provided that can be used to test if it provides scale and/or orientation information on the interest point.  The disadvantages of using this interface is that it prevents tight coupling between algorithms, leading to excessive computations.  If descriptors are also being computed, consider using the DetectDescribePoint interface instead.
 


Example Code:
Example Code:
* [https://github.com/lessthanoptimal/BoofCV/blob/master/examples/src/boofcv/examples/ExampleInterestPoint.java ExampleInterestPoint.java]
* [https://github.com/lessthanoptimal/BoofCV/blob/v0.40/examples/src/main/java/boofcv/examples/features/ExampleInterestPoint.java ExampleInterestPoint.java]


Concepts:
Concepts:
* Point feature detection
* Point feature detection


Relevant Applets:
Related Examples:
* [[Applet_Point_Detected| Interest Point Detector]]
* [[Example_Detect_Describe_Interface| Detect Describe Interface]]
* [[Example_Feature_Selector_Limit| Feature Selector Limit]]


= Example Code =
= Example Code =
Line 26: Line 24:
public class ExampleInterestPoint {
public class ExampleInterestPoint {


public static <T extends ImageSingleBand>
public static <T extends ImageGray<T>>
void detect( BufferedImage image , Class<T> imageType ) {
void detect( BufferedImage image, Class<T> imageType ) {
T input = ConvertBufferedImage.convertFromSingle(image, null, imageType);
T input = ConvertBufferedImage.convertFromSingle(image, null, imageType);


// Create a Fast Hessian detector from the SURF paper.
// Create a Fast Hessian detector from the SURF paper.
// Other detectors can be used in this example too.
// Other detectors can be used in this example too.
InterestPointDetector<T> detector = FactoryInterestPoint.fastHessian(10, 2, 100, 2, 9, 3, 4);
InterestPointDetector<T> detector = FactoryInterestPoint.fastHessian(
new ConfigFastHessian(10, 2, 100, 2, 9, 3, 4), imageType);


// find interest points in the image
// find interest points in the image
Line 41: Line 40:
}
}


private static <T extends ImageSingleBand> void displayResults(BufferedImage image,
private static <T extends ImageGray<T>>
InterestPointDetector<T> detector)
void displayResults( BufferedImage image, InterestPointDetector<T> detector ) {
{
Graphics2D g2 = image.createGraphics();
Graphics2D g2 = image.createGraphics();
FancyInterestPointRender render = new FancyInterestPointRender();
FancyInterestPointRender render = new FancyInterestPointRender();


double detectorRadius = detector.getCanonicalRadius();
for (int i = 0; i < detector.getNumberOfFeatures(); i++) {
 
for( int i = 0; i < detector.getNumberOfFeatures(); i++ ) {
Point2D_F64 pt = detector.getLocation(i);
Point2D_F64 pt = detector.getLocation(i);


// note how it checks the capabilities of the detector
// note how it checks the capabilities of the detector
if( detector.hasScale() ) {
if (detector.hasScale()) {
double scale = detector.getScale(i);
int radius = (int)detector.getRadius(i);
render.addCircle((int)pt.x,(int)pt.y,(int)(scale*detectorRadius));
render.addCircle((int)pt.x, (int)pt.y, radius);
} else {
} else {
render.addPoint((int) pt.x, (int) pt.y);
render.addPoint((int)pt.x, (int)pt.y);
}
}
}
}
Line 65: Line 61:
// just draw the features onto the input image
// just draw the features onto the input image
render.draw(g2);
render.draw(g2);
ShowImages.showWindow(image, "Detected Features");
ShowImages.showWindow(image, "Detected Features", true);
}
}


public static void main( String args[] ) {
public static void main( String[] args ) {
BufferedImage image = UtilImageIO.loadImage("../data/evaluation/sunflowers.png");
BufferedImage image = UtilImageIO.loadImageNotNull(UtilIO.pathExample("sunflowers.jpg"));
detect(image, ImageFloat32.class);
detect(image, GrayF32.class);
}
}
}
}
</syntaxhighlight>
</syntaxhighlight>

Latest revision as of 15:07, 2 September 2022

Interest points are a general term in computer vision for points in the image that can detected and are relevant for higher level processing. Interest points are commonly used by image stabilization and structure from motion applications to track how the image changes from frame to frame. The following example shows how interest points can be detected easily using the InterestPointDetector<T> interface.

InterestPointDetector is a generalized interface that allows the user to switch between different types of interest points. Functions are provided that can be used to test if it provides scale and/or orientation information on the interest point. The disadvantages of using this interface is that it prevents tight coupling between algorithms, leading to excessive computations. If descriptors are also being computed, consider using the DetectDescribePoint interface instead.

Example Code:

Concepts:

  • Point feature detection

Related Examples:

Example Code

public class ExampleInterestPoint {

	public static <T extends ImageGray<T>>
	void detect( BufferedImage image, Class<T> imageType ) {
		T input = ConvertBufferedImage.convertFromSingle(image, null, imageType);

		// Create a Fast Hessian detector from the SURF paper.
		// Other detectors can be used in this example too.
		InterestPointDetector<T> detector = FactoryInterestPoint.fastHessian(
				new ConfigFastHessian(10, 2, 100, 2, 9, 3, 4), imageType);

		// find interest points in the image
		detector.detect(input);

		// Show the features
		displayResults(image, detector);
	}

	private static <T extends ImageGray<T>>
	void displayResults( BufferedImage image, InterestPointDetector<T> detector ) {
		Graphics2D g2 = image.createGraphics();
		FancyInterestPointRender render = new FancyInterestPointRender();

		for (int i = 0; i < detector.getNumberOfFeatures(); i++) {
			Point2D_F64 pt = detector.getLocation(i);

			// note how it checks the capabilities of the detector
			if (detector.hasScale()) {
				int radius = (int)detector.getRadius(i);
				render.addCircle((int)pt.x, (int)pt.y, radius);
			} else {
				render.addPoint((int)pt.x, (int)pt.y);
			}
		}
		// make the circle's thicker
		g2.setStroke(new BasicStroke(3));

		// just draw the features onto the input image
		render.draw(g2);
		ShowImages.showWindow(image, "Detected Features", true);
	}

	public static void main( String[] args ) {
		BufferedImage image = UtilImageIO.loadImageNotNull(UtilIO.pathExample("sunflowers.jpg"));
		detect(image, GrayF32.class);
	}
}