diff options
author | Tiago Conceição <Tiago_caza@hotmail.com> | 2020-10-10 23:28:09 +0300 |
---|---|---|
committer | Tiago Conceição <Tiago_caza@hotmail.com> | 2020-10-10 23:28:09 +0300 |
commit | d88b2dd455b3fc860730df03f65cef981e78e405 (patch) | |
tree | 1ff439838e342f6adb24c8a06c7a8ef757bc2775 /UVtools.Core/Extensions/EmguExtensions.cs | |
parent | 27cbfc2aef9a04e4140dc694847bf5a6d0cd0bec (diff) |
Fix blank mats
Diffstat (limited to 'UVtools.Core/Extensions/EmguExtensions.cs')
-rw-r--r-- | UVtools.Core/Extensions/EmguExtensions.cs | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/UVtools.Core/Extensions/EmguExtensions.cs b/UVtools.Core/Extensions/EmguExtensions.cs index 4cbb507..e022816 100644 --- a/UVtools.Core/Extensions/EmguExtensions.cs +++ b/UVtools.Core/Extensions/EmguExtensions.cs @@ -11,11 +11,14 @@ using System.Drawing; using System.Runtime.InteropServices; using Emgu.CV; using Emgu.CV.CvEnum; +using Emgu.CV.Structure; namespace UVtools.Core.Extensions { public static class EmguExtensions { + public static readonly MCvScalar BlackByte = new MCvScalar(0); + public static unsafe byte* GetBytePointer(this Mat mat) { return (byte*)mat.DataPointer.ToPointer(); @@ -181,7 +184,7 @@ namespace UVtools.Core.Extensions /// <returns>Blanked <see cref="Mat"/></returns> public static Mat CloneBlank(this Mat mat) { - return new Mat(new Size(mat.Width, mat.Height), mat.Depth, mat.NumberOfChannels); + return InitMat(mat.Size, mat.Depth, mat.NumberOfChannels); } public static byte GetByte(this Mat mat, int pos) @@ -210,5 +213,12 @@ namespace UVtools.Core.Extensions public static void SetBytes(this Mat mat, byte[] value) => Marshal.Copy(value, 0, mat.DataPointer, value.Length); + public static Mat InitMat(Size size, DepthType depthType = DepthType.Cv8U, int channels = 1) + { + var mat = new Mat(size, depthType, channels); + mat.SetTo(BlackByte); + return mat; + } + } } |