OpenCV for Unity  2.2.8
Enox Software / Please refer to OpenCV official document(http://docs.opencv.org/3.4.1/index.html) for the details of the argument of the method.
Static Public Member Functions | List of all members
OpenCVForUnity.Utils Class Reference

Static Public Member Functions

static string getVersion ()
 
static void copyFromMat (Mat mat, IntPtr intPtr)
 
static void copyToMat (IntPtr intPtr, Mat mat)
 
static void copyFromMat< T > (Mat mat, IList< T > array)
 
static void copyToMat< T > (IList< T > array, Mat mat)
 
static void copyFromTexture (Texture texture, IntPtr intPtr, int bytesPerPixel)
 
static void copyToTexture (IntPtr intPtr, Texture texture, int bytesPerPixel)
 
static void copyFromTexture< T > (Texture texture, IList< T > array, int bytesPerPixel)
 
static void copyToTexture< T > (IList< T > array, Texture texture, int bytesPerPixel)
 
static void matToTexture2D (Mat mat, Texture2D texture2D)
 
static void matToTexture2D (Mat mat, Texture2D texture2D, Color32[] bufferColors)
 
static void fastMatToTexture2D (Mat mat, Texture2D texture2D, bool flip=true, int flipCode=0, bool flipAfter=false)
 
static void texture2DToMat (Texture2D texture2D, Mat mat)
 
static void fastTexture2DToMat (Texture2D texture2D, Mat mat, bool flip=true, int flipCode=0)
 
static void webCamTextureToMat (WebCamTexture webCamTexture, Mat mat)
 
static void webCamTextureToMat (WebCamTexture webCamTexture, Mat mat, Color32[] bufferColors)
 
static void textureToTexture2D (Texture texture, Texture2D texture2D)
 
static void matToTexture (Mat mat, Texture texture)
 
static void textureToMat (Texture texture, Mat mat)
 
static int getLowLevelGraphicsDeviceType ()
 
static int getLowLevelTextureFormat (Texture texture)
 
static bool isNewLowLevelNativePluginInterface ()
 
static string getFilePath (string filepath, bool refresh=false)
 
static IEnumerator getFilePathAsync (string filepath, Action< string > completed, Action< string, float > progress=null, bool refresh=false)
 
static void setDebugMode (bool debugMode, bool throwException=false)
 

Member Function Documentation

static void OpenCVForUnity.Utils.copyFromMat ( Mat  mat,
IntPtr  intPtr 
)
static

Copies an OpenCV Mat data to a pixel data IntPtr.


This function copies the OpenCV Mat data to the pixel data IntPtr.
The pixel data has to be of the same byte size as the Mat data ([total() * elemSize()] byte).
Because this function doesn't check bounds, is faster than Mat.get().

Parameters
mata Mat object
intPtrthe pixel data has to be of the same byte size as the Mat data ([total() * elemSize()] byte)
static void OpenCVForUnity.Utils.copyFromMat< T > ( Mat  mat,
IList< T >  array 
)
static

Copies an OpenCV Mat data to a pixel data Array.


This function copies the OpenCV Mat data to the pixel data Array.
The pixel data Array has to be of the same byte size as the Mat data ([total() * elemSize()] byte).
Because this function doesn't check bounds, is faster than Mat.get().

Parameters
mata Mat object
arraythe pixel data Array has to be of the same byte size as the Mat data ([total() * elemSize()] byte)
static void OpenCVForUnity.Utils.copyFromTexture ( Texture  texture,
IntPtr  intPtr,
int  bytesPerPixel 
)
static

Copies a Texture pixel data to a pixel data IntPtr using low-level native plugin interface.


This function copies the Texture pixel data to the pixel data IntPtr.
The pixel data has to be of the same byte size as the Texture pixel data ([width * height * bytePerPixel] byte).
This function doesn't check bounds.
This function not implemented yet on OpenGLCore, Direct3D12.

Parameters
texturea Texture object
intPtrthe pixel data has to be of the same byte size as the Texture pixel data ([width * height * bytePerPixel] byte)
bytesPerPixelthe bytes per pixel
static void OpenCVForUnity.Utils.copyFromTexture< T > ( Texture  texture,
IList< T >  array,
int  bytesPerPixel 
)
static

Copies a Texture pixel data to a pixel data Array using low-level native plugin interface.


This function copies the Texture pixel data to the pixel data Array.
The pixel data Array has to be of the same byte size as the Texture pixel data ([width * height * bytePerPixel] byte).
This function doesn't check bounds.
This function not implemented yet on OpenGLCore, Direct3D12.

Parameters
texturea Texture object
arraythe pixel data Array has to be of the same byte size as the Texture pixel data ([width * height * bytePerPixel] byte)
bytesPerPixelthe bytes per pixel
static void OpenCVForUnity.Utils.copyToMat ( IntPtr  intPtr,
Mat  mat 
)
static

Copies a pixel data IntPtr to an OpenCV Mat data.


This function copy the pixel data IntPtr to the OpenCV Mat data.
The Mat object has to be of the same byte size as the pixel data ([total() * elemSize()] byte).
Because this function doesn't check bounds, is faster than Mat.put().

Parameters
intPtra pixel data IntPtr
matthe Mat object has to be of the same byte size as the pixel data ([total() * elemSize()] byte)
static void OpenCVForUnity.Utils.copyToMat< T > ( IList< T >  array,
Mat  mat 
)
static

Copies a pixel data Array to an OpenCV Mat data.


This function copies the pixel data Array to the OpenCV Mat data.
The Mat object has to be of the same byte size as the pixel data Array ([total() * elemSize()] byte).
Because this function doesn't check bounds, is faster than Mat.put().

Parameters
arraya pixel data Array
matthe Mat object has to be of the same byte size as the pixel data Array ([total() * elemSize()] byte)
static void OpenCVForUnity.Utils.copyToTexture ( IntPtr  intPtr,
Texture  texture,
int  bytesPerPixel 
)
static

Copies a pixel data IntPtr to a Texture pixel data using low-level native plugin interface.


This function copies the pixel data IntPtr to the Texture pixel data.
The Texture pixel data has to be of the same byte size as the pixel data ([width * height * bytePerPixel] byte).
This function doesn't check bounds.
This function not implemented yet on OpenGLCore, Direct3D12.

Parameters
intPtra pixel data IntPtr
matthe Texture pixel data has to be of the same byte size as the Pixel data ([width * height * bytePerPixel] byte)
bytesPerPixelthe bytes per pixel
static void OpenCVForUnity.Utils.copyToTexture< T > ( IList< T >  array,
Texture  texture,
int  bytesPerPixel 
)
static

Copies a pixel data Array to a Texture pixel data using low-level native plugin interface.


This function copies the pixel data Array to the Texture pixel data.
The Texture pixel data has to be of the same byte size as the pixel data Array ([width * height * bytePerPixel] byte).
This function doesn't check bounds.
This function not implemented yet on OpenGLCore, Direct3D12.

Parameters
arraya pixel data Array
matthe Texture pixel data has to be of the same byte size as the pixel data Array ([width * height * bytePerPixel] byte)
bytesPerPixelthe bytes per pixel
static void OpenCVForUnity.Utils.fastMatToTexture2D ( Mat  mat,
Texture2D  texture2D,
bool  flip = true,
int  flipCode = 0,
bool  flipAfter = false 
)
static

Fast converts OpenCV Mat to Unity Texture2D.(Unity5.3+)


This function converts the OpenCV Mat to the Unity Texture2D image.
Passed Mat data should be of required size to fill the whole texture according to its width, height, data format and mipmapCount.
This function doesn't check bounds.

Parameters
mat
texture2DThe Texture2D object has to be of the same size as the Mat (width * height).
flipif true, the mat is fliped before converting.
flipCodea flag to specify how to flip the array; 0 means flipping around the x-axis and positive value (for example, 1) means flipping around y-axis. Negative value (for example, -1) means flipping around both axes.
flipAfterif true, the mat is fliped after converting.
static void OpenCVForUnity.Utils.fastTexture2DToMat ( Texture2D  texture2D,
Mat  mat,
bool  flip = true,
int  flipCode = 0 
)
static

Fast converts Unity Texture2D to OpenCV Mat.(Unity5.1+)


This function converts the Unity Texture2D image to the OpenCV Mat.
Mat data size must be the same as the texture data size.
This function doesn't check bounds.

Parameters
texture2D
matthe Mat object has to be of the same size as the Texture2D'(width * height).
flipif true, the mat is fliped after converting.
flipCodea flag to specify how to flip the array; 0 means flipping around the x-axis and positive value (for example, 1) means flipping around y-axis. Negative value (for example, -1) means flipping around both axes.
static string OpenCVForUnity.Utils.getFilePath ( string  filepath,
bool  refresh = false 
)
static

Gets the readable path of a file in the "StreamingAssets" folder.


Set a relative file path from the starting point of the "StreamingAssets" folder. e.g. "foobar.txt" or "hogehoge/foobar.txt".
[Android]The target file that exists in the "StreamingAssets" folder is copied into the folder of the Application.persistentDataPath. If refresh flag is false, when the file has already been copied, the file is not copied. If refresh flag is true, the file is always copyied.
[WebGL]If the target file has not yet been copied to WebGL's virtual filesystem, you need to use getFilePathAsync() at first.

Parameters
filepatha relative file path starting from "StreamingAssets" folder
refresh[Android]If refresh flag is false, when the file has already been copied, the file is not copied. If refresh flag is true, the file is always copyied.
Returns
returns the file path in case of success and returns empty in case of error.
static IEnumerator OpenCVForUnity.Utils.getFilePathAsync ( string  filepath,
Action< string >  completed,
Action< string, float >  progress = null,
bool  refresh = false 
)
static

Gets the readable path of a file in the "StreamingAssets" folder by using coroutines.


Set a relative file path from the starting point of the "StreamingAssets" folder. e.g. "foobar.txt" or "hogehoge/foobar.txt".
[Android]The target file that exists in the "StreamingAssets" folder is copied into the folder of the Application.persistentDataPath. If refresh flag is false, when the file has already been copied, the file is not copied. If refresh flag is true, the file is always copyied.
[WebGL]The target file in the "StreamingAssets" folder is copied to the WebGL's virtual filesystem. If refresh flag is false, when the file has already been copied, the file is not copied. If refresh flag is true, the file is always copyied.

Parameters
filepatha relative file path starting from "StreamingAssets" folder
completeda callback function that is called when process is completed. Returns the file path in case of success and returns empty in case of error.
progressa callback function that is called when process is progress. Returns the file path and a value of 0 to 1.
refresh[Android][WebGL]If refresh flag is false, when the file has already been copied, the file is not copied. If refresh flag is true, the file is always copyied.
static int OpenCVForUnity.Utils.getLowLevelGraphicsDeviceType ( )
static

Returns the low level graphics API type used by the graphics device. (using low-level native plugin interface)


This function not implemented yet on OpenGLCore, Direct3D12.


http://docs.unity3d.com/Manual/NativePluginInterface.html
kUnityGfxRendererOpenGL = 0, // Desktop OpenGL
kUnityGfxRendererD3D9 = 1, // Direct3D 9
kUnityGfxRendererD3D11 = 2, // Direct3D 11
kUnityGfxRendererGCM = 3, // PlayStation 3
kUnityGfxRendererNull = 4, // "null" device (used in batch mode)
kUnityGfxRendererXenon = 6, // Xbox 360
kUnityGfxRendererOpenGLES20 = 8, // OpenGL ES 2.0
kUnityGfxRendererOpenGLES30 = 11, // OpenGL ES 3.0
kUnityGfxRendererGXM = 12, // PlayStation Vita
kUnityGfxRendererPS4 = 13, // PlayStation 4
kUnityGfxRendererXboxOne = 14, // Xbox One
kUnityGfxRendererMetal = 16, // iOS Metal
kUnityGfxRendererD3D12 = 18, // Direct3D 12

Returns
the graphics API type
static int OpenCVForUnity.Utils.getLowLevelTextureFormat ( Texture  texture)
static

Returns the low level texture format of a Texture. (using low-level native plugin interface)


This function not implemented yet on OpenGLCore, Direct3D12.
Direct3D 9 D3DFORMAT (Win)
Direct3D 11 DXGI_FORMAT (Win WindowsPhone)
OpenGL internalFormat (Win OSX)
OpenGLES always return -1 (Android iOS)
Metal MTLPixelFormat (iOS)

Parameters
texturea Texture object
Returns
the low level texture format
static string OpenCVForUnity.Utils.getVersion ( )
static

Returns this "OpenCV for Unity" version number.

Returns
this "OpenCV for Unity" version number
static bool OpenCVForUnity.Utils.isNewLowLevelNativePluginInterface ( )
static

Indicates whether is new low level native plugin interface.


http://docs.unity3d.com/Manual/NativePluginInterface.html

Returns
true, if it is new low level native plugin interface false otherwise.
static void OpenCVForUnity.Utils.matToTexture ( Mat  mat,
Texture  texture 
)
static

Converts OpenCV Mat to Unity Texture using low-level native plugin interface.


This function converts the OpenCV Mat to the Unity Texture image using low-level native plugin interface.
The Mat object has to be of the types 'CV_8UC4' (RGBA).
The Texture object has to be of the TextureFormat 'RGBA32' or 'ARGB32'.
The Texture object has to be of the same size as the Mat'(width * height).
This function not implemented yet on OpenGLCore, Direct3D12.

Parameters
matthe Mat object has to be of the types 'CV_8UC4' (RGBA)
texturethe Texture object has to be of the TextureFormat 'RGBA32' or 'ARGB32'. The Texture object has to be of the same size as the Mat (width * height).
static void OpenCVForUnity.Utils.matToTexture2D ( Mat  mat,
Texture2D  texture2D 
)
static

Converts OpenCV Mat to Unity Texture2D.


This function converts the OpenCV Mat to the Unity Texture2D image.
The Mat object has to be of the types 'CV_8UC4' (RGBA) , 'CV_8UC3' (RGB) or 'CV_8UC1' (GRAY).
The Texture2D object has to be of the TextureFormat 'RGBA32' or 'ARGB32'.(SetPixels32() must function.)
The Texture2D object has to be of the same size as the Mat'(width * height).

Parameters
matthe Mat object has to be of the types 'CV_8UC4' (RGBA) , 'CV_8UC3' (RGB) or 'CV_8UC1' (GRAY)
texture2Dthe Texture2D object has to be of the TextureFormat 'RGBA32' or 'ARGB32'.(SetPixels32() must function.) The Texture2D object has to be of the same size as the Mat (width * height).
static void OpenCVForUnity.Utils.matToTexture2D ( Mat  mat,
Texture2D  texture2D,
Color32[]  bufferColors 
)
static

Converts OpenCV Mat to Unity Texture2D.


This function converts the OpenCV Mat to the Unity Texture2D image.
The Mat object has to be of the types 'CV_8UC4' (RGBA) , 'CV_8UC3' (RGB) or 'CV_8UC1' (GRAY).
The Texture2D object has to be of the TextureFormat 'RGBA32' or 'ARGB32'.(SetPixels32() must function.)
The Texture2D object has to be of the same size as the Mat'(width * height).

Parameters
matthe Mat object has to be of the types 'CV_8UC4' (RGBA) , 'CV_8UC3' (RGB) or 'CV_8UC1' (GRAY)
texture2Dthe Texture2D object has to be of the TextureFormat 'RGBA32' or 'ARGB32'.(SetPixels32() must function) The Texture2D object has to be of the same size as the Mat (width * height).
bufferColorsthe optional array to receive pixel data. You can optionally pass in an array of Color32s to use in colors to avoid allocating new memory each frame. The array needs to be initialized to a length matching width * height of the texture.(http://docs.unity3d.com/ScriptReference/WebCamTexture.GetPixels32.html)
static void OpenCVForUnity.Utils.setDebugMode ( bool  debugMode,
bool  throwException = false 
)
static

Sets the debug mode.


if debugMode is true, The error log of the Native side OpenCV will be displayed on the Unity Editor Console.However, if throwException is true, CvException is thrown instead of calling Debug.LogError (msg).
This method is supported on WIN, MAC and LINUX.
Please use as follows.
Utils.setDebugMode(true);
aaa
bbb
ccc
Utils.setDebugMode(false);

Parameters
debugModeif true, The error log of the Native side OpenCV will be displayed on the Unity Editor Console
throwExceptionif true, CvException is thrown instead of calling Debug.LogError (msg).
static void OpenCVForUnity.Utils.texture2DToMat ( Texture2D  texture2D,
Mat  mat 
)
static

Converts Unity Texture2D to OpenCV Mat.


This function converts the Unity Texture2D image to the OpenCV Mat.
The Mat object has to be of the same size as the Texture2D'(width * height).
The Mat object has to be of the types 'CV_8UC4' (RGBA) , 'CV_8UC3' (RGB) or 'CV_8UC1' (GRAY).

Parameters
texture2Dthe Texture2D object has to be of the TextureFormat 'RGBA32' or 'ARGB32'.(SetPixels32() must function)
matthe Mat object has to be of the same size as the Texture2D'(width * height). The Mat object has to be of the types 'CV_8UC4' (RGBA) , 'CV_8UC3' (RGB) or 'CV_8UC1' (GRAY).
static void OpenCVForUnity.Utils.textureToMat ( Texture  texture,
Mat  mat 
)
static

Converts Unity Texture to OpenCV Mat using low-level native plugin interface.


This function converts the Unity Texture image to the OpenCV Mat using low-level native plugin interface.
The Mat object has to be of the same size as the Texture'(width * height).
The Mat object has to be of the types 'CV_8UC4' (RGBA).
This function not implemented yet on OpenGLCore, Direct3D12.
When using Windows 10 and Direct3D11, Utils.textureToMat() seems to have limitations on the size of the texture. 2^n x 2^n (32x32, 32x64, 128x128, ...) is OK. But, other size is NG.

Parameters
texturea Texture object
matthe Mat object has to be of the same size as the Texture'(width * height). The Mat object has to be of the types 'CV_8UC4' (RGBA).
static void OpenCVForUnity.Utils.textureToTexture2D ( Texture  texture,
Texture2D  texture2D 
)
static

Converts Texture to Texture2D.


This function converts the Texture image to the Texture2D image.
The texture and texture2D need to be the same size.
The texture2D's TextureFormat needs to be RGBA32(Unity5.5+), ARGB32, RGB24, RGBAFloat or RGBAHalf.

Parameters
texturea texture object
texture2Da texture2D object
static void OpenCVForUnity.Utils.webCamTextureToMat ( WebCamTexture  webCamTexture,
Mat  mat 
)
static

Converts Unity WebCamTexture to OpenCV Mat.


This function converts the Unity WebCamTexture image to the OpenCV Mat.
The Mat object has to be of the same size as the WebCamTexture'(width * height).
The Mat object has to be of the types 'CV_8UC4' (RGBA) , 'CV_8UC3' (RGB) or 'CV_8UC1' (GRAY).

Parameters
webcamTexturea WebCamTexture object
matthe Mat object has to be of the same size as the WebCamTexture'(width * height). The Mat object has to be of the types 'CV_8UC4' (RGBA) , 'CV_8UC3' (RGB) or 'CV_8UC1' (GRAY).
static void OpenCVForUnity.Utils.webCamTextureToMat ( WebCamTexture  webCamTexture,
Mat  mat,
Color32[]  bufferColors 
)
static

Converts Unity WebCamTexture to OpenCV Mat.


This function converts the Unity WebCamTexture image to the OpenCV Mat.
The Mat object has to be of the same size as the WebCamTexture'(width * height).
The Mat object has to be of the types 'CV_8UC4' (RGBA) , 'CV_8UC3' (RGB) or 'CV_8UC1' (GRAY).

Parameters
webcamTexturea WebCamTexture object
matthe Mat object has to be of the same size as the WebCamTexture'(width * height). The Mat object has to be of the types 'CV_8UC4' (RGBA) , 'CV_8UC3' (RGB) or 'CV_8UC1' (GRAY).
bufferColorsthe optional array to receive pixel data. You can optionally pass in an array of Color32s to use in colors to avoid allocating new memory each frame. The array needs to be initialized to a length matching width * height of the texture.(http://docs.unity3d.com/ScriptReference/WebCamTexture.GetPixels32.html)

The documentation for this class was generated from the following file: