OpenCV for Unity 3.0.0
Enox Software / Please refer to OpenCV official document ( http://docs.opencv.org/4.12.0/index.html ) for the details of the argument of the method.
|
OpenCV Mat utilities. More...
Public Types | |
enum | CopyMode { PerPixel , Contiguous } |
Enumeration to specify the data copy method. More... | |
Static Public Member Functions | |
static int | CopyFromMat (Mat mat, IntPtr intPtr) |
Copies the data from an OpenCV Mat to an IntPtr. | |
static int | CopyFromMat (Mat mat, IntPtr intPtr, int length) |
Copies the data from an OpenCV Mat to an IntPtr. | |
static int | CopyFromMat< T > (Mat mat, IntPtr intPtr, int length) |
Copies the data from an OpenCV Mat to an IntPtr. | |
static int | CopyFromMat< T > (Mat mat, NativeArray< T > array) |
Copies the data from an OpenCV Mat to a NativeArray. | |
static int | CopyFromMat< T > (Mat mat, NativeArray< T > array, int length) |
Copies the data from an OpenCV Mat to a NativeArray. | |
static int | CopyFromMat< T > (Mat mat, Span< T > array) |
Copies the data from an OpenCV Mat to a Span. | |
static int | CopyFromMat< T > (Mat mat, Span< T > array, int length) |
Copies the data from an OpenCV Mat to a Span. | |
static int | CopyFromMat< T > (Mat mat, T[] array) |
Copies the data from an OpenCV Mat to a managed array. | |
static int | CopyFromMat< T > (Mat mat, T[] array, int length) |
Copies the data from an OpenCV Mat to a managed array. | |
static int | CopyToMat (IntPtr intPtr, Mat mat) |
Copies the data from an IntPtr to an OpenCV Mat. | |
static int | CopyToMat (IntPtr intPtr, Mat mat, int length) |
Copies the data from an IntPtr to an OpenCV Mat. | |
static int | CopyToMat< T > (IntPtr intPtr, Mat mat, int length) |
Copies the data from an IntPtr to an OpenCV Mat. | |
static int | CopyToMat< T > (NativeArray< T > array, Mat mat) |
Copies the data from a NativeArray to an OpenCV Mat. | |
static int | CopyToMat< T > (NativeArray< T > array, Mat mat, int length) |
Copies the data from a NativeArray to an OpenCV Mat. | |
static int | CopyToMat< T > (ReadOnlySpan< T > array, Mat mat) |
Copies the data from a Span to an OpenCV Mat. | |
static int | CopyToMat< T > (ReadOnlySpan< T > array, Mat mat, int length) |
Copies the data from a Span to an OpenCV Mat. | |
static int | CopyToMat< T > (T[] array, Mat mat) |
Copies the data from a managed array to an OpenCV Mat. | |
static int | CopyToMat< T > (T[] array, Mat mat, int length) |
Copies the data from a managed array to an OpenCV Mat. | |
static ComputeShader | CreateMatToRenderTextureComputeShader (GraphicsBuffer graphicsBuffer, RenderTexture renderTexture, bool flip=true, int flipCode=0) |
Creates a ComputeShader for converting from Mat to RenderTexture based on the current platform and graphics API. This ComputeShader is intended to be used with the kernel index obtained from the GetKernelIndexForMatToRenderTextureComputeShader method when dispatching. | |
static ComputeShader | CreateRenderTextureToMatComputeShader (RenderTexture renderTexture, GraphicsBuffer graphicsBuffer, bool flip=true, int flipCode=0) |
Creates a ComputeShader for converting from RenderTexture to Mat based on the current platform and graphics API. This ComputeShader is intended to be used with the kernel index obtained from the GetKernelIndexForRenderTextureToMatComputeShader method when dispatching. | |
static int | GetKernelIndexForMatToRenderTextureComputeShader (GraphicsBuffer graphicsBuffer, RenderTexture renderTexture) |
Gets the kernel index to use for converting from Mat to RenderTexture based on the current platform and graphics API. This kernel index is intended to be used when dispatching the ComputeShader obtained from the CreateMatToRenderTextureComputeShader method. | |
static int | GetKernelIndexForRenderTextureToMatComputeShader (RenderTexture renderTexture, GraphicsBuffer graphicsBuffer) |
Gets the kernel index to use for converting from RenderTexture to Mat based on the current platform and graphics API. This kernel index is intended to be used when dispatching the ComputeShader obtained from the CreateRenderTextureToMatComputeShader method. | |
static void | GraphicsBufferToMat (GraphicsBuffer graphicsBuffer, Mat mat, CopyMode copyMode) |
Copies data from a Unity GraphicsBuffer to a OpenCV Mat. | |
static async Awaitable | GraphicsBufferToMatAsync (GraphicsBuffer graphicsBuffer, Mat mat, CopyMode copyMode, CancellationToken cancellationToken=default) |
Copies data from a Unity GraphicsBuffer to an OpenCV Mat asynchronously. | |
static void | MatToGraphicsBuffer (Mat mat, GraphicsBuffer graphicsBuffer, CopyMode copyMode) |
Copies data from a OpenCv Mat to a Unity GraphicsBuffer. | |
static async Awaitable< AsyncGPUReadbackRequest > | MatToGraphicsBufferAsync (Mat mat, GraphicsBuffer graphicsBuffer, CopyMode copyMode, CancellationToken cancellationToken=default) |
Copies data from a OpenCv Mat to a Unity GraphicsBuffer asynchronously. | |
static void | MatToRenderTexture (Mat mat, RenderTexture renderTexture, GraphicsBuffer graphicsBuffer, bool flip=true, int flipCode=0) |
Converts an OpenCV Mat to a Unity RenderTexture. | |
static async Awaitable< AsyncGPUReadbackRequest > | MatToRenderTextureAsync (Mat mat, RenderTexture renderTexture, GraphicsBuffer graphicsBuffer, bool flip=true, int flipCode=0, CancellationToken cancellationToken=default) |
Converts an OpenCV Mat to a Unity RenderTexture asynchronously. | |
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 async Awaitable | RenderTextureToMatAsync (RenderTexture renderTexture, Mat mat, GraphicsBuffer graphicsBuffer, bool flip=true, int flipCode=0, CancellationToken cancellationToken=default) |
Converts a Unity RenderTexture to an OpenCV Mat asynchronously. | |
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 async Awaitable | TextureToMatAsync (Texture texture, Mat mat, bool flip=true, int flipCode=0, int mipIndex=0, int x=0, int width=-1, int y=0, int height=-1, int z=0, int depth=1, GraphicsFormat? dstFormat=null, CancellationToken cancellationToken=default) |
Converts a Texture to an OpenCV Mat asynchronously. | |
static async Awaitable | TextureToMatAsync (Texture texture, Mat mat, CancellationToken cancellationToken=default) |
Converts a Texture to an OpenCV Mat asynchronously. | |
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. | |
OpenCV Mat utilities.
Enumeration to specify the data copy method.
|
static |
Copies the data from an OpenCV Mat to an IntPtr.
This method transfers the data stored in an OpenCV Mat object into an IntPtr. It supports both continuous and non-continuous Mat objects:
mat.isContinuous()
is false
and mat.dims()
exceeds 2, the method will throw an exception, as non-continuous Mats with more than 2 dimensions are unsupported.mat.isContinuous()
is true
, the method can copy data from Mats with any number of dimensions.The entire range of data managed by the Mat will be copied to the IntPtr. If you want to specify the exact range of data to copy, please use the method that accepts a length argument.
Note: This method operates on unmanaged memory, and incorrect usage can lead to unpredictable behavior, crashes, or data corruption. Ensure that the source pointer points to a valid memory region and that the specified length does not exceed the allocated memory size for that region. Additionally, as this method involves unmanaged memory, be cautious about potential security risks. Accessing memory beyond the intended range can lead to buffer overflows and may compromise application stability and security. It is highly recommended to perform validation checks on the pointer and the specified length.
Note: This method is specialized for copying a continuous range of data regardless of differences in types between the Mat and the array. Although its functionality is more limited compared to the Mat.get
method, it offers improved performance for such operations.
mat | The source Mat from which data will be copied. The Mat must not be disposed of or null. |
intPtr | The destination IntPtr where the data will be copied. This pointer must reference a valid memory region. |
ArgumentNullException | Thrown when mat is null. |
ArgumentException | Thrown when intPtr == IntPtr.Zero . Thrown when !mat.isContinuous() && mat.dims() > 2 . |
|
static |
Copies the data from an OpenCV Mat to an IntPtr.
This method transfers the data stored in an OpenCV Mat object into an IntPtr. It supports both continuous and non-continuous Mat objects:
mat.isContinuous()
is false
and mat.dims()
exceeds 2, the method will throw an exception, as non-continuous Mats with more than 2 dimensions are unsupported.mat.isContinuous()
is true
, the method can copy data from Mats with any number of dimensions.If the data size of the memory region pointed to by the IntPtr is smaller than the data size managed by the Mat, data will be copied up to the size of the IntPtr. If the data size of the memory region pointed to by the IntPtr is larger, data will be copied up to the size managed by the Mat.
Note: This method operates on unmanaged memory, and incorrect usage can lead to unpredictable behavior, crashes, or data corruption. Ensure that the source pointer points to a valid memory region and that the specified length does not exceed the allocated memory size for that region. Additionally, as this method involves unmanaged memory, be cautious about potential security risks. Accessing memory beyond the intended range can lead to buffer overflows and may compromise application stability and security. It is highly recommended to perform validation checks on the pointer and the specified length.
Note: This method is specialized for copying a continuous range of data regardless of differences in types between the Mat and the array. Although its functionality is more limited compared to the Mat.get
method, it offers improved performance for such operations.
mat | The source Mat from which data will be copied. The Mat must not be disposed of or null. |
intPtr | The destination IntPtr where the data will be copied. This pointer must reference a valid memory region. |
length | The number of elements, in terms of byte size, to copy from the source Mat to the destination IntPtr. The length represents the size in bytes, regardless of the actual type of data in the Mat or the destination. |
ArgumentNullException | Thrown when mat is null. |
ArgumentException | Thrown when intPtr == IntPtr.Zero . Thrown when !mat.isContinuous() && mat.dims() > 2 . |
|
static |
Copies the data from an OpenCV Mat to an IntPtr.
This method transfers the data stored in an OpenCV Mat object into an IntPtr. It supports both continuous and non-continuous Mat objects:
mat.isContinuous()
is false
and mat.dims()
exceeds 2, the method will throw an exception, as non-continuous Mats with more than 2 dimensions are unsupported.mat.isContinuous()
is true
, the method can copy data from Mats with any number of dimensions.If the data size of the memory region pointed to by the IntPtr is smaller than the data size managed by the Mat, data will be copied up to the size of the IntPtr. If the data size of the memory region pointed to by the IntPtr is larger, data will be copied up to the size managed by the Mat.
Note: This method operates on unmanaged memory, and incorrect usage can lead to unpredictable behavior, crashes, or data corruption. Ensure that the source pointer points to a valid memory region and that the specified length does not exceed the allocated memory size for that region. Additionally, as this method involves unmanaged memory, be cautious about potential security risks. Accessing memory beyond the intended range can lead to buffer overflows and may compromise application stability and security. It is highly recommended to perform validation checks on the pointer and the specified length.
Note: This method is specialized for copying a continuous range of data regardless of differences in types between the Mat and the array. Although its functionality is more limited compared to the Mat.get
method, it offers improved performance for such operations.
T | The type of the elements represented by the IntPtr. This must be an unmanaged type (i.e., a type without references to managed objects) to allow for direct memory access. |
mat | The source Mat from which data will be copied. The Mat must not be disposed of or null. |
intPtr | The destination IntPtr where the data will be copied. This pointer must reference a valid memory region. |
length | The number of elements of type T to copy from the source Mat to the destination IntPtr. |
ArgumentNullException | Thrown when mat is null. |
ArgumentException | Thrown when intPtr == IntPtr.Zero . Thrown when !mat.isContinuous() && mat.dims() > 2 . |
T | : | unmanaged |
|
static |
Copies the data from an OpenCV Mat to a NativeArray.
This method transfers the data stored in an OpenCV Mat object into a NativeArray. It supports both continuous and non-continuous Mat objects:
mat.isContinuous()
is false
and mat.dims()
exceeds 2, the method will throw an exception, as non-continuous Mats with more than 2 dimensions are unsupported.mat.isContinuous()
is true
, the method can copy data from Mats with any number of dimensions.If the data size managed by the array is smaller than the data size managed by the Mat, data will be copied up to the size of the array. If the data size managed by the array is larger, data will be copied up to the size managed by the Mat.
Note: This method is specialized for copying a continuous range of data regardless of differences in types between the Mat and the array. Although its functionality is more limited compared to the Mat.get
method, it offers improved performance for such operations.
T | The type of the elements in the NativeArray. This must be an unmanaged type (i.e., a type without references to managed objects) to allow for direct memory access. |
mat | The source Mat from which data will be copied. The Mat must not be disposed of or null. |
array | The destination NativeArray where the data will be copied. |
ArgumentNullException | Thrown when mat or array is null. |
ArgumentException | Thrown when !mat.isContinuous() && mat.dims() > 2 . |
T | : | unmanaged |
|
static |
Copies the data from an OpenCV Mat to a NativeArray.
This method transfers the data stored in an OpenCV Mat object into a NativeArray. It supports both continuous and non-continuous Mat objects:
mat.isContinuous()
is false
and mat.dims()
exceeds 2, the method will throw an exception, as non-continuous Mats with more than 2 dimensions are unsupported.mat.isContinuous()
is true
, the method can copy data from Mats with any number of dimensions.If the data size managed by the array is smaller than the data size managed by the Mat, data will be copied up to the size of the array. If the data size managed by the array is larger, data will be copied up to the size managed by the Mat.
Note: This method is specialized for copying a continuous range of data regardless of differences in types between the Mat and the array. Although its functionality is more limited compared to the Mat.get
method, it offers improved performance for such operations.
T | The type of the elements in the NativeArray. This must be an unmanaged type (i.e., a type without references to managed objects) to allow for direct memory access. |
mat | The source Mat from which data will be copied. The Mat must not be disposed of or null. |
array | The destination NativeArray where the data will be copied. |
length | The number of elements of type T to copy from the source Mat to the destination managed array. |
ArgumentNullException | Thrown when mat or array is null. |
ArgumentException | Thrown when !mat.isContinuous() && mat.dims() > 2 . |
T | : | unmanaged |
|
static |
Copies the data from an OpenCV Mat to a Span.
This method transfers the data stored in an OpenCV Mat object into a Span. It supports both continuous and non-continuous Mat objects:
mat.isContinuous()
is false
and mat.dims()
exceeds 2, the method will throw an exception, as non-continuous Mats with more than 2 dimensions are unsupported.mat.isContinuous()
is true
, the method can copy data from Mats with any number of dimensions.If the data size managed by the array is smaller than the data size managed by the Mat, data will be copied up to the size of the array. If the data size managed by the array is larger, data will be copied up to the size managed by the Mat.
Note: This method is specialized for copying a continuous range of data regardless of differences in types between the Mat and the array. Although its functionality is more limited compared to the Mat.get
method, it offers improved performance for such operations.
T | The type of the elements in the Span. This must be an unmanaged type (i.e., a type without references to managed objects) to allow for direct memory access. |
mat | The source Mat from which data will be copied. The Mat must not be disposed of or null. |
array | The destination Span where the data will be copied. |
ArgumentNullException | Thrown when mat or array is null. |
ArgumentException | Thrown when !mat.isContinuous() && mat.dims() > 2 . |
T | : | unmanaged |
|
static |
Copies the data from an OpenCV Mat to a Span.
This method transfers the data stored in an OpenCV Mat object into a Span. It supports both continuous and non-continuous Mat objects:
mat.isContinuous()
is false
and mat.dims()
exceeds 2, the method will throw an exception, as non-continuous Mats with more than 2 dimensions are unsupported.mat.isContinuous()
is true
, the method can copy data from Mats with any number of dimensions.If the data size managed by the array is smaller than the data size managed by the Mat, data will be copied up to the size of the array. If the data size managed by the array is larger, data will be copied up to the size managed by the Mat.
Note: This method is specialized for copying a continuous range of data regardless of differences in types between the Mat and the array. Although its functionality is more limited compared to the Mat.get
method, it offers improved performance for such operations.
T | The type of the elements in the Span. This must be an unmanaged type (i.e., a type without references to managed objects) to allow for direct memory access. |
mat | The source Mat from which data will be copied. The Mat must not be disposed of or null. |
array | The destination Span where the data will be copied. |
length | The number of elements of type T to copy from the source Mat to the destination Span. |
ArgumentNullException | Thrown when mat or array is null. |
ArgumentException | Thrown when !mat.isContinuous() && mat.dims() > 2 . |
T | : | unmanaged |
|
static |
Copies the data from an OpenCV Mat to a managed array.
This method transfers the data stored in an OpenCV Mat object into a managed array. It supports both continuous and non-continuous Mat objects:
mat.isContinuous()
is false
and mat.dims()
exceeds 2, the method will throw an exception, as non-continuous Mats with more than 2 dimensions are unsupported.mat.isContinuous()
is true
, the method can copy data from Mats with any number of dimensions.If the data size managed by the array is smaller than the data size managed by the Mat, data will be copied up to the size of the array. If the data size managed by the array is larger, data will be copied up to the size managed by the Mat.
Note: This method is specialized for copying a continuous range of data regardless of differences in types between the Mat and the array. Although its functionality is more limited compared to the Mat.get
method, it offers improved performance for such operations.
T | The type of the elements in the managed array. This must be an unmanaged type (i.e., a type without references to managed objects) to allow for direct memory access. |
mat | The source Mat from which data will be copied. The Mat must not be disposed of or null. |
array | The destination managed array where the data will be copied. |
ArgumentNullException | Thrown when mat or array is null. |
ArgumentException | Thrown when !mat.isContinuous() && mat.dims() > 2 . |
T | : | unmanaged |
|
static |
Copies the data from an OpenCV Mat to a managed array.
This method transfers the data stored in an OpenCV Mat object into a managed array. It supports both continuous and non-continuous Mat objects:
mat.isContinuous()
is false
and mat.dims()
exceeds 2, the method will throw an exception, as non-continuous Mats with more than 2 dimensions are unsupported.mat.isContinuous()
is true
, the method can copy data from Mats with any number of dimensions.If the data size managed by the array is smaller than the data size managed by the Mat, data will be copied up to the size of the array. If the data size managed by the array is larger, data will be copied up to the size managed by the Mat.
Note: This method is specialized for copying a continuous range of data regardless of differences in types between the Mat and the array. Although its functionality is more limited compared to the Mat.get
method, it offers improved performance for such operations.
T | The type of the elements in the managed array. This must be an unmanaged type (i.e., a type without references to managed objects) to allow for direct memory access. |
mat | The source Mat from which data will be copied. The Mat must not be disposed of or null. |
array | The destination managed array where the data will be copied. |
length | The number of elements of type T to copy from the source Mat to the destination managed array. |
ArgumentNullException | Thrown when mat or array is null. |
ArgumentException | Thrown when !mat.isContinuous() && mat.dims() > 2 . |
T | : | unmanaged |
|
static |
Copies the data from an IntPtr to an OpenCV Mat.
This method transfers the data stored in an IntPtr to an OpenCV Mat. It supports both continuous and non-continuous Mat objects:
mat.isContinuous()
is false
and mat.dims()
exceeds 2, the method will throw an exception, as non-continuous Mats with more than 2 dimensions are unsupported.mat.isContinuous()
is true
, the method can copy data from Mats with any number of dimensions.Data of the same size in bytes as the data managed by the Mat is copied from the IntPtr to the Mat. If you want to specify the exact range of data to copy, please use the method that accepts a length argument.
Note: This method operates on unmanaged memory, and incorrect usage can lead to unpredictable behavior, crashes, or data corruption. Ensure that the source pointer points to a valid memory region and that the specified length does not exceed the allocated memory size for that region. Additionally, as this method involves unmanaged memory, be cautious about potential security risks. Accessing memory beyond the intended range can lead to buffer overflows and may compromise application stability and security. It is highly recommended to perform validation checks on the pointer and the specified length.
Note: This method is specialized for copying a continuous range of data regardless of differences in types between the array and the Mat. Although its functionality is more limited compared to the Mat.put
method, it offers improved performance for such operations.
intPtr | The source IntPtr from which data will be copied. This pointer must reference a valid memory region. |
mat | The destination Mat where the data will be copied. The Mat must not be disposed of or null. |
ArgumentNullException | Thrown when mat is null. |
ArgumentException | Thrown when intPtr == IntPtr.Zero . Thrown when !mat.isContinuous() && mat.dims() > 2 . |
|
static |
Copies the data from an IntPtr to an OpenCV Mat.
This method transfers the data stored in an IntPtr to an OpenCV Mat. It supports both continuous and non-continuous Mat objects:
mat.isContinuous()
is false
and mat.dims()
exceeds 2, the method will throw an exception, as non-continuous Mats with more than 2 dimensions are unsupported.mat.isContinuous()
is true
, the method can copy data from Mats with any number of dimensions.If the data size managed by the Mat is smaller than the data size of the memory region pointed to by the IntPtr, data will be copied up to the size of the mat. If the data size managed by the Mat is larger, data will be copied up to the size of the memory region pointed to by the IntPtr.
Note: This method operates on unmanaged memory, and incorrect usage can lead to unpredictable behavior, crashes, or data corruption. Ensure that the source pointer points to a valid memory region and that the specified length does not exceed the allocated memory size for that region. Additionally, as this method involves unmanaged memory, be cautious about potential security risks. Accessing memory beyond the intended range can lead to buffer overflows and may compromise application stability and security. It is highly recommended to perform validation checks on the pointer and the specified length.
Note: This method is specialized for copying a continuous range of data regardless of differences in types between the array and the Mat. Although its functionality is more limited compared to the Mat.put
method, it offers improved performance for such operations.
intPtr | The source IntPtr from which data will be copied. This pointer must reference a valid memory region. |
mat | The destination Mat where the data will be copied. The Mat must not be disposed of or null. |
length | The number of elements, in terms of byte size, to copy from the source IntPtr to the destination Mat. The length represents the size in bytes, regardless of the actual type of data in the IntPtr or the destination. |
ArgumentNullException | Thrown when mat is null. |
ArgumentException | Thrown when intPtr == IntPtr.Zero . Thrown when !mat.isContinuous() && mat.dims() > 2 . |
|
static |
Copies the data from an IntPtr to an OpenCV Mat.
This method transfers the data stored in an IntPtr to an OpenCV Mat. It supports both continuous and non-continuous Mat objects:
mat.isContinuous()
is false
and mat.dims()
exceeds 2, the method will throw an exception, as non-continuous Mats with more than 2 dimensions are unsupported.mat.isContinuous()
is true
, the method can copy data from Mats with any number of dimensions.If the data size managed by the Mat is smaller than the data size of the memory region pointed to by the IntPtr, data will be copied up to the size of the mat. If the data size managed by the Mat is larger, data will be copied up to the size of the memory region pointed to by the IntPtr.
Note: This method operates on unmanaged memory, and incorrect usage can lead to unpredictable behavior, crashes, or data corruption. Ensure that the source pointer points to a valid memory region and that the specified length does not exceed the allocated memory size for that region. Additionally, as this method involves unmanaged memory, be cautious about potential security risks. Accessing memory beyond the intended range can lead to buffer overflows and may compromise application stability and security. It is highly recommended to perform validation checks on the pointer and the specified length.
Note: This method is specialized for copying a continuous range of data regardless of differences in types between the array and the Mat. Although its functionality is more limited compared to the Mat.put
method, it offers improved performance for such operations.
T | The type of the elements represented by the IntPtr. This must be an unmanaged type (i.e., a type without references to managed objects) to allow for direct memory access. |
intPtr | The source IntPtr from which data will be copied. This pointer must reference a valid memory region. |
mat | The destination Mat where the data will be copied. The Mat must not be disposed of or null. |
length | The number of elements of type T to copy from the source IntPtr to the destination Mat. |
ArgumentNullException | Thrown when mat is null. |
ArgumentException | Thrown when intPtr == IntPtr.Zero . Thrown when !mat.isContinuous() && mat.dims() > 2 . |
T | : | unmanaged |
|
static |
Copies the data from a NativeArray to an OpenCV Mat.
This method transfers the data stored in a NativeArray into an OpenCV Mat object. It supports both continuous and non-continuous Mat objects:
mat.isContinuous()
is false
and mat.dims()
exceeds 2, the method will throw an exception, as non-continuous Mats with more than 2 dimensions are unsupported.mat.isContinuous()
is true
, the method can copy data where Mats with any number of dimensions.If the data size managed by the Mat is smaller than the data size managed by the array, data will be copied up to the size of the mat. If the data size managed by the Mat is larger, data will be copied up to the size managed by the array.
Note: This method is specialized for copying a continuous range of data regardless of differences in types between the array and the Mat. Although its functionality is more limited compared to the Mat.put
method, it offers improved performance for such operations.
T | The type of the elements in the NativeArray. This must be an unmanaged type (i.e., a type without references to managed objects) to allow for direct memory access. |
array | The source NativeArray from which data will be copied. |
mat | The destination Mat where the data will be copied. The Mat must not be disposed of or null. |
ArgumentNullException | Thrown when array or mat is null. |
ArgumentException | Thrown when !mat.isContinuous() && mat.dims() > 2 . |
T | : | unmanaged |
|
static |
Copies the data from a NativeArray to an OpenCV Mat.
This method transfers the data stored in a NativeArray into an OpenCV Mat object. It supports both continuous and non-continuous Mat objects:
mat.isContinuous()
is false
and mat.dims()
exceeds 2, the method will throw an exception, as non-continuous Mats with more than 2 dimensions are unsupported.mat.isContinuous()
is true
, the method can copy data where Mats with any number of dimensions.If the data size managed by the Mat is smaller than the data size managed by the array, data will be copied up to the size of the mat. If the data size managed by the Mat is larger, data will be copied up to the size managed by the array.
Note: This method is specialized for copying a continuous range of data regardless of differences in types between the array and the Mat. Although its functionality is more limited compared to the Mat.put
method, it offers improved performance for such operations.
T | The type of the elements in the NativeArray. This must be an unmanaged type (i.e., a type without references to managed objects) to allow for direct memory access. |
array | The source NativeArray from which data will be copied. |
mat | The destination Mat where the data will be copied. The Mat must not be disposed of or null. |
length | The number of elements of type T to copy from the source NativeArray to the destination Mat. |
ArgumentNullException | Thrown when array or mat is null. |
ArgumentException | Thrown when !mat.isContinuous() && mat.dims() > 2 . |
T | : | unmanaged |
|
static |
Copies the data from a Span to an OpenCV Mat.
This method transfers the data stored in a Span into an OpenCV Mat object. It supports both continuous and non-continuous Mat objects:
mat.isContinuous()
is false
and mat.dims()
exceeds 2, the method will throw an exception, as non-continuous Mats with more than 2 dimensions are unsupported.mat.isContinuous()
is true
, the method can copy data where Mats with any number of dimensions.If the data size managed by the Mat is smaller than the data size managed by the array, data will be copied up to the size of the mat. If the data size managed by the Mat is larger, data will be copied up to the size managed by the array.
Note: This method is specialized for copying a continuous range of data regardless of differences in types between the array and the Mat. Although its functionality is more limited compared to the Mat.put
method, it offers improved performance for such operations.
T | The type of the elements in the Span. This must be an unmanaged type (i.e., a type without references to managed objects) to allow for direct memory access. |
array | The source Span from which data will be copied. |
mat | The destination Mat where the data will be copied. The Mat must not be disposed of or null. |
ArgumentNullException | Thrown when array or mat is null. |
ArgumentException | Thrown when !mat.isContinuous() && mat.dims() > 2 . |
T | : | unmanaged |
|
static |
Copies the data from a Span to an OpenCV Mat.
This method transfers the data stored in a Span into an OpenCV Mat object. It supports both continuous and non-continuous Mat objects:
mat.isContinuous()
is false
and mat.dims()
exceeds 2, the method will throw an exception, as non-continuous Mats with more than 2 dimensions are unsupported.mat.isContinuous()
is true
, the method can copy data where Mats with any number of dimensions.If the data size managed by the Mat is smaller than the data size managed by the array, data will be copied up to the size of the mat. If the data size managed by the Mat is larger, data will be copied up to the size managed by the array.
Note: This method is specialized for copying a continuous range of data regardless of differences in types between the array and the Mat. Although its functionality is more limited compared to the Mat.put
method, it offers improved performance for such operations.
T | The type of the elements in the Span. This must be an unmanaged type (i.e., a type without references to managed objects) to allow for direct memory access. |
array | The source Span from which data will be copied. |
mat | The destination Mat where the data will be copied. The Mat must not be disposed of or null. |
length | The number of elements of type T to copy from the source Span to the destination Mat. |
ArgumentNullException | Thrown when array or mat is null. |
ArgumentException | Thrown when !mat.isContinuous() && mat.dims() > 2 . |
T | : | unmanaged |
|
static |
Copies the data from a managed array to an OpenCV Mat.
This method transfers the data stored in a managed array into an OpenCV Mat object. It supports both continuous and non-continuous Mat objects:
mat.isContinuous()
is false
and mat.dims()
exceeds 2, the method will throw an exception, as non-continuous Mats with more than 2 dimensions are unsupported.mat.isContinuous()
is true
, the method can copy data where Mats with any number of dimensions.If the data size managed by the Mat is smaller than the data size managed by the array, data will be copied up to the size of the mat. If the data size managed by the Mat is larger, data will be copied up to the size managed by the array.
Note: This method is specialized for copying a continuous range of data regardless of differences in types between the array and the Mat. Although its functionality is more limited compared to the Mat.put
method, it offers improved performance for such operations.
T | The type of the elements in the managed array. This must be an unmanaged type (i.e., a type without references to managed objects) to allow for direct memory access. |
array | The source managed array from which data will be copied. |
mat | The destination Mat where the data will be copied. The Mat must not be disposed of or null. |
ArgumentNullException | Thrown when array or mat is null. |
ArgumentException | Thrown when !mat.isContinuous() && mat.dims() > 2 . |
T | : | unmanaged |
|
static |
Copies the data from a managed array to an OpenCV Mat.
This method transfers the data stored in a managed array into an OpenCV Mat object. It supports both continuous and non-continuous Mat objects:
mat.isContinuous()
is false
and mat.dims()
exceeds 2, the method will throw an exception, as non-continuous Mats with more than 2 dimensions are unsupported.mat.isContinuous()
is true
, the method can copy data where Mats with any number of dimensions.If the data size managed by the Mat is smaller than the data size managed by the array, data will be copied up to the size of the mat. If the data size managed by the Mat is larger, data will be copied up to the size managed by the array.
Note: This method is specialized for copying a continuous range of data regardless of differences in types between the array and the Mat. Although its functionality is more limited compared to the Mat.put
method, it offers improved performance for such operations.
T | The type of the elements in the managed array. This must be an unmanaged type (i.e., a type without references to managed objects) to allow for direct memory access. |
array | The source managed array from which data will be copied. |
mat | The destination Mat where the data will be copied. The Mat must not be disposed of or null. |
length | The number of elements of type T to copy from the source managed array to the destination Mat. |
ArgumentNullException | Thrown when array or mat is null. |
ArgumentException | Thrown when !mat.isContinuous() && mat.dims() > 2 . |
T | : | unmanaged |
|
static |
Creates a ComputeShader for converting from Mat to RenderTexture based on the current platform and graphics API. This ComputeShader is intended to be used with the kernel index obtained from the GetKernelIndexForMatToRenderTextureComputeShader method when dispatching.
graphicsBuffer | The source GraphicsBuffer. |
renderTexture | The destination RenderTexture. |
flip | Whether to flip the image vertically. |
flipCode | The flipCode for the Core.flip() method. |
|
static |
Creates a ComputeShader for converting from RenderTexture to Mat based on the current platform and graphics API. This ComputeShader is intended to be used with the kernel index obtained from the GetKernelIndexForRenderTextureToMatComputeShader method when dispatching.
renderTexture | The source RenderTexture. |
graphicsBuffer | The destination GraphicsBuffer. |
flip | Whether to flip the image vertically. |
flipCode | The flipCode for the Core.flip() method. |
|
static |
Gets the kernel index to use for converting from Mat to RenderTexture based on the current platform and graphics API. This kernel index is intended to be used when dispatching the ComputeShader obtained from the CreateMatToRenderTextureComputeShader method.
graphicsBuffer | The source GraphicsBuffer. |
renderTexture | The destination RenderTexture. |
|
static |
Gets the kernel index to use for converting from RenderTexture to Mat based on the current platform and graphics API. This kernel index is intended to be used when dispatching the ComputeShader obtained from the CreateRenderTextureToMatComputeShader method.
renderTexture | The source RenderTexture. |
graphicsBuffer | The destination GraphicsBuffer. |
|
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 Unity GraphicsBuffer to an OpenCV Mat asynchronously.
graphicsBuffer | The source Unity GraphicsBuffer. |
mat | The destination OpenCV Mat. |
copyMode | The CopyMode enumeration specifying the method of copying data. |
cancellationToken | A token to monitor for cancellation requests. |
ArgumentNullException | Thrown if mat or graphicsBuffer is null. |
ArgumentException | Thrown if data size or stride does not match. |
NotSupportedException | Thrown if compute shaders are not supported on the current platform. |
OperationCanceledException | Thrown if the operation is canceled via cancellationToken . |
|
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 |
Copies data from a OpenCv Mat to a Unity GraphicsBuffer asynchronously.
mat | The source OpenCV Mat. |
graphicsBuffer | The destination Unity GraphicsBuffer. |
copyMode | The CopyMode enumeration specifying the method of copying data. |
cancellationToken | Cancellation token to cancel the asynchronous operation. |
ArgumentNullException | Thrown if mat or graphicsBuffer is null. |
ArgumentException | Thrown if data size or stride does not match. |
OperationCanceledException | Thrown when the operation is canceled via the cancellationToken . |
|
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 RenderTexture asynchronously.
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. |
cancellationToken | A token to monitor for cancellation requests. |
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. |
OperationCanceledException | Thrown if the operation is canceled via cancellationToken . |
|
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 |
Converts a Unity RenderTexture to an OpenCV Mat asynchronously.
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. |
cancellationToken | A token to monitor for cancellation requests. |
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. |
OperationCanceledException | Thrown if the operation is canceled via cancellationToken . |
|
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 |
Converts a Texture to an OpenCV Mat asynchronously.
texture | The source Texture to be converted. |
mat | The destination Mat that will store the converted texture data. |
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 . |
mipIndex | Index of the mipmap to be fetched. |
x | Starting X coordinate in pixels of the Texture data to be fetched. |
width | Width in pixels of the Texture data to be fetched. |
y | Starting Y coordinate in pixels of the Texture data to be fetched. |
height | Height in pixels of the Texture data to be fetched. |
z | Depth in pixels for Texture3D being fetched. Number of layers for TextureCube, TextureArray and TextureCubeArray. |
depth | Depth in pixels for Texture3D being fetched. Number of layers for TextureCube, TextureArray and TextureCubeArray. |
dstFormat | Target GraphicsFormat of the data. If the target format is different from the format stored on the GPU, the conversion is automatic. |
cancellationToken | Cancellation token to cancel the asynchronous operation. |
ArgumentNullException | Thrown if texture or mat is null. |
NotSupportedException | Thrown when the graphics format of the texture is not supported for reading using AsyncGPUReadback. |
OperationCanceledException | Thrown when the operation is canceled via the cancellationToken . |
InvalidOperationException | Thrown when AsyncGPUReadback completes with an error. |
|
static |
Converts a Texture to an OpenCV Mat asynchronously.
texture | The source Texture to be converted. |
mat | The destination Mat that will store the converted texture data. |
cancellationToken | Cancellation token to cancel the asynchronous operation. |
ArgumentNullException | Thrown if texture or mat is null. |
NotSupportedException | Thrown when the graphics format of the texture is not supported for reading using AsyncGPUReadback. |
OperationCanceledException | Thrown when the operation is canceled via the cancellationToken . |
InvalidOperationException | Thrown when AsyncGPUReadback completes with an error. |
|
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.
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). |
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. (WebCamTexture.GetPixels32) |
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 |