Click here to Skip to main content
13,297,266 members (67,625 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


24 bookmarked
Posted 1 Dec 2011

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.


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!

Version: Alpha v0.2
Date: December, 1 2011
Author: Peter Abeles  

Binary Image Processing Image Registration and Model Fitting Interest Point Detecting  


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:

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

    // Associate features between the two images

    // display the results
    AssociationPanel panel = new AssociationPanel(20);

    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 )

    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 ) {
            desc = descs.pop();
    // remove the last element from the queue, which has not been used.
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 =, 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");



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


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


About the Author

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

You may also be interested in...

Comments and Discussions

Discussions on this specific version of this article. Add your comments on how to improve this article here. These comments will not be visible on the final published version of this article.
QuestionProblem with converting BufferedImage into the type T Pin
Steven Balzary6-May-14 5:51
memberSteven Balzary6-May-14 5:51 
AnswerRe: Problem with converting BufferedImage into the type T Pin
lessthanoptimal20-Jun-14 3:49
memberlessthanoptimal20-Jun-14 3:49 
QuestionConvert stabiliz display activity to multispectral color Pin
mehran_5830-Nov-13 4:39
membermehran_5830-Nov-13 4:39 
AnswerRe: Convert stabiliz display activity to multispectral color Pin
lessthanoptimal2-Dec-13 6:18
memberlessthanoptimal2-Dec-13 6:18 
GeneralRe: Convert stabiliz display activity to multispectral color Pin
mehran_583-Dec-13 7:57
membermehran_583-Dec-13 7:57 
QuestionAmazing Pin
revalo28-Mar-13 4:41
memberrevalo28-Mar-13 4:41 
AnswerRe: Amazing Pin
lessthanoptimal28-Mar-13 6:27
memberlessthanoptimal28-Mar-13 6:27 

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

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

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.171207.1 | Last Updated 7 Jun 2012
Article Copyright 2011 by lessthanoptimal
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid