Android support

From BoofCV
Jump to: navigation, search

BoofCV works without modification on Android systems, however to build in image types are not directly compatible with BoofCV. To get around this issue BoofCV provides code in its integration package for converting to and from several Android image types. Support is currently provided for converting Bitmap and NV21 images. These functions are many times faster than trying to convert images using Bitmap's RGB values or through some more convoluted process like NV21->jpeg->Bitmap->BoofCV. Functions have been tested on Android 2.3.3 API and will most likely work on even earlier versions.

To use these additional functions you must either use the precompiled BoofCVAndroid.jar or compile it yourself from source code. Source code for Android integration can be found in the 'boofcv/integration/android' directory. An ant script is provided for compiling the jar file, but needs to be modified so that it points towards your Android API installation.

Having Trouble in Android Studio?

Here are a few common issues with using BoofCV in Android.

  • Don't compile code that's byte compatible with JDK 8
  • Remove conflicting libraries.
  • Look at this working example.

Make sure your 'app/build.gradle' file has the following in it:

// Remove libraries that conflict with libraries already included with Android
configurations {
    all*.exclude group: "xmlpull", module: "xmlpull"
    all*.exclude group: "org.apache.commons", module: "commons-compress"

dependencies {
    ['android', 'core'].each { String a -> compile group: 'org.boofcv', name: a, version: 'ENTER YOUR BOOFCV VERSION HERE' }
    ... other dependencies ...

Usage Examples

A more detailed and working example for processing video images in Android can be found at the link below. Short code snippets are included in this section.

Full Examples:

Converting Bitmap images

    	// Easiest way to convert a Bitmap into a BoofCV type
    	GrayU8 image = ConvertBitmap.bitmapToGray(bitmap, (GrayU8)null, null);
    	// If you are converting a sequence of images it is faster reuse a
    	// previously declare image and buffer
    	byte[] workBuffer = ConvertBitmap.declareStorage(bitmap, null);
    	ConvertBitmap.bitmapToGray(bitmap, image, workBuffer);
    	// Convert back into a Bitmap
    	ConvertBitmap.grayToBitmap(image, bitmap, workBuffer);
    	// another less efficient way
    	bitmap = ConvertBitmap.grayToBitmap(image, Bitmap.Config.ARGB_8888);
    	// Functions are also provided for multi-spectral images
    	Planar<GrayF32> color = ConvertBitmap.bitmapToMS(bitmap, null, GrayF32.class, null);

Converting NV21 Images

Data from camera previews is made available in the NV21 image format.

    	// from NV21 to gray scale
   	// from NV21 to YUV Multi-Spectral

Besides converting images, VisualizeImageData is provided for visualizing

Android Apps

Android demonstration and benchmark applications are available for download from the google play store.

The demonstration visualizes several computer vision algorithms and provides a good estimate on what sort of runtime performance can be expected when using BoofCV on Android. The benchmark application is primarily a diagnostic app and if you submit results helps the BoofCV developers understand how will it performs on different devices. Additional information on each of these apps can be accessed using the links below. Full source is available for both applications.


  • If you try to compile BoofCV in an Android you will get errors due to the swing code. The solution to this problem is to not compile it inside the Android app and instead just link to its jars.
  • Compiler can't find ConvertBitmap? Make sure BoofCVAndroid.jar is included in your project.