OpenCV for Unity  2.3.1
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 matToTexture2D (Mat mat, Texture2D texture2D, bool flip=true, int flipCode=0, bool flipAfter=false, bool updateMipmaps=false, bool makeNoLongerReadable=false)
 
static void matToTexture2D (Mat mat, Texture2D texture2D, Color32[] bufferColors, bool flip=true, int flipCode=0, bool flipAfter=false, bool updateMipmaps=false, bool makeNoLongerReadable=false)
 
static void fastMatToTexture2D (Mat mat, Texture2D texture2D, bool flip=true, int flipCode=0, bool flipAfter=false, bool updateMipmaps=false, bool makeNoLongerReadable=false)
 
static void texture2DToMat (Texture2D texture2D, Mat mat, bool flip=true, int flipCode=0)
 
static void fastTexture2DToMat (Texture2D texture2D, Mat mat, bool flip=true, int flipCode=0)
 
static void webCamTextureToMat (WebCamTexture webCamTexture, Mat mat, bool flip=true, int flipCode=0)
 
static void webCamTextureToMat (WebCamTexture webCamTexture, Mat mat, Color32[] bufferColors, bool flip=true, int flipCode=0)
 
static void textureToTexture2D (Texture texture, Texture2D texture2D)
 
static void RegisterWebGLPlugin ()
 
static void IntPtrToTextureInRenderThread (IntPtr intPtr, Texture texture)
 
static void ArrayToTextureInRenderThread< T > (IList< T > array, Texture texture)
 
static void MatToTextureInRenderThread (Mat mat, Texture texture)
 
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.ArrayToTextureInRenderThread< T > ( IList< T >  array,
Texture  texture 
)
static

Copies Pixel Data Array to Texture at render thread.


This function copies the pixel data Array to Texture at render thread.
The pixel data Array has to be of the same byte size as the Texture data ([width * height * 4] byte)
The texture's TextureFormat needs to be 4byte per pixel(RGBA32(Unity5.5+), ARGB32).

Parameters
arraythe pixel data Array has to be of the same byte size as the Texture data ([width * height * 4] byte)
texturethe texture's TextureFormat needs to be 4byte per pixel(RGBA32(Unity5.5+), ARGB32).
static void OpenCVForUnity.Utils.copyFromMat ( Mat  mat,
IntPtr  intPtr 
)
static

Copies OpenCV Mat data to 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 OpenCV Mat data to 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.copyToMat ( IntPtr  intPtr,
Mat  mat 
)
static

Copies Pixel Data IntPtr to 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 Pixel Data Array to 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.fastMatToTexture2D ( Mat  mat,
Texture2D  texture2D,
bool  flip = true,
int  flipCode = 0,
bool  flipAfter = false,
bool  updateMipmaps = false,
bool  makeNoLongerReadable = 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. If you want to use mat even after calling this function, set true.
updateMipmapsWhen set to true, mipmap levels are recalculated.
makeNoLongerReadableWhen set to true, system memory copy of a texture is released.
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 string OpenCVForUnity.Utils.getVersion ( )
static

Returns this "OpenCV for Unity" version number.

Returns
this "OpenCV for Unity" version number
static void OpenCVForUnity.Utils.IntPtrToTextureInRenderThread ( IntPtr  intPtr,
Texture  texture 
)
static

Copies Pixel Data IntPtr to Texture at render thread.


This function copies the pixel data IntPtr to Texture at render thread.
The pixel data has to be of the same byte size as the Texture data ([width * height * 4] byte)
The texture's TextureFormat needs to be 4byte per pixel(RGBA32(Unity5.5+), ARGB32).

Parameters
intPtrthe pixel data has to be of the same byte size as the Texture data ([width * height * 4] byte)
texturethe texture's TextureFormat needs to be 4byte per pixel(RGBA32(Unity5.5+), ARGB32).
static void OpenCVForUnity.Utils.matToTexture2D ( Mat  mat,
Texture2D  texture2D,
bool  flip = true,
int  flipCode = 0,
bool  flipAfter = false,
bool  updateMipmaps = false,
bool  makeNoLongerReadable = false 
)
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).
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. If you want to use mat even after calling this function, set true.
updateMipmapsWhen set to true, mipmap levels are recalculated.
makeNoLongerReadableWhen set to true, system memory copy of a texture is released.
static void OpenCVForUnity.Utils.matToTexture2D ( Mat  mat,
Texture2D  texture2D,
Color32[]  bufferColors,
bool  flip = true,
int  flipCode = 0,
bool  flipAfter = false,
bool  updateMipmaps = false,
bool  makeNoLongerReadable = false 
)
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)
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. If you want to use mat even after calling this function, set true.
updateMipmapsWhen set to true, mipmap levels are recalculated.
makeNoLongerReadableWhen set to true, system memory copy of a texture is released.
static void OpenCVForUnity.Utils.MatToTextureInRenderThread ( Mat  mat,
Texture  texture 
)
static

Copies OpenCV Mat data to Texture at render thread.


This function copies the OpenCV Mat data to Texture at render thread.
This method does not flip mat before copying mat to the texture.
The OpenCV Mat data has to be of the same byte size as the Texture data ([width * height * 4] byte)
The texture's TextureFormat needs to be 4byte per pixel(RGBA32(Unity5.5+), ARGB32).

Parameters
matthe OpenCV Mat data has to be of the same byte size as the Texture data ([width * height * 4] byte)
texturethe texture's TextureFormat needs to be 4byte per pixel(RGBA32(Unity5.5+), ARGB32).
static void OpenCVForUnity.Utils.RegisterWebGLPlugin ( )
static

Register Plugin on WebGL.


For the WebGL platform, please call this method before calling IntPtrToTextureInRenderThread(), ArrayToTextureInRenderThread() and MatToTextureInRenderThread() methods.

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).
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,
bool  flip = true,
int  flipCode = 0 
)
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).
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 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,
bool  flip = true,
int  flipCode = 0 
)
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).
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 void OpenCVForUnity.Utils.webCamTextureToMat ( WebCamTexture  webCamTexture,
Mat  mat,
Color32[]  bufferColors,
bool  flip = true,
int  flipCode = 0 
)
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)
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.

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