Difference between revisions of "Example Detect Describe Interface"

From BoofCV
Jump to navigationJump to search
(Created page with "BoofCV provides multiple ways to detect and describe interest points inside of images. The easiest high level interface to work with is DetectDescribePoint. It will detect a...")
 
m
Line 2: Line 2:


Example Code:
Example Code:
* [https://github.com/lessthanoptimal/BoofCV/blob/v0.12/examples/src/boofcv/examples/ExampleDetectDescribe.java ExampleDetectDescribe.java]
* [https://github.com/lessthanoptimal/BoofCV/blob/v0.13/examples/src/boofcv/examples/ExampleDetectDescribe.java ExampleDetectDescribe.java]


Concepts:
Concepts:
Line 23: Line 23:
  * where individual algorithms are used for feature detection, orientation estimation, and describe.  It also
  * where individual algorithms are used for feature detection, orientation estimation, and describe.  It also
  * simplifies the code.
  * simplifies the code.
*
* This example demonstrates how to create instances, but the {@link ExampleAssociatePoints} demonstrates how
* to use the interface.
  *
  *
  * @author Peter Abeles
  * @author Peter Abeles
Line 32: Line 35:
* in situations where there was a performance advantage or that it was a very common combination.
* in situations where there was a performance advantage or that it was a very common combination.
*/
*/
public static <T extends ImageSingleBand, D extends TupleDesc>
public static <T extends ImageSingleBand, TD extends TupleDesc>
DetectDescribePoint<T,D> createFromPremade( Class<T> imageType ) {
DetectDescribePoint<T, TD> createFromPremade( Class<T> imageType ) {
return (DetectDescribePoint)FactoryDetectDescribe.surf(1, 2, 200, 1, 9, 4, 4,true,imageType);
return (DetectDescribePoint)FactoryDetectDescribe.surfStable(
new ConfigFastHessian(1, 2, 200, 1, 9, 4, 4), null,null, ImageFloat32.class);
// note that SIFT only supports ImageFloat32
// note that SIFT only supports ImageFloat32
// if( imageType == ImageFloat32.class )
// if( imageType == ImageFloat32.class )
// return (DetectDescribePoint)FactoryDetectDescribe.sift(4,2,false,-1);
// return (DetectDescribePoint)FactoryDetectDescribe.sift(null,new ConfigSiftDetector(2,0,200,5),null,null);
// else
// else
// throw new RuntimeException("Unsupported image type");
// throw new RuntimeException("Unsupported image type");
Line 47: Line 51:
* This should only be done if there isn't a pre-made DetectDescribePoint.
* This should only be done if there isn't a pre-made DetectDescribePoint.
*/
*/
public static <T extends ImageSingleBand, D extends ImageSingleBand, TD extends TupleDesc>
public static <T extends ImageSingleBand, TD extends TupleDesc>
DetectDescribePoint<T, TD> createFromComponents( Class<T> imageType ) {
DetectDescribePoint<T, TD> createFromComponents( Class<T> imageType ) {
// create a corner detector
// create a corner detector
Class<D> derivType = GImageDerivativeOps.getDerivativeType(imageType);
Class derivType = GImageDerivativeOps.getDerivativeType(imageType);
GeneralFeatureDetector<T,D> corner = FactoryDetectPoint.createShiTomasi(2, false, 1, 300, derivType);
GeneralFeatureDetector corner = FactoryDetectPoint.createShiTomasi(new ConfigGeneralDetector(1000,5,1), false, derivType);
InterestPointDetector detector = FactoryInterestPoint.wrapPoint(corner, 1, imageType, derivType);


// describe points using BRIEF
// describe points using BRIEF
DescribeRegionPoint describe = FactoryDescribeRegionPoint.brief(16, 512, -1, 4, true, imageType);
DescribeRegionPoint describe = FactoryDescribeRegionPoint.brief(new ConfigBrief(true), imageType);


// Combine together.
// Combine together.
// NOTE: orientation will not be estimated
// NOTE: orientation will not be estimated
return FactoryDetectDescribe.fuseTogether(corner, null, describe,1,imageType,derivType);
return FactoryDetectDescribe.fuseTogether(detector, null, describe);
}
}


public static void main( String args[] ) {
public static void main( String args[] ) {


// select which feature to use
Class imageType = ImageFloat32.class;
DetectDescribePoint<ImageFloat32,?> detDesc = createFromPremade(ImageFloat32.class);
 
// DetectDescribePoint<ImageFloat32,?> detDesc = createFromComponents(ImageFloat32.class);
DetectDescribePoint detDesc = createFromPremade(imageType);
// DetectDescribePoint detDesc = createFromComponents(imageType);


// Load an image
// Might as well have this example do something useful, like associate two images
BufferedImage buffered = UtilImageIO.loadImage("../data/evaluation/outdoors01.jpg");
ScoreAssociation scorer = FactoryAssociation.defaultScore(detDesc.getDescriptionType());
ImageFloat32 input = ConvertBufferedImage.convertFrom(buffered,(ImageFloat32)null);
AssociateDescription associate = FactoryAssociation.greedy(scorer, Double.MAX_VALUE, true);


// detect features inside the image
// load and match images
detDesc.detect(input);
ExampleAssociatePoints app = new ExampleAssociatePoints(detDesc,associate,imageType);


// print how out many were found
BufferedImage imageA = UtilImageIO.loadImage("../data/evaluation/stitch/kayak_01.jpg");
System.out.println("Found "+detDesc.getNumberOfFeatures());
BufferedImage imageB = UtilImageIO.loadImage("../data/evaluation/stitch/kayak_03.jpg");


// print out info for the first feature
app.associate(imageA,imageB);
System.out.println("Properties of first feature:");
System.out.println("Location: "+detDesc.getLocation(0));
System.out.println("Scale: "+detDesc.getScale(0));
System.out.println("Orientation: "+detDesc.getOrientation(0));
System.out.println("Descriptor: "+detDesc.getDescriptor(0));
}
}
}
}
</syntaxhighlight>
</syntaxhighlight>

Revision as of 14:08, 16 February 2013

BoofCV provides multiple ways to detect and describe interest points inside of images. The easiest high level interface to work with is DetectDescribePoint. It will detect and describe all interest points in the image at the same time. The alternative involves using separate interfaces for detection, orientation, and describing.

Example Code:

Concepts:

  • Interest point detection
  • Local region descriptors

Relevant Applets:

Related Examples

Example Code

/**
 * {@link DetectDescribePoint} provides a single unified interface for detecting interest points inside of images
 * and describing the features. For some features (e.g. SIFT) it can be much faster than the alternative approach
 * where individual algorithms are used for feature detection, orientation estimation, and describe.  It also
 * simplifies the code.
 *
 * This example demonstrates how to create instances, but the {@link ExampleAssociatePoints} demonstrates how
 * to use the interface.
 *
 * @author Peter Abeles
 */
public class ExampleDetectDescribe {

	/**
	 * For some features, there are pre-made implementations of DetectDescribePoint.  This has only been done
	 * in situations where there was a performance advantage or that it was a very common combination.
	 */
	public static <T extends ImageSingleBand, TD extends TupleDesc>
	DetectDescribePoint<T, TD> createFromPremade( Class<T> imageType ) {
		return (DetectDescribePoint)FactoryDetectDescribe.surfStable(
				new ConfigFastHessian(1, 2, 200, 1, 9, 4, 4), null,null, ImageFloat32.class);
		// note that SIFT only supports ImageFloat32
//		if( imageType == ImageFloat32.class )
//			return (DetectDescribePoint)FactoryDetectDescribe.sift(null,new ConfigSiftDetector(2,0,200,5),null,null);
//		else
//			throw new RuntimeException("Unsupported image type");
	}

	/**
	 * Any arbitrary implementation of InterestPointDetector, OrientationImage, DescribeRegionPoint
	 * can be combined into DetectDescribePoint.  The syntax is more complex, but the end result is more flexible.
	 * This should only be done if there isn't a pre-made DetectDescribePoint.
	 */
	public static <T extends ImageSingleBand, TD extends TupleDesc>
	DetectDescribePoint<T, TD> createFromComponents( Class<T> imageType ) {
		// create a corner detector
		Class derivType = GImageDerivativeOps.getDerivativeType(imageType);
		GeneralFeatureDetector corner = FactoryDetectPoint.createShiTomasi(new ConfigGeneralDetector(1000,5,1), false, derivType);
		InterestPointDetector detector = FactoryInterestPoint.wrapPoint(corner, 1, imageType, derivType);

		// describe points using BRIEF
		DescribeRegionPoint describe = FactoryDescribeRegionPoint.brief(new ConfigBrief(true), imageType);

		// Combine together.
		// NOTE: orientation will not be estimated
		return FactoryDetectDescribe.fuseTogether(detector, null, describe);
	}

	public static void main( String args[] ) {

		Class imageType = ImageFloat32.class;

		DetectDescribePoint detDesc = createFromPremade(imageType);
//		DetectDescribePoint detDesc = createFromComponents(imageType);

		// Might as well have this example do something useful, like associate two images
		ScoreAssociation scorer = FactoryAssociation.defaultScore(detDesc.getDescriptionType());
		AssociateDescription associate = FactoryAssociation.greedy(scorer, Double.MAX_VALUE, true);

		// load and match images
		ExampleAssociatePoints app = new ExampleAssociatePoints(detDesc,associate,imageType);

		BufferedImage imageA = UtilImageIO.loadImage("../data/evaluation/stitch/kayak_01.jpg");
		BufferedImage imageB = UtilImageIO.loadImage("../data/evaluation/stitch/kayak_03.jpg");

		app.associate(imageA,imageB);
	}
}