Difference between revisions of "Android support"

From BoofCV
Jump to navigationJump to search
m
m
Line 1: Line 1:
BoofCV will work without modification on Android systems, however to call image processing routines you will need to convert Bitmap into BoofCV image types.  Converting image using pixel RGB values is extremely slow, instead use the optimized conversion routines.  These routines are provided as an optional add-on in the integration directoryThese routines have been tested on Android 2.3.3 API and will most likely work on even earlier versions.
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->BoofCVFunctions have been tested on Android 2.3.3 API and will most likely work on even earlier versions.


* [http://boofcv.org/javadoc/integration/boofcv/android/ConvertBitmap.html ConvertBitmap JavaDoc]
* [http://boofcv.org/javadoc/integration/boofcv/android/package-summary.html Android JavaDoc]
* Android support provided in BoofCVAndroid.jar
* [http://boofcv.org/javadoc/integration/boofcv/android/ConvertBitmap.html Convert Bitmap]
** Use the pre-compiled jars or see below for compiling it yourself.
* [http://boofcv.org/javadoc/integration/boofcv/android/ConvertNV21.html Convert NV21]


Example:
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.
 
= 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:
* [[Example_Android_Video|Android Video]]
 
== Converting Bitmap images ==
<pre>
<pre>
     // Easiest way to convert a Bitmap into a BoofCV type
     // Easiest way to convert a Bitmap into a BoofCV type
Line 24: Line 33:
     MultiSpectral<ImageFloat32> color = ConvertBitmap.bitmapToMS(bitmap, null, ImageFloat32.class, null);
     MultiSpectral<ImageFloat32> color = ConvertBitmap.bitmapToMS(bitmap, null, ImageFloat32.class, null);
</pre>
</pre>
== Converting NV21 Images ==
Data from camera previews is made available in the NV21 image format.
<pre>
    // from NV21 to gray scale
    ConvertNV21.nv21ToGray(bytes,width,height,gray)
  // from NV21 to YUV Multi-Spectral
    ConvertNV21.nv21ToMsYuv(bytes,width,height,colorMS,ImageUInt8.class);
</pre>
Besides converting images, VisualizeImageData is provided for visualizing


= Diagnostic App =  
= Diagnostic App =  
Line 31: Line 53:
* [[Android_benchmark_app|Benchmark App Wiki]]
* [[Android_benchmark_app|Benchmark App Wiki]]
* [https://play.google.com/store/apps/details?id=boofcv.benchmark.android Benchmark in Play Store]
* [https://play.google.com/store/apps/details?id=boofcv.benchmark.android Benchmark in Play Store]
= Compiling =
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.  A pre-compiled jar is provided at the usual download location.


= Problems? =
= Problems? =

Revision as of 16:20, 16 February 2013

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.

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
    	ImageUInt8 image = ConvertBitmap.bitmapToGray(bitmap, (ImageUInt8)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
    	MultiSpectral<ImageFloat32> color = ConvertBitmap.bitmapToMS(bitmap, null, ImageFloat32.class, null);

Converting NV21 Images

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

    	// from NV21 to gray scale
    	ConvertNV21.nv21ToGray(bytes,width,height,gray)

   	// from NV21 to YUV Multi-Spectral
    	ConvertNV21.nv21ToMsYuv(bytes,width,height,colorMS,ImageUInt8.class);

Besides converting images, VisualizeImageData is provided for visualizing

Diagnostic App

A free diagnostic Android app is available in the Google Play store. The app will run a series of benchmarks and can be used to visually inspect the correctness of conversion routines. To help BoofCV development please submit the results. See the wiki link for more information on the benchmark app.

Problems?

  • 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.