|
OpenCV for Unity 3.0.4
Enox Software / Please refer to OpenCV official document ( http://docs.opencv.org/5.0/index.html ) for the details of the argument of the method.
|
OpenCV Mat Unity integration utilities. More...
Public Types | |
| enum | CopyMode { PerPixel , Contiguous } |
| Enumeration to specify the data copy method. More... | |
Static Public Member Functions | |
| 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 an OpenCV Mat. | |
| static async Task | GraphicsBufferToMatAsync (GraphicsBuffer graphicsBuffer, Mat mat, CopyMode copyMode, CancellationToken cancellationToken=default) |
| Copies data from a Unity GraphicsBuffer to an OpenCV Mat asynchronously. | |
| static async Awaitable | GraphicsBufferToMatAwaitableAsync (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 an OpenCV Mat to a Unity GraphicsBuffer. | |
| static async Task< AsyncGPUReadbackRequest > | MatToGraphicsBufferAsync (Mat mat, GraphicsBuffer graphicsBuffer, CopyMode copyMode, CancellationToken cancellationToken=default) |
| Copies data from an OpenCV Mat to a Unity GraphicsBuffer asynchronously. | |
| static async Awaitable< AsyncGPUReadbackRequest > | MatToGraphicsBufferAwaitableAsync (Mat mat, GraphicsBuffer graphicsBuffer, CopyMode copyMode, CancellationToken cancellationToken=default) |
| Copies data from an 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 Task< 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 async Awaitable< AsyncGPUReadbackRequest > | MatToRenderTextureAwaitableAsync (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, 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 Task | 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 async Awaitable | RenderTextureToMatAwaitableAsync (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 Task | 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 Task | TextureToMatAsync (Texture texture, Mat mat, CancellationToken cancellationToken=default) |
| Converts a Texture to an OpenCV Mat asynchronously. | |
| static async Awaitable | TextureToMatAwaitableAsync (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 using Awaitable. | |
| static async Awaitable | TextureToMatAwaitableAsync (Texture texture, Mat mat, CancellationToken cancellationToken=default) |
| Converts a Texture to an OpenCV Mat asynchronously using Awaitable. | |
| 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 Unity integration utilities.
OpenCV Mat Unity integration utilities (ComputeShader).
Enumeration to specify the data copy method.
|
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 apply flipping based on flipCode when true; otherwise, no flipping is applied. |
| 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 apply flipping based on flipCode when true; otherwise, no flipping is applied. |
| 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 an 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 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 an 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 an 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 |
Copies data from an 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 apply flipping based on flipCode when true; otherwise, no flipping is applied. |
| 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 apply flipping based on flipCode when true; otherwise, no flipping is applied. |
| 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 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 apply flipping based on flipCode when true; otherwise, no flipping is applied. |
| 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) |
| 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.
| 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 apply flipping based on flipCode when true; otherwise, no flipping is applied. |
| 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 apply flipping based on flipCode when true; otherwise, no flipping is applied. |
| 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 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 apply flipping based on flipCode when true; otherwise, no flipping is applied. |
| 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 Texture2D 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 Texture2D 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 Texture2D 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 Texture2D 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 Texture2D 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 | Starting Z coordinate in pixels of the Texture data to be fetched. |
| 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 |
Converts a Texture to an OpenCV Mat asynchronously using Awaitable.
| 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 Texture2D 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 | Starting Z coordinate in pixels of the Texture data to be fetched. |
| 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 using Awaitable.
| 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 |