Click here to Skip to main content
Click here to Skip to main content

Tagged as

BoofCV: Real Time Computer Vision in Java

, 7 Jun 2012
Rate this:
Please Sign up or sign in to vote.
Introduction to and an example of how to use BoofCV
This is an old version of the currently published article.

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  

boofcv_alpha_v02/200px-Example_binary_labeled.png boofcv_alpha_v02/Example_interestpoint_detected.jpg
Binary Image Processing  Image Registration and Model Fitting  Interest Point Detecting  

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:

  1. Detect interest points
  2. Describe interest points 
  3. 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> {
 
	// algorithm used to detect interest points
	InterestPointDetector<t> detector;
	// algorithm used to describe each interest point based on local pixels
	DescribeRegionPoint<t> describe;
	// Associated descriptions together by minimizing an error metric
	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.
	
	 /**
	 * Detect and associate point features in the two images.  Display the results.
	 */
	public void associate( BufferedImage imageA , BufferedImage imageB )
	{
		T inputA = ConvertBufferedImage.convertFrom(imageA, null, imageType);
		T inputB = ConvertBufferedImage.convertFrom(imageB, null, imageType);
 
		// stores the location of detected interest points
		List<Point2D_F64> pointsA = new ArrayList<Point2D_F64>();
		List<Point2D_F64> pointsB = new ArrayList<Point2D_F64>();
 
		// stores the description of detected interest points
		FastQueue<TupleDesc_F64> descA = new TupleDescQueue(describe.getDescriptionLength(),true);
		FastQueue<TupleDesc_F64> descB = new TupleDescQueue(describe.getDescriptionLength(),true);
 
		// describe each image using interest points
		describeImage(inputA,pointsA,descA);
		describeImage(inputB,pointsB,descB);
 
		// Associate features between the two images
		associate.associate(descA,descB);
 
		// display the results
		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.
 
	/**
	 * Detects features inside the two images and computes descriptions at those points.
	 */
	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++ ) {
			// get the feature location info
			Point2D_F64 p = detector.getLocation(i);
			double yaw = detector.getOrientation(i);
			double scale = detector.getScale(i);
 
			// extract the description and save the results into the provided description
			if( describe.process(p.x,p.y,yaw,scale,desc) != null ) {
				points.add(p.copy());
				desc = descs.pop();
			}
		}
		// remove the last element from the queue, which has not been used.
		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;
 
		// select which algorithms to use
		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);
 
		// load and match images
		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);
	}
}

 

boofcv_alpha_v02/example_matching_mountain.jpg 

Image above shows pairs of detected and associated interest points inside two images at different orientations.  That's it for now!

License

This article, along with any associated source code and files, is licensed under The Apache License, Version 2.0

Share

About the Author

lessthanoptimal

United States United States
Peter Abeles is a researcher in robotics and computer vision. In addition he is the author of several open source projects which include BoofCV, EJML, and JMatBench. His neglected blog can be found at http://peterabeles.com/blog
Follow on   Twitter   Google+

Comments and Discussions


Discussions posted for the Published version of this article. Posting a message here will take you to the publicly available article in order to continue your conversation in public.
 
QuestionProblem with converting BufferedImage into the type T PinmemberSteven Balzary6-May-14 4:51 
AnswerRe: Problem with converting BufferedImage into the type T Pinpremiumlessthanoptimal20-Jun-14 2:49 
QuestionConvert stabiliz display activity to multispectral color Pinmembermehran_5830-Nov-13 3:39 
AnswerRe: Convert stabiliz display activity to multispectral color Pinmemberlessthanoptimal2-Dec-13 5:18 
GeneralRe: Convert stabiliz display activity to multispectral color Pinmembermehran_583-Dec-13 6:57 
QuestionAmazing Pinmemberrevalo28-Mar-13 3:41 
AnswerRe: Amazing Pinmemberlessthanoptimal28-Mar-13 5:27 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web03 | 2.8.140826.1 | Last Updated 7 Jun 2012
Article Copyright 2011 by lessthanoptimal
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid