Static helpers for color-format conversion and Mat geometric transforms used by SourceToMat.
More...
|
| static Mat | ApplyMatTransformations (Mat inputMat, Mat rotated90Mat, bool flipVertical, bool flipHorizontal) |
| | Applies horizontal/vertical flips and an optional 90-degree clockwise rotation to inputMat .
|
| |
| static bool | CanReadSourceWithoutCopy (SourceToMatColorFormat sourceColorFormat, SourceToMatColorFormat outputColorFormat, bool rotate90Degree, bool flipVertical, bool flipHorizontal) |
| | Returns whether ProduceOutputMat can read the source without mutating it or returning that same instance.
|
| |
| static int | Channels (SourceToMatColorFormat type) |
| | Gets the number of channels for the specified color format.
|
| |
| static int | ColorConversionCodes (SourceToMatColorFormat srcType, SourceToMatColorFormat dstType) |
| | Gets the OpenCV color conversion code needed for converting between two color formats.
|
| |
| static Mat | ProduceOutputMat (Mat sourceMat, SourceToMatColorFormat sourceColorFormat, SourceToMatColorFormat outputColorFormat, bool rotate90Degree, bool flipVertical, bool flipHorizontal, out bool usedUnsupportedColorFallback, Mat colorConversionScratch=null) |
| | Produces an output mat from a grabber-sized source: color conversion, optional 90-degree clockwise rotation, and flip.
|
| |
| static bool | TryCopyOrConvertColor (Mat sourceMat, Mat destinationMat, SourceToMatColorFormat sourceFormat, SourceToMatColorFormat destinationFormat) |
| | Copies sourceMat into destinationMat , converting color when needed.
|
| |
Static helpers for color-format conversion and Mat geometric transforms used by SourceToMat.
◆ ApplyMatTransformations()
| static Mat OpenCVForUnity.Extensions.SourceToMat.SourceToMatUtils.ApplyMatTransformations |
( |
Mat | inputMat, |
|
|
Mat | rotated90Mat, |
|
|
bool | flipVertical, |
|
|
bool | flipHorizontal ) |
|
static |
Applies horizontal/vertical flips and an optional 90-degree clockwise rotation to inputMat .
- Parameters
-
| inputMat | Input mat to transform. |
| rotated90Mat | Pre-allocated output for rotation. When null, rotation is skipped. Must be pre-allocated with swapped width/height and the same type as inputMat . |
| flipVertical | Whether to flip vertically. |
| flipHorizontal | Whether to flip horizontally. |
- Returns
- rotated90Mat when rotation succeeds; otherwise inputMat .
◆ CanReadSourceWithoutCopy()
| static bool OpenCVForUnity.Extensions.SourceToMat.SourceToMatUtils.CanReadSourceWithoutCopy |
( |
SourceToMatColorFormat | sourceColorFormat, |
|
|
SourceToMatColorFormat | outputColorFormat, |
|
|
bool | rotate90Degree, |
|
|
bool | flipVertical, |
|
|
bool | flipHorizontal ) |
|
static |
Returns whether ProduceOutputMat can read the source without mutating it or returning that same instance.
Returns true when color conversion or a 90-degree rotation will produce a separate result, and neither flip is requested. Flip is applied in place, so any flip request returns false. When this method returns true, ProduceOutputMat does not write to the source mat and does not return that instance. The caller keeps ownership of the source and disposes only the returned mat. When this method returns false, the result may be the source mat after an in-place flip. Pass an owned copy if the original pixels must be preserved.
- Parameters
-
| sourceColorFormat | Color format of the source mat. |
| outputColorFormat | Requested output color format. |
| rotate90Degree | Whether a 90-degree clockwise rotation is requested. |
| flipVertical | Whether a vertical flip is requested. |
| flipHorizontal | Whether a horizontal flip is requested. |
- Returns
true when the source can be read without copy because conversion or rotation allocates a separate result and no flip is requested; otherwise false.
◆ Channels()
Gets the number of channels for the specified color format.
- Parameters
-
- Returns
- Number of channels. Returns 1 for GRAY, 3 for RGB/BGR, 4 for RGBA/BGRA. Returns 4 for unknown formats.
◆ ColorConversionCodes()
Gets the OpenCV color conversion code needed for converting between two color formats.
- Parameters
-
| srcType | The source color format. |
| dstType | The destination color format. |
- Returns
- OpenCV color conversion code. Returns -1 if conversion is not possible.
Supported color format conversions:
- GRAY ⇔ RGB/BGR/RGBA/BGRA
- RGB ⇔ GRAY/BGR/RGBA/BGRA
- BGR ⇔ GRAY/RGB/RGBA/BGRA
- RGBA ⇔ GRAY/RGB/BGR/BGRA
- BGRA ⇔ GRAY/RGB/BGR/RGBA
◆ ProduceOutputMat()
| static Mat OpenCVForUnity.Extensions.SourceToMat.SourceToMatUtils.ProduceOutputMat |
( |
Mat | sourceMat, |
|
|
SourceToMatColorFormat | sourceColorFormat, |
|
|
SourceToMatColorFormat | outputColorFormat, |
|
|
bool | rotate90Degree, |
|
|
bool | flipVertical, |
|
|
bool | flipHorizontal, |
|
|
out bool | usedUnsupportedColorFallback, |
|
|
Mat | colorConversionScratch = null ) |
|
static |
Produces an output mat from a grabber-sized source: color conversion, optional 90-degree clockwise rotation, and flip.
Does not take ownership of sourceMat . When the returned instance is not sourceMat , the caller still owns sourceMat . When the returned instance is sourceMat , dispose only the result. Flip may mutate sourceMat in place when sourceColorFormat already matches outputColorFormat . The caller owns the returned mat and must dispose it. When CanReadSourceWithoutCopy is true for the same color formats, rotation, and flip arguments, this method does not mutate sourceMat and does not return that instance. When CanReadSourceWithoutCopy is false, the result may be sourceMat after an in-place flip. Pass an owned copy if the original pixels must be preserved. colorConversionScratch is an optional color-conversion destination used only when converting color and rotating. It is never returned. When rotation produces a separate mat, this method does not dispose the scratch so the caller can reuse it. When null, conversion allocates a one-shot mat. Size or type mismatch is reallocated with Mat.create(int, int, int).
- Parameters
-
| sourceMat | Grabber-sized source mat. |
| sourceColorFormat | Color format of sourceMat . |
| outputColorFormat | Requested output color format. |
| rotate90Degree | Whether to rotate 90 degrees clockwise after flip. |
| flipVertical | Whether to flip vertically before rotation. |
| flipHorizontal | Whether to flip horizontally before rotation. |
| usedUnsupportedColorFallback | true when color conversion is unsupported and a same-size copy was used instead. |
| colorConversionScratch | Optional color-conversion destination used only when converting color and rotating. Never returned as the result. When rotation produces a separate mat, this instance is left allocated for reuse. Pass null to allocate a one-shot conversion mat. |
- Returns
- The produced output mat. The caller owns it and must dispose it.
- Exceptions
-
| ArgumentNullException | sourceMat is null. |
◆ TryCopyOrConvertColor()
Copies sourceMat into destinationMat , converting color when needed.
- Parameters
-
| sourceMat | Source mat. |
| destinationMat | Destination mat. |
| sourceFormat | Source color format. |
| destinationFormat | Destination color format. |
- Returns
true when a same-format copy or supported conversion succeeded; false when conversion is unsupported.
The documentation for this class was generated from the following file: