Introduction
BoofCV is a new real time computer vision library written in Java. Written from scratch for ease of use and high performance, it provides a range of functionality from low level image processing, wavelet denoising, to higher level 3D geometric vision. Released under an Apache license for both academic and commercial use. BoofCV's speed has been demonstrated in a couple of comparative studies against other popular computer vision libraries (link).
This article will demonstrate how to detect image features and associate two images together. Image association is a vital component in creating image mosaics, image stabilization, visual odometry, 3D structure estimation, and many other applications. BoofCV's website contains several other tutorials, applets, and example code.
Since this article was written BoofCV is at version 0.7 as of April 2012. With many new features and performance improvements!
Website: http://boofcv.org
Version: Alpha v0.2
Date: December, 1 2011
Author: Peter Abeles
Background
It is assumed that the reader is familiar with basic concepts in computer vision as well as Java development. BoofCV is a very new library, with its first public release in early November 2011. It is undergoing a rapid phase of development. If you like BoofCV please let other people know about it by sharing its webpage with your friends!
Browsing through the code below you might notice that BoofCV makes extensive use of Java generics. Generics allows BoofCV to maintain strong typing and provide easy to use highly abstracted data types. It is recommend that you are familiar with generics before trying to use BoofCV.
Image Registration Example
BoofCV provides several different ways to register images. Most of them fall under the category of interest points. In this context, an interest point is a feature inside the image which can be easily and repeadily recognized between multiple images of the same scene from different points of view. If Java is set up in your browser, then you can see feature association in action by taking a look at this applet:
Feature Association: http://boofcv.org/index.php?title=Applet_Associate_Points
In the example, below the two images are registered to each other in several steps:
- Detect interest points
- Describe interest points
- Associate image features
In the block of code below the class is defined and several classes are passed in. These classes are abstract interfaces which allow several algorithms to be swapped in for each other. New ones can be easily added in the future. While not shown in this example, the un abstracted code is also easy to work with when high performance is required over easy of development.
public class ExampleAssociatePoints<T> {
InterestPointDetector<t> detector;
DescribeRegionPoint<t> describe;
GeneralAssociation<tupledesc_f64> associate;
Class<t> imageType;
public ExampleAssociatePoints(InterestPointDetector<T> detector,
DescribeRegionPoint<T> describe,
GeneralAssociation<TupleDesc_F64> associate,
Class<t> imageType) {
this.detector = detector;
this.describe = describe;
this.associate = associate;
this.imageType = imageType;
}
Below is the meat of the code. Here two images are passed in they are 1) converted into image types that BoofCV can process, 2) interest points are detect, 3) descriptors extracted, 4) features associated, and 5) The results displayed. All within a few lines of code.
public void associate( BufferedImage imageA , BufferedImage imageB )
{
T inputA = ConvertBufferedImage.convertFrom(imageA, null, imageType);
T inputB = ConvertBufferedImage.convertFrom(imageB, null, imageType);
List<Point2D_F64> pointsA = new ArrayList<Point2D_F64>();
List<Point2D_F64> pointsB = new ArrayList<Point2D_F64>();
FastQueue<TupleDesc_F64> descA = new TupleDescQueue(describe.getDescriptionLength(),true);
FastQueue<TupleDesc_F64> descB = new TupleDescQueue(describe.getDescriptionLength(),true);
describeImage(inputA,pointsA,descA);
describeImage(inputB,pointsB,descB);
associate.associate(descA,descB);
AssociationPanel panel = new AssociationPanel(20);
panel.setAssociation(pointsA,pointsB,associate.getMatches());
panel.setImages(imageA,imageB);
ShowImages.showWindow(panel,"Associated Features");
}
Both images are described using a set of feature descriptors. For each detected interest point a feature descriptor is extracted.
private void describeImage(T input, List<point2D_F64> points, FastQueue<tupledesc_f64> descs )
{
detector.detect(input);
describe.setImage(input);
descs.reset();
TupleDesc_F64 desc = descs.pop();
for( int i = 0; i < detector.getNumberOfFeatures(); i++ ) {
Point2D_F64 p = detector.getLocation(i);
double yaw = detector.getOrientation(i);
double scale = detector.getScale(i);
if( describe.process(p.x,p.y,yaw,scale,desc) != null ) {
points.add(p.copy());
desc = descs.pop();
}
}
descs.removeTail();
}
Below is the main function that invokes everything. It specifies the image to process, the image format, and which algorithms to use.
public static void main( String args[] ) {
Class imageType = ImageFloat32.class;
InterestPointDetector detector = FactoryInterestPoint.fastHessian(1, 2, 400, 1, 9, 4, 4);
DescribeRegionPoint describe = FactoryDescribeRegionPoint.surf(true, imageType);
GeneralAssociation<TupleDesc_F64> associate = FactoryAssociation.greedy(new ScoreAssociateEuclideanSq(), 2, -1, true);
ExampleAssociatePoints app = new ExampleAssociatePoints(detector,describe,associate,imageType);
BufferedImage imageA = UtilImageIO.loadImage("../evaluation/data/stitch/kayak_01.jpg");
BufferedImage imageB = UtilImageIO.loadImage("../evaluation/data/stitch/kayak_03.jpg");
app.associate(imageA,imageB);
}
}
Image above shows pairs of detected and associated interest points inside two images at different orientations. That's it for now!