OpenCV for Unity 2.6.4
Enox Software / Please refer to OpenCV official document ( http://docs.opencv.org/4.10.0/index.html ) for the details of the argument of the method.
|
Public Types | |
enum | CopyMode { PerPixel , Contiguous } |
Enumeration to specify the data copy method. More... | |
Static Public Member Functions | |
static int | fastMatToTexture2D (Mat mat, Texture2D texture2D, bool flip=true, int flipCode=0, bool updateMipmaps=false, bool makeNoLongerReadable=false) |
static int | fastTexture2DToMat (Texture2D texture2D, Mat mat, bool flip=true, int flipCode=0) |
static string | getFilePath (string filepath, bool refresh=false, int timeout=0) |
Gets the readable path of a file in the "StreamingAssets" directory. | |
static IEnumerator | getFilePathAsync (string filepath, Action< string > completed, Action< string, float > progressChanged=null, Action< string, string, long > errorOccurred=null, bool refresh=false, int timeout=0) |
Asynchronously retrieves the readable path of a file in the "StreamingAssets" directory using coroutines. | |
static async Task< string > | getFilePathAsyncTask (string filepath, Action< string, float > progressChanged=null, Action< string, string, long > errorOccurred=null, bool refresh=false, int timeout=0, CancellationToken cancellationToken=default) |
Asynchronously retrieves the readable path of a file in the "StreamingAssets" directory using a Task. | |
static IReadOnlyList< string > | getMultipleFilePaths (IReadOnlyList< string > filepaths, bool refresh=false, int timeout=0) |
Gets the multiple readable paths of a file in the "StreamingAssets" directory. | |
static IEnumerator | getMultipleFilePathsAsync (IReadOnlyList< string > filepaths, Action< IReadOnlyList< string > > allCompleted, Action< string > completed=null, Action< string, float > progressChanged=null, Action< string, string, long > errorOccurred=null, bool refresh=false, int timeout=0) |
Asynchronously retrieves the multiple readable paths of files in the "StreamingAssets" directory using coroutines. | |
static async Task< IReadOnlyList< string > > | getMultipleFilePathsAsyncTask (IReadOnlyList< string > filepaths, Action< string > completed=null, Action< string, float > progressChanged=null, Action< string, string, long > errorOccurred=null, bool refresh=false, int timeout=0, CancellationToken cancellationToken=default) |
Asynchronously retrieves the multiple readable paths of files in the "StreamingAssets" directory using a Task. | |
static string | getVersion () |
Returns this "OpenCV for Unity" version number. | |
static void | graphicsBufferToMat (GraphicsBuffer graphicsBuffer, Mat mat, CopyMode copyMode) |
Copies data from a Unity GraphicsBuffer to a OpenCV Mat. | |
static void | matToGraphicsBuffer (Mat mat, GraphicsBuffer graphicsBuffer, CopyMode copyMode) |
Copies data from a OpenCv Mat to a Unity GraphicsBuffer. | |
static void | matToRenderTexture (Mat mat, RenderTexture renderTexture, GraphicsBuffer graphicsBuffer, bool flip=true, int flipCode=0) |
Converts an OpenCV Mat to a Unity RenderTexture. | |
static void | matToTexture2D (Mat mat, Texture2D texture2D, bool flip=true, int flipCode=0, bool updateMipmaps=false, bool makeNoLongerReadable=false) |
Converts an OpenCV Mat to a Unity Texture2D. | |
static void | matToTexture2D (Mat mat, Texture2D texture2D, Color32[] pixels32Buffer, byte[] rawTextureDataBuffer=null, bool flip=true, int flipCode=0, bool updateMipmaps=false, bool makeNoLongerReadable=false) |
Converts an OpenCV Mat to a Unity Texture2D. | |
static void | matToTexture2D (Mat mat, Texture2D texture2D, int mipLevel, bool flip=true, int flipCode=0, bool updateMipmaps=false, bool makeNoLongerReadable=false) |
Converts an OpenCV Mat to a Unity Texture2D, targeting the specified mipmap level. | |
static void | matToTexture2D (Mat mat, Texture2D texture2D, int mipLevel, Color32[] pixels32Buffer, bool flip=true, int flipCode=0, bool updateMipmaps=false, bool makeNoLongerReadable=false) |
Converts an OpenCV Mat to a Unity Texture2D, targeting the specified mipmap level. | |
static int | matToTexture2DRaw (Mat mat, Texture2D texture2D, bool flip=true, int flipCode=0, bool updateMipmaps=false, bool makeNoLongerReadable=false) |
Copies raw data from an OpenCV Mat to a Unity Texture2D. | |
static int | matToTexture2DRaw (Mat mat, Texture2D texture2D, int mipLevel, bool flip=true, int flipCode=0, bool updateMipmaps=false, bool makeNoLongerReadable=false) |
Copies raw data from an OpenCV Mat to a Unity Texture2D, targeting the specified mipmap level. | |
static void | renderTextureToMat (RenderTexture renderTexture, Mat mat, GraphicsBuffer graphicsBuffer, bool flip=true, int flipCode=0) |
Converts a Unity RenderTexture to an OpenCV Mat. | |
static void | setDebugMode (bool debugMode, bool throwException=false, Action< string > callback=null) |
Sets the debug mode. | |
static void | texture2DToMat (Texture2D texture2D, Mat mat, bool flip=true, int flipCode=0) |
Converts a Unity Texture2D to an OpenCV Mat. | |
static void | texture2DToMat (Texture2D texture2D, Mat mat, int mipLevel, bool flip=true, int flipCode=0) |
Converts a Unity Texture2D to an OpenCV Mat, targeting the specified mipmap level. | |
static int | texture2DToMatRaw (Texture2D texture2D, Mat mat, bool flip=true, int flipCode=0) |
Copies raw data from a Unity Texture2D to an OpenCV Mat. | |
static int | texture2DToMatRaw (Texture2D texture2D, Mat mat, int mipLevel, bool flip=true, int flipCode=0) |
Copies raw data from a Unity Texture2D to an OpenCV Mat, targeting the specified mipmap level. | |
static void | textureToTexture2D (Texture texture, Texture2D texture2D) |
OPENCV_DONT_USE_WEBCAMTEXTURE_API. | |
static void | webCamTextureToMat (WebCamTexture webCamTexture, Mat mat, bool flip=true, int flipCode=0) |
Converts a Unity WebCamTexture to an OpenCV Mat. | |
static void | webCamTextureToMat (WebCamTexture webCamTexture, Mat mat, Color32[] pixels32Buffer, bool flip=true, int flipCode=0) |
Converts a Unity WebCamTexture to an OpenCV Mat. | |
Enumeration to specify the data copy method.
|
static |
|
static |
|
static |
Gets the readable path of a file in the "StreamingAssets" directory.
Provide a relative file path based on the "StreamingAssets" directory. e.g., "foobar.txt" or "hogehoge/foobar.txt". [Android] The target file that exists in the "StreamingAssets" directory is copied to the the Application.persistentDataPath directory. [WebGL] If the target file has not yet been copied to WebGL's virtual filesystem, it is necessary to use getFilePathAsync of getFilePathAsyncTask at first.
filepath | A file path relative to the "StreamingAssets" directory. |
refresh | [Android] If false, the file is not copied if it already exists. If true, the file is always copied. |
timeout | [Android] Sets the UnityWebRequest to abort after the specified number of seconds. If set to 0, no timeout is applied. The default is 0. |
string.Empty
in case of error. ArgumentNullException | Thrown if filepath is null. |
|
static |
Asynchronously retrieves the readable path of a file in the "StreamingAssets" directory using coroutines.
Provide a relative file path based on the "StreamingAssets" directory. e.g., "foobar.txt" or "hogehoge/foobar.txt". [Android] The target file that exists in the "StreamingAssets" directory is copied to the the Application.persistentDataPath directory. [WebGL] The target file in the "StreamingAssets" directory is copied to the WebGL's virtual filesystem.
filepath | A file path relative to the "StreamingAssets" directory. |
completed | A callback that is called when the process is completed. Returns a readable file path in case of success and returns string.Empty in case of error. |
progressChanged | An optional callback that is called when the process is the progress. Returns the file path and a progress value (0.0 to 1.0). |
errorOccurred | An optional callback that is called when the process is error occurred. Returns the file path and an error string and an error response code. |
refresh | [Android][WebGL] If false, the file is not copied if it already exists. If true, the file is always copied. |
timeout | [Android][WebGL] Sets the UnityWebRequest to abort after the specified number of seconds. If set to 0, no timeout is applied. The default is 0. |
ArgumentNullException | Thrown if filepath is null. |
|
static |
Asynchronously retrieves the readable path of a file in the "StreamingAssets" directory using a Task.
Provide a relative file path based on the "StreamingAssets" directory. e.g., "foobar.txt" or "hogehoge/foobar.txt". [Android] The target file that exists in the "StreamingAssets" directory is copied to the the Application.persistentDataPath directory. [WebGL] The target file in the "StreamingAssets" directory is copied to the WebGL's virtual filesystem.
filepath | A file path relative to the "StreamingAssets" directory. |
progressChanged | An optional callback that is called when the process is the progress. Returns the file path and a progress value (0.0 to 1.0). |
errorOccurred | An optional callback that is called when the process is error occurred. Returns the file path and an error string and an error response code. |
refresh | [Android][WebGL] If false, the file is not copied if it already exists. If true, the file is always copied. |
timeout | [Android][WebGL] Sets the UnityWebRequest to abort after the specified number of seconds. If set to 0, no timeout is applied. The default is 0. |
cancellationToken | A cancellation token that can be used to cancel the download operation. |
string.Empty
if the download fails. ArgumentNullException | Thrown if filepath is null. |
InvalidOperationException | Thrown if this method is called from a non-main thread. |
OperationCanceledException | Thrown if the download operation is canceled. |
|
static |
Gets the multiple readable paths of a file in the "StreamingAssets" directory.
Provide a relative file path based on the "StreamingAssets" directory. e.g., "foobar.txt" or "hogehoge/foobar.txt". [Android] The target file that exists in the "StreamingAssets" directory is copied to the the Application.persistentDataPath directory. [WebGL] If the target file has not yet been copied to WebGL's virtual filesystem, it is necessary to use getMultipleFilePathsAsync of getMultipleFilePathsAsynck at first.
filepaths | The list of file paths relative to the "StreamingAssets" directory. |
refresh | [Android] If false, the file is not copied if it already exists. If true, the file is always copied. |
timeout | [Android] Sets the UnityWebRequest to abort after the specified number of seconds. If set to 0, no timeout is applied. The default is 0. |
string.Empty
in case of error. ArgumentNullException | Thrown if filepath is null. |
|
static |
Asynchronously retrieves the multiple readable paths of files in the "StreamingAssets" directory using coroutines.
Provide a relative file path based on the "StreamingAssets" directory. e.g., "foobar.txt" or "hogehoge/foobar.txt". [Android] The target file that exists in the "StreamingAssets" directory is copied to the the Application.persistentDataPath directory. [WebGL] The target file in the "StreamingAssets" directory is copied to the WebGL's virtual filesystem.
filepaths | The list of file paths relative to the "StreamingAssets" directory. |
allCompleted | A callback that is called when all processes are completed. Returns a list of file paths. Returns a readable file path in case of success and returns string.Empty in case of error. |
completed | An optional callback that is called when one process is completed. Returns a readable file path in case of success and returns empty in case of error. |
progressChanged | An optional callback that is called when one process is the progress. Returns the file path and a progress value (0.0 to 1.0). |
errorOccurred | An optional callback that is called when one process is error occurred. Returns the file path and an error string and an error response code. |
refresh | [Android][WebGL] If false, the file is not copied if it already exists. If true, the file is always copied. |
timeout | [Android][WebGL] Sets the UnityWebRequest to abort after the specified number of seconds. If set to 0, no timeout is applied. The default is 0. |
ArgumentNullException | Thrown if filepath is null. |
|
static |
Asynchronously retrieves the multiple readable paths of files in the "StreamingAssets" directory using a Task.
Provide a relative file path based on the "StreamingAssets" directory. e.g., "foobar.txt" or "hogehoge/foobar.txt". [Android] The target file that exists in the "StreamingAssets" directory is copied to the the Application.persistentDataPath directory. [WebGL] The target file in the "StreamingAssets" directory is copied to the WebGL's virtual filesystem.
filepaths | The list of file paths relative to the "StreamingAssets" directory. |
completed | An optional callback that is called when one process is completed. Returns a readable file path in case of success and returns empty in case of error. |
progressChanged | An optional callback that is called when one process is the progress. Returns the file path and a progress value (0.0 to 1.0). |
errorOccurred | An optional callback that is called when one process is error occurred. Returns the file path and an error string and an error response code. |
refresh | [Android][WebGL] If false, the file is not copied if it already exists. If true, the file is always copied. |
timeout | [Android][WebGL] Sets the UnityWebRequest to abort after the specified number of seconds. If set to 0, no timeout is applied. The default is 0. |
cancellationToken | A cancellation token that can be used to cancel the download operation. |
string.Empty
if the download fails. ArgumentNullException | Thrown if filepath is null. |
InvalidOperationException | Thrown if this method is called from a non-main thread. |
OperationCanceledException | Thrown if the download operation is canceled. |
|
static |
Returns this "OpenCV for Unity" version number.
|
static |
Copies data from a Unity GraphicsBuffer to a OpenCV Mat.
graphicsBuffer | The source Unity GraphicsBuffer. |
mat | The destination OpenCV Mat. |
copyMode | The CopyMode enumeration specifying the method of copying data. |
ArgumentNullException | Thrown if mat or graphicsBuffer is null. |
ArgumentException | Thrown if data size or stride does not match. |
|
static |
Copies data from a OpenCv Mat to a Unity GraphicsBuffer.
mat | The source OpenCV Mat. |
graphicsBuffer | The destination Unity GraphicsBuffer. |
copyMode | The CopyMode enumeration specifying the method of copying data. |
ArgumentNullException | Thrown if mat or graphicsBuffer is null. |
ArgumentException | Thrown if data size or stride does not match. |
|
static |
Converts an OpenCV Mat to a Unity RenderTexture.
mat | The source OpenCV Mat. The depth must be 'CV_8U'. The Mat object must not have more than 4 channels. |
renderTexture | The destination Unity RenderTexture. Must have enableRandomWrite set to true. |
graphicsBuffer | A temporary GraphicsBuffer. If null, a new one will be created. The stride of the graphics buffer must be exactly 4 bytes. |
flip | Whether to flip the image vertically. |
flipCode | The flipCode for the Core.flip() method. |
ArgumentNullException | Thrown if renderTexture or mat is null. |
ArgumentException | Thrown if renderTexture has enableRandomWrite set to false, or if the size or format of the RenderTexture is invalid. |
|
static |
Converts an OpenCV Mat to a Unity Texture2D.
This method converts an OpenCV Mat to a Unity Texture2D. Conversion is possible even when the number of bytes per pixel differs, such as from Mat(8UC1) to Texture2D(RGBA32). In the case of multi-channel color to 1-channel, it is converted to grayscale. Performance is optimal when the per-pixel data size and color order match, such as with Mat(8UC4) and Texture2D(RGBA32). If the texture format is not RGBA32, BGRA32, RGB24, Alpha8, or R8, the Texture2D.SetPixels32 and Texture2D.GetPixels32 methods are used. In such cases, it is recommended to use the pixels32Buffer argument to avoid repeated memory allocations.
mat | The source Mat must be 2-dimensional, with a CvType of 'CV_8UC4' (RGBA), 'CV_8UC3' (RGB), or 'CV_8UC1' (GRAYSCALE). For other CvTypes or color orders, use matToTexture2DRaw. |
texture2D | The destination Texture2D must have the same size as the source Mat. The destination Texture2D supports the following formats. (Texture2D.SetPixels32) |
flip | If true , the Mat is flipped before conversion. The default is true , as the Mat must be flipped to align with the coordinate system of the destination Texture2D image. |
flipCode | Specifies how to flip the Mat: Vertical flipping of the image (flipCode == 0) to flip around the x-axis, horizontal flipping of the image (flipCode > 0, e.g., 1) to flip around the y-axis, and simultaneous horizontal and vertical flipping (flipCode < 0, e.g., -1) to flip around both axes. The default is 0 . |
updateMipmaps | If true , mipmaps are recalculated after conversion. The default is false . |
makeNoLongerReadable | If true , system memory copy of a texture is released. The default is false . |
ArgumentNullException | Thrown when mat or texture2D is null. |
ArgumentException |
|
static |
Converts an OpenCV Mat to a Unity Texture2D.
This method converts an OpenCV Mat to a Unity Texture2D. Conversion is possible even when the number of bytes per pixel differs, such as from Mat(8UC1) to Texture2D(RGBA32). In the case of multi-channel color to 1-channel, it is converted to grayscale. Performance is optimal when the per-pixel data size and color order match, such as with Mat(8UC4) and Texture2D(RGBA32). If the texture format is not RGBA32, BGRA32, RGB24, Alpha8, or R8, the Texture2D.SetPixels32 and Texture2D.GetPixels32 methods are used. In such cases, it is recommended to use the pixels32Buffer argument to avoid repeated memory allocations.
mat | The source Mat must be 2-dimensional, with a CvType of 'CV_8UC4' (RGBA), 'CV_8UC3' (RGB), or 'CV_8UC1' (GRAYSCALE). For other CvTypes or color orders, use matToTexture2DRaw. |
texture2D | The destination Texture2D must have the same size as the source Mat. The destination Texture2D supports the following formats. (Texture2D.SetPixels32) |
pixels32Buffer | An optional array for receiving pixel data as Color32. Using this array helps avoid memory allocation each frame. Ensure the array is initialized to a length matching the texture’s width * height. (Texture2D.GetPixels32) |
rawTextureDataBuffer | An optional array for receiving raw texture data. This only works when the "OPENCV_DONT_USE_UNSAFE_CODE" symbol is defined and texture2D has no mipmaps (mipmapCount == 1). Passing a byte array can help avoid memory allocation each frame. Ensure the array length matches the texture's raw data size. (Texture2D.GetRawTextureData) The default value is null . |
flip | If true , the Mat is flipped before conversion. The default is true , as the Mat must be flipped to align with the coordinate system of the destination Texture2D image. |
flipCode | Specifies how to flip the Mat: Vertical flipping of the image (flipCode == 0) to flip around the x-axis, horizontal flipping of the image (flipCode > 0, e.g., 1) to flip around the y-axis, and simultaneous horizontal and vertical flipping (flipCode < 0, e.g., -1) to flip around both axes. The default is 0 . |
updateMipmaps | If true , mipmaps are recalculated after conversion. The default is false . |
makeNoLongerReadable | If true , system memory copy of a texture is released. The default is false . |
ArgumentNullException | Thrown when mat or texture2D is null. |
ArgumentException |
|
static |
Converts an OpenCV Mat to a Unity Texture2D, targeting the specified mipmap level.
This method converts an OpenCV Mat to a Unity Texture2D, targeting the specified mipmap level. Conversion is possible even when the number of bytes per pixel differs, such as from Mat(8UC1) to Texture2D(RGBA32). In the case of multi-channel color to 1-channel, it is converted to grayscale. It is recommended to use the pixels32Buffer argument to avoid repeated memory allocations.
mat | The source Mat must be 2-dimensional, with a CvType of 'CV_8UC4' (RGBA), 'CV_8UC3' (RGB), or 'CV_8UC1' (GRAYSCALE). For other CvTypes or color orders, use matToTexture2DRaw. The source Mat must be the same size as the mipmap of the destination Texture2D. |
texture2D | The destination Texture2D most be supports mipmaps, as the conversion will target themipLevel . The destination Texture2D supports the following formats. (Texture2D.SetPixels32) |
mipLevel | The mipmap level to which the Mat will be converted. The level must be within the range supported by the destination Texture2D. |
flip | If true , the Mat is flipped before conversion. The default is true , as the Mat must be flipped to align with the coordinate system of the destination Texture2D image. |
flipCode | Specifies how to flip the Mat: Vertical flipping of the image (flipCode == 0) to flip around the x-axis, horizontal flipping of the image (flipCode > 0, e.g., 1) to flip around the y-axis, and simultaneous horizontal and vertical flipping (flipCode < 0, e.g., -1) to flip around both axes. The default is 0 . |
updateMipmaps | If true , mipmaps are recalculated after conversion. The default is false . |
makeNoLongerReadable | If true , system memory copy of a texture is released. The default is false . |
ArgumentNullException | Thrown when mat or texture2D is null. |
ArgumentException |
|
static |
Converts an OpenCV Mat to a Unity Texture2D, targeting the specified mipmap level.
This method converts an OpenCV Mat to a Unity Texture2D, targeting the specified mipmap level. Conversion is possible even when the number of bytes per pixel differs, such as from Mat(8UC1) to Texture2D(RGBA32). In the case of multi-channel color to 1-channel, it is converted to grayscale. It is recommended to use the pixels32Buffer argument to avoid repeated memory allocations.
mat | The source Mat must be 2-dimensional, with a CvType of 'CV_8UC4' (RGBA), 'CV_8UC3' (RGB), or 'CV_8UC1' (GRAYSCALE). For other CvTypes or color orders, use matToTexture2DRaw. The source Mat must be the same size as the mipmap of the destination Texture2D. |
texture2D | The destination Texture2D most be supports mipmaps, as the conversion will target themipLevel . The destination Texture2D supports the following formats. (Texture2D.SetPixels32) |
mipLevel | The mipmap level to which the Mat will be converted. The level must be within the range supported by the destination Texture2D. |
pixels32Buffer | An optional array for receiving pixel data as Color32. Using this array helps avoid memory allocation each frame. Ensure the array is initialized to a length matching the texture’s mipmap width * height. (Texture2D.GetPixels32) |
flip | If true , the Mat is flipped before conversion. The default is true , as the Mat must be flipped to align with the coordinate system of the destination Texture2D image. |
flipCode | Specifies how to flip the Mat: Vertical flipping of the image (flipCode == 0) to flip around the x-axis, horizontal flipping of the image (flipCode > 0, e.g., 1) to flip around the y-axis, and simultaneous horizontal and vertical flipping (flipCode < 0, e.g., -1) to flip around both axes. The default is 0 . |
updateMipmaps | If true , mipmaps are recalculated after conversion. The default is false . |
makeNoLongerReadable | If true , system memory copy of a texture is released. The default is false . |
ArgumentNullException | Thrown when mat or texture2D is null. |
ArgumentException |
|
static |
Copies raw data from an OpenCV Mat to a Unity Texture2D.
This method copies raw data from an OpenCV Mat to a Unity Texture2D. There are no specific requirements for the size or type of the Mat and Texture2D; data is copied up to the maximum size that fits within the data size of the destination Texture2D, including mipmaps. A common use case for this method is writing a Mat with BGRA color order to a Texture2D in the BGRA32 format. If the "OPENCV_DONT_USE_UNSAFE_CODE" symbol is defined, the following operating conditions are added: mat.isContinuous() == true, and the data size of Texture2D is the same as or larger than the data size of Mat.
mat | The source Mat must be 2-dimensional. |
texture2D | The destination Texture2D. |
flip | If true , the Mat is flipped before copies. The default is true , as the Mat must be flipped to align with the coordinate system of the destination Texture2D image. |
flipCode | Specifies how to flip the Mat: Vertical flipping of the image (flipCode == 0) to flip around the x-axis, horizontal flipping of the image (flipCode > 0, e.g., 1) to flip around the y-axis, and simultaneous horizontal and vertical flipping (flipCode < 0, e.g., -1) to flip around both axes. The default is 0 . |
updateMipmaps | If true , mipmaps are recalculated after copies. The default is false . |
makeNoLongerReadable | If true , system memory copy of a texture is released. The default is false . |
ArgumentNullException | Thrown when mat or texture2D is null. |
ArgumentException |
|
static |
Copies raw data from an OpenCV Mat to a Unity Texture2D, targeting the specified mipmap level.
This method copies raw data from an OpenCV Mat to a Unity Texture2D, targeting the specified mipmap level. There are no specific requirements for the size or type of the Mat and Texture2D; data is copied up to the maximum size that fits within the data size of the mipmap of the destination Texture2D.
mat | The source Mat must be 2-dimensional. |
texture2D | The destination Texture2D. |
mipLevel | The mipmap level to which the Mat will be converted. The level must be within the range supported by the destination Texture2D. |
flip | If true , the Mat is flipped before copies. The default is true , as the Mat must be flipped to align with the coordinate system of the destination Texture2D image. |
flipCode | Specifies how to flip the Mat: Vertical flipping of the image (flipCode == 0) to flip around the x-axis, horizontal flipping of the image (flipCode > 0, e.g., 1) to flip around the y-axis, and simultaneous horizontal and vertical flipping (flipCode < 0, e.g., -1) to flip around both axes. The default is 0 . |
updateMipmaps | If true , mipmaps are recalculated after copies. The default is false . |
makeNoLongerReadable | If true , system memory copy of a texture is released. The default is false . |
ArgumentNullException | Thrown when mat or texture2D is null. |
ArgumentException |
|
static |
Converts a Unity RenderTexture to an OpenCV Mat.
renderTexture | The source Unity RenderTexture. Must have enableRandomWrite set to true. |
mat | The destination OpenCV Mat. The depth must be 'CV_8U'. The Mat object must not have more than 4 channels. |
graphicsBuffer | A temporary GraphicsBuffer. If null, a new one will be created. The stride of the graphics buffer must be exactly 4 bytes. |
flip | Whether to flip the image vertically. |
flipCode | The flipCode for the Core.flip() method. |
ArgumentNullException | Thrown if renderTexture or mat is null. |
ArgumentException | Thrown if renderTexture has enableRandomWrite set to false, or if the size or format of the RenderTexture is invalid. |
|
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.
debugMode | If true, The error log of the Native side OpenCV will be displayed on the Unity Editor Console. |
throwException | If true, CvException is thrown instead of calling Debug.LogError (msg). |
callback | Callback called when an OpenCV error occurs on the Native side. |
|
static |
Converts a Unity Texture2D to an OpenCV Mat.
This method converts a Unity Texture2D to an OpenCV Mat. Conversion is possible even when the number of bytes per pixel differs, such as from Texture2D(RGBA32) to Mat(8UC1). In the case of multi-channel color to 1-channel, it is converted to grayscale. Performance is optimal when the per-pixel data size and color order match, such as with Texture2D(RGBA32) and Mat(8UC4). If the texture format is not RGBA32, BGRA32, RGB24, Alpha8, or R8, the Texture2D.GetPixels32 methods are used.
texture2D | The source Texture2D must have the same size as the destination Mat. The source Texture2D supports the following formats. (Texture2D.GetPixels32) |
mat | The destination Mat must be 2-dimensional, with a CvType of 'CV_8UC4' (RGBA), 'CV_8UC3' (RGB), or 'CV_8UC1' (GRAYSCALE). For other CvTypes or color orders, use texture2DToMatRaw. |
flip | If true , the pixel data retrieved from the Texture2D is flipped before conversion. The default is true , as the pixel data must be flipped to align with the coordinate system of the destination Mat. |
flipCode | Specifies how to flip the Textrue2D image: Vertical flipping of the image (flipCode == 0) to flip around the x-axis, horizontal flipping of the image (flipCode > 0, e.g., 1) to flip around the y-axis, and simultaneous horizontal and vertical flipping (flipCode < 0, e.g., -1) to flip around both axes. The default is 0 . |
ArgumentNullException | Thrown when texture2D or mat is null. |
ArgumentException |
|
static |
Converts a Unity Texture2D to an OpenCV Mat, targeting the specified mipmap level.
This method converts a Unity Texture2D to an OpenCV Mat, targeting the specified mipmap level. Conversion is possible even when the number of bytes per pixel differs, such as from Texture2D(RGBA32) to Mat(8UC1). In the case of multi-channel color to 1-channel, it is converted to grayscale.
texture2D | The source Texture2D supports the following formats. (Texture2D.GetPixels32) The source Texture2D most be supports mipmaps, as the conversion will target themipLevel . |
mat | The destination Mat must be 2-dimensional, with a CvType of 'CV_8UC4' (RGBA), 'CV_8UC3' (RGB), or 'CV_8UC1' (GRAYSCALE). For other CvTypes or color orders, use texture2DToMatRaw. The destination Mat must be the same size as the mipmap of the destination Texture2D. |
mipLevel | The mipmap level to which the Mat will be converted. The level must be within the range supported by the source Texture2D. |
flip | If true , the pixel data retrieved from the Texture2D is flipped before conversion. The default is true , as the pixel data must be flipped to align with the coordinate system of the destination Mat. |
flipCode | Specifies how to flip the Textrue2D image: Vertical flipping of the image (flipCode == 0) to flip around the x-axis, horizontal flipping of the image (flipCode > 0, e.g., 1) to flip around the y-axis, and simultaneous horizontal and vertical flipping (flipCode < 0, e.g., -1) to flip around both axes. The default is 0 . |
ArgumentNullException | Thrown when texture2D or mat is null. |
ArgumentException |
|
static |
Copies raw data from a Unity Texture2D to an OpenCV Mat.
This method copies raw data from a Unity Texture2D to an OpenCV Mat. There are no specific requirements for the size or type of the Texture2D and Mat; data is copied up to the maximum size that fits within the data size of the destination Mat. A common use case for this method is writing a Texture2D in the BGRA32 format to a Mat with BGRA color order.
texture2D | The source Texture2D. |
mat | The destination Mat must be 2-dimensional. |
flip | If true , the pixel data retrieved from the Texture2D is flipped before copies. The default is true , as the pixel data must be flipped to align with the coordinate system of the destination Mat. |
flipCode | Specifies how to flip the Textrue2D image: Vertical flipping of the image (flipCode == 0) to flip around the x-axis, horizontal flipping of the image (flipCode > 0, e.g., 1) to flip around the y-axis, and simultaneous horizontal and vertical flipping (flipCode < 0, e.g., -1) to flip around both axes. The default is 0 . |
ArgumentNullException | Thrown when texture2D or mat is null. |
ArgumentException |
|
static |
Copies raw data from a Unity Texture2D to an OpenCV Mat, targeting the specified mipmap level.
This method copies raw data from a Unity Texture2D to an OpenCV Mat, targeting the specified mipmap level. There are no specific requirements for the size or type of the Texture2D and Mat; data is copied up to the maximum size that fits within the data size of the mipmap of the destination Mat.
texture2D | The source Texture2D. |
mat | The destination Mat must be 2-dimensional. |
mipLevel | The mipmap level to which the Mat will be converted. The level must be within the range supported by the source Texture2D. |
flip | If true , the pixel data retrieved from the Texture2D is flipped before copies. The default is true , as the pixel data must be flipped to align with the coordinate system of the destination Mat. |
flipCode | Specifies how to flip the Textrue2D image: Vertical flipping of the image (flipCode == 0) to flip around the x-axis, horizontal flipping of the image (flipCode > 0, e.g., 1) to flip around the y-axis, and simultaneous horizontal and vertical flipping (flipCode < 0, e.g., -1) to flip around both axes. The default is 0 . |
ArgumentNullException | Thrown when texture2D or mat is null. |
ArgumentException |
|
static |
OPENCV_DONT_USE_WEBCAMTEXTURE_API.
Converts a Texture to a Texture2D.
This method converts a Texture to a Texture2D. The Texture and the Texture2D must be the same size.
texture | The source Texture. |
texture2D | The destination Texture2D. It must have a TextureFormat of RGBA32, ARGB32, RGB24, RGBAFloat, or RGBAHalf. |
ArgumentNullException | Thrown when texture or texture2D is null. |
ArgumentException |
|
static |
Converts a Unity WebCamTexture to an OpenCV Mat.
This method converts a Unity WebCamTexture image to an OpenCV Mat. Conversion is possible even when the number of bytes per pixel differs, such as from WebCamTexture(RGBA32) to Mat(8UC1). In the case of multi-channel color to 1-channel, it is converted to grayscale. Performance is optimal when the per-pixel data size and color order match, such as with Texture2D(RGBA32) and Mat(8UC4). It is recommended to use the pixels32Buffer argument to avoid repeated memory allocations.
webCamTexture | The source WebCamTexture must have the same size as the destination Mat. |
mat | The destination Mat must be 2-dimensional, with a CvType of 'CV_8UC4' (RGBA), 'CV_8UC3' (RGB), or 'CV_8UC1' (GRAYSCALE). |
flip | If true , the pixel data retrieved from the WebCamTexture is flipped before conversion. The default is true , as the pixel data must be flipped to align with the coordinate system of the destination Mat. |
flipCode | Specifies how to flip the WebCamTexture image: Vertical flipping of the image (flipCode == 0) to flip around the x-axis, horizontal flipping of the image (flipCode > 0, e.g., 1) to flip around the y-axis, and simultaneous horizontal and vertical flipping (flipCode < 0, e.g., -1) to flip around both axes. The default is 0 . |
ArgumentNullException | Thrown when webCamTexture or mat is null. |
ArgumentException |
|
static |
Converts a Unity WebCamTexture to an OpenCV Mat.
This method converts a Unity WebCamTexture image to an OpenCV Mat. Conversion is possible even when the number of bytes per pixel differs, such as from WebCamTexture(RGBA32) to Mat(8UC1). In the case of multi-channel color to 1-channel, it is converted to grayscale. Performance is optimal when the per-pixel data size and color order match, such as with Texture2D(RGBA32) and Mat(8UC4). It is recommended to use the pixels32Buffer argument to avoid repeated memory allocations.