OpenCV 2.4.2

org.opencv.android
Class Utils

java.lang.Object
  extended by org.opencv.android.Utils

public class Utils
extends java.lang.Object


Constructor Summary
Utils()
           
 
Method Summary
static void bitmapToMat(Bitmap bmp, Mat mat)
          Shortened form of the bitmapToMat(bmp, mat, unPremultiplyAlpha=false)
static void bitmapToMat(Bitmap bmp, Mat mat, boolean unPremultiplyAlpha)
          Converts Android Bitmap to OpenCV Mat.
static java.lang.String exportResource(Context context, int resourceId)
           
static java.lang.String exportResource(Context context, int resourceId, java.lang.String dirname)
           
static Mat loadResource(Context context, int resourceId)
           
static Mat loadResource(Context context, int resourceId, int flags)
           
static void matToBitmap(Mat mat, Bitmap bmp)
          Shortened form of the matToBitmap(mat, bmp, premultiplyAlpha=false)
static void matToBitmap(Mat mat, Bitmap bmp, boolean premultiplyAlpha)
          Converts OpenCV Mat to Android Bitmap.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Utils

public Utils()
Method Detail

bitmapToMat

public static void bitmapToMat(Bitmap bmp,
                               Mat mat)
Shortened form of the bitmapToMat(bmp, mat, unPremultiplyAlpha=false)

Parameters:
bmp - is a valid input Bitmap object of the type 'ARGB_8888' or 'RGB_565'.
mat - is a valid output Mat object, it will be reallocated if needed, so it's possible to pass an empty Mat.

bitmapToMat

public static void bitmapToMat(Bitmap bmp,
                               Mat mat,
                               boolean unPremultiplyAlpha)
Converts Android Bitmap to OpenCV Mat.

The function converts an image in the Android Bitmap representation to the OpenCV Mat.
The 'ARGB_8888' and 'RGB_565' input Bitmap formats are supported.
The output Mat is always created of the same size as the input Bitmap and of the 'CV_8UC4' type, it keeps the image in RGBA format.
The function throws an exception if the conversion fails.

Parameters:
bmp - is a valid input Bitmap object of the type 'ARGB_8888' or 'RGB_565'.
mat - is a valid output Mat object, it will be reallocated if needed, so it's possible to pass an empty Mat.
unPremultiplyAlpha - is a flag if the bitmap needs to be converted from alpha premultiplied format (like Android keeps 'ARGB_8888' ones) to regular one. The flag is ignored for 'RGB_565' bitmaps.

exportResource

public static java.lang.String exportResource(Context context,
                                              int resourceId)

exportResource

public static java.lang.String exportResource(Context context,
                                              int resourceId,
                                              java.lang.String dirname)

loadResource

public static Mat loadResource(Context context,
                               int resourceId)
                        throws java.io.IOException
Throws:
java.io.IOException

loadResource

public static Mat loadResource(Context context,
                               int resourceId,
                               int flags)
                        throws java.io.IOException
Throws:
java.io.IOException

matToBitmap

public static void matToBitmap(Mat mat,
                               Bitmap bmp)
Shortened form of the matToBitmap(mat, bmp, premultiplyAlpha=false)

Parameters:
mat - is a valid input Mat object of the types 'CV_8UC1', 'CV_8UC3' or 'CV_8UC4'.
bmp - is a valid Bitmap object of the same size as the Mat m and of type 'ARGB_8888' or 'RGB_565'.

matToBitmap

public static void matToBitmap(Mat mat,
                               Bitmap bmp,
                               boolean premultiplyAlpha)
Converts OpenCV Mat to Android Bitmap.


The function converts an image in the OpenCV Mat representation to the Android Bitmap.
The input Mat object has to be of the types 'CV_8UC1' (gray-scale), 'CV_8UC3' (RGB) or 'CV_8UC4' (RGBA).
The output Bitmap object has to be of the same size as the input Mat and of the types 'ARGB_8888' or 'RGB_565'.
The function throws an exception if the conversion fails.

Parameters:
mat - is a valid input Mat object of the types 'CV_8UC1', 'CV_8UC3' or 'CV_8UC4'.
bmp - is a valid Bitmap object of the same size as the Mat m and of type 'ARGB_8888' or 'RGB_565'.
premultiplyAlpha - is a flag if the Mat needs to be converted to alpha premultiplied format (like Android keeps 'ARGB_8888' bitmaps). The flag is ignored for 'RGB_565' bitmaps.

Official OpenCV 2.4 Documentation