OpenCV for Unity 3.0.5
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.
Loading...
Searching...
No Matches
OpenCVForUnity.Extensions.SourceToMat.SourceToMatUtils Class Reference

Static helpers for color-format conversion and Mat geometric transforms used by SourceToMat. More...

Static Public Member Functions

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.
 

Detailed Description

Static helpers for color-format conversion and Mat geometric transforms used by SourceToMat.

Member Function Documentation

◆ 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
inputMatInput mat to transform.
rotated90MatPre-allocated output for rotation. When null, rotation is skipped. Must be pre-allocated with swapped width/height and the same type as inputMat .
flipVerticalWhether to flip vertically.
flipHorizontalWhether 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
sourceColorFormatColor format of the source mat.
outputColorFormatRequested output color format.
rotate90DegreeWhether a 90-degree clockwise rotation is requested.
flipVerticalWhether a vertical flip is requested.
flipHorizontalWhether 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()

static int OpenCVForUnity.Extensions.SourceToMat.SourceToMatUtils.Channels ( SourceToMatColorFormat type)
static

Gets the number of channels for the specified color format.

Parameters
typeThe color format.
Returns
Number of channels. Returns 1 for GRAY, 3 for RGB/BGR, 4 for RGBA/BGRA. Returns 4 for unknown formats.

◆ ColorConversionCodes()

static int OpenCVForUnity.Extensions.SourceToMat.SourceToMatUtils.ColorConversionCodes ( SourceToMatColorFormat srcType,
SourceToMatColorFormat dstType )
static

Gets the OpenCV color conversion code needed for converting between two color formats.

Parameters
srcTypeThe source color format.
dstTypeThe 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
sourceMatGrabber-sized source mat.
sourceColorFormatColor format of sourceMat .
outputColorFormatRequested output color format.
rotate90DegreeWhether to rotate 90 degrees clockwise after flip.
flipVerticalWhether to flip vertically before rotation.
flipHorizontalWhether to flip horizontally before rotation.
usedUnsupportedColorFallbacktrue when color conversion is unsupported and a same-size copy was used instead.
colorConversionScratchOptional 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
ArgumentNullExceptionsourceMat is null.

◆ TryCopyOrConvertColor()

static bool OpenCVForUnity.Extensions.SourceToMat.SourceToMatUtils.TryCopyOrConvertColor ( Mat sourceMat,
Mat destinationMat,
SourceToMatColorFormat sourceFormat,
SourceToMatColorFormat destinationFormat )
static

Copies sourceMat into destinationMat , converting color when needed.

Parameters
sourceMatSource mat.
destinationMatDestination mat.
sourceFormatSource color format.
destinationFormatDestination 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: