#define TRACE using System; using System.Collections; using System.Collections.Generic; using System.ComponentModel; using System.Diagnostics; using System.Drawing; using System.IO; using System.IO.Compression; using System.Net.Http; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Serialization; using System.Runtime.Versioning; using System.Security.Cryptography; using System.Text; using System.Threading; using System.Threading.Tasks; using System.Xml; using System.Xml.Linq; using System.Xml.Schema; using System.Xml.Serialization; using Emgu.CV.Cuda; using Emgu.CV.CvEnum; using Emgu.CV.Dnn; using Emgu.CV.Features2D; using Emgu.CV.Flann; using Emgu.CV.ML.MlEnum; using Emgu.CV.Ocl; using Emgu.CV.Reflection; using Emgu.CV.Structure; using Emgu.CV.Util; using Emgu.Util; using Emgu.Util.TypeEnum; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETStandard,Version=v2.0", FrameworkDisplayName = "")] [assembly: AssemblyCompany("Emgu Corporation")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyCopyright("Emgu Corporation 2022")] [assembly: AssemblyFileVersion("4.6.0.5131")] [assembly: AssemblyInformationalVersion("4.6.0.5131")] [assembly: AssemblyProduct("Emgu.CV")] [assembly: AssemblyTitle("Emgu.CV")] [assembly: AssemblyVersion("4.6.0.5131")] namespace Emgu.Util { public abstract class DisposableObject : IDisposable { private bool _disposed; public void Dispose() { Dispose(disposing: true); GC.SuppressFinalize(this); } private void Dispose(bool disposing) { if (!_disposed) { _disposed = true; if (disposing) { ReleaseManagedResources(); } DisposeObject(); } } protected virtual void ReleaseManagedResources() { } protected abstract void DisposeObject(); ~DisposableObject() { Dispose(disposing: false); } } public class DownloadableFile { private string _url; private string _localSubfolder; private string _sha256Hash; private string _localFile; public string Url => _url; public bool IsLocalFileValid { get { string localFile = LocalFile; if (!File.Exists(localFile)) { return false; } FileInfo fileInfo = new FileInfo(localFile); if (fileInfo.Length == 0L) { return false; } if (_sha256Hash != null) { using SHA256 sHA = SHA256.Create(); try { using FileStream fileStream = fileInfo.Open(FileMode.Open); fileStream.Position = 0L; string text = ByteArrayToString(sHA.ComputeHash(fileStream)); if (text != _sha256Hash) { Trace.WriteLine($"{localFile}: expecting SHA256 of \"{_sha256Hash}\", got \"{text}\""); return false; } } catch (IOException ex) { Trace.WriteLine("I/O Exception: " + ex.Message); return false; } catch (UnauthorizedAccessException ex2) { Trace.WriteLine("Access Exception: " + ex2.Message); return false; } } return true; } } public string LocalFile { get { if (_localFile != null) { return _localFile; } if (Url == null) { return null; } string fileName = Path.GetFileName(new Uri(Url).LocalPath); return GetLocalFileName(fileName); } set { _localFile = value; } } public string LocalFolder => new FileInfo(LocalFile).DirectoryName; public DownloadableFile(string url, string localSubfolder, string sha256Hash = null) { _url = url; _localSubfolder = localSubfolder; if (sha256Hash != null) { _sha256Hash = sha256Hash.ToUpper(); } else { _sha256Hash = null; } } private static string ByteArrayToString(byte[] array) { StringBuilder stringBuilder = new StringBuilder(); for (int i = 0; i < array.Length; i++) { stringBuilder.Append($"{array[i]:X2}"); } return stringBuilder.ToString(); } public string GetLocalFileName(string fileName) { return Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), _localSubfolder, fileName); } } public class EventArgs : EventArgs { private T _value; public T Value => _value; public EventArgs(T value) { _value = value; } } public class EventArgs : EventArgs { private T1 _value1; private T2 _value2; public T1 Value1 => _value1; public T2 Value2 => _value2; public EventArgs(T1 value1, T2 value2) { _value1 = value1; _value2 = value2; } } public abstract class ExceptionHandler { public abstract bool HandleException(Exception ex); } public class FileDownloadManager { public delegate void DownloadProgressChangedEventHandler(long? totalBytesToReceive, long bytesReceived, double? progressPercentage); public class HttpClientWithProgress : HttpClient { public event DownloadProgressChangedEventHandler DownloadProgressChanged; public async Task DownloadFileTaskAsync(string downloadUrl, string destinationFilePath) { using HttpResponseMessage response = await GetAsync(downloadUrl, HttpCompletionOption.ResponseHeadersRead); await DownloadFileFromHttpResponseMessage(response, destinationFilePath); } private async Task DownloadFileFromHttpResponseMessage(HttpResponseMessage response, string destinationFilePath) { response.EnsureSuccessStatusCode(); long? totalBytes = response.Content.Headers.ContentLength; using System.IO.Stream contentStream = await response.Content.ReadAsStreamAsync(); await ProcessContentStream(totalBytes, contentStream, destinationFilePath); } private async Task ProcessContentStream(long? totalDownloadSize, System.IO.Stream contentStream, string destinationFilePath) { long totalBytesRead = 0L; long readCount = 0L; byte[] buffer = new byte[8192]; bool isMoreToRead = true; using FileStream fileStream = new FileStream(destinationFilePath, FileMode.Create, FileAccess.Write, FileShare.None, 8192, useAsync: true); do { int bytesRead = await contentStream.ReadAsync(buffer, 0, buffer.Length); if (bytesRead == 0) { isMoreToRead = false; TriggerProgressChanged(totalDownloadSize, totalBytesRead); continue; } await fileStream.WriteAsync(buffer, 0, bytesRead); totalBytesRead += bytesRead; readCount++; if (readCount % 100 == 0L) { TriggerProgressChanged(totalDownloadSize, totalBytesRead); } } while (isMoreToRead); } private void TriggerProgressChanged(long? totalDownloadSize, long totalBytesRead) { if (this.DownloadProgressChanged != null) { double? progressPercentage = null; if (totalDownloadSize.HasValue) { progressPercentage = Math.Round((double)totalBytesRead / (double)totalDownloadSize.Value * 100.0, 2); } this.DownloadProgressChanged(totalDownloadSize, totalBytesRead, progressPercentage); } } } private List _files = new List(); public bool AllFilesDownloaded { get { bool flag = true; foreach (DownloadableFile file in _files) { flag &= file.IsLocalFileValid; } return flag; } } public DownloadableFile[] Files => _files.ToArray(); public event DownloadProgressChangedEventHandler OnDownloadProgressChanged; public void Clear() { _files.Clear(); } public void AddFile(string url, string localSubfolder, string sha256Hash = null) { _files.Add(new DownloadableFile(url, localSubfolder, sha256Hash)); } public void AddFile(DownloadableFile downloadableFile) { _files.Add(downloadableFile); } public async Task Download(int retry = 1) { await Download(_files.ToArray(), retry, this.OnDownloadProgressChanged); } private static async Task Download(DownloadableFile[] files, int retry = 1, DownloadProgressChangedEventHandler onDownloadProgressChanged = null) { await DownloadHelperMultiple(files, retry, onDownloadProgressChanged); } private static async Task DownloadHelperMultiple(DownloadableFile[] downloadableFiles, int retry = 1, DownloadProgressChangedEventHandler onDownloadProgressChanged = null) { if (downloadableFiles != null && downloadableFiles.Length != 0) { if (downloadableFiles.Length == 1) { await DownloadHelper(downloadableFiles[0], retry, onDownloadProgressChanged); return; } DownloadableFile downloadableFile = downloadableFiles[0]; DownloadableFile[] remainingFiles = new DownloadableFile[downloadableFiles.Length - 1]; Array.Copy(downloadableFiles, 1, remainingFiles, 0, remainingFiles.Length); await DownloadHelper(downloadableFile, retry, onDownloadProgressChanged); await DownloadHelperMultiple(remainingFiles, retry, onDownloadProgressChanged); } } private static async Task DownloadHelper(DownloadableFile downloadableFile, int retry = 1, DownloadProgressChangedEventHandler onDownloadProgressChanged = null) { if (downloadableFile.Url == null || downloadableFile.IsLocalFileValid) { return; } try { Trace.WriteLine("downloading file from:" + downloadableFile.Url + " to: " + downloadableFile.LocalFile); HttpClientWithProgress httpClientWithProgress = new HttpClientWithProgress(); if (onDownloadProgressChanged != null) { httpClientWithProgress.DownloadProgressChanged += onDownloadProgressChanged; } FileInfo fileInfo = new FileInfo(downloadableFile.LocalFile); if (!fileInfo.Directory.Exists) { fileInfo.Directory.Create(); } await httpClientWithProgress.DownloadFileTaskAsync(downloadableFile.Url, downloadableFile.LocalFile); } catch (Exception value) { if (!downloadableFile.IsLocalFileValid) { File.Delete(downloadableFile.LocalFile); } if (retry <= 0) { Trace.WriteLine(value); throw; } await DownloadHelper(downloadableFile, retry - 1); } } } public interface ICodeGenerable { string ToCode(ProgrammingLanguage language); } public interface IInterpolatable where T : new() { double InterpolationIndex { get; } T LinearInterpolate(T other, double index); } public class PinnedArray : DisposableObject { private T[] _array; private GCHandle _handle; public T[] Array => _array; public PinnedArray(int size) { _array = new T[size]; _handle = GCHandle.Alloc(_array, GCHandleType.Pinned); } public IntPtr AddrOfPinnedObject() { return _handle.AddrOfPinnedObject(); } protected override void ReleaseManagedResources() { _handle.Free(); } protected override void DisposeObject() { } } public static class Platform { public enum OS { Unknown, Windows, Linux, MacOS, IOS, Android } public enum Clr { Unknown, DotNet, DotNetNative, Mono, Unity } private static readonly OS _os; private static readonly Clr _runtime; public static OS OperationSystem => _os; public static Clr ClrType => _runtime; static Platform() { if (RuntimeInformation.FrameworkDescription.ToLower().StartsWith(".net native")) { _runtime = Clr.DotNetNative; } else if (RuntimeInformation.FrameworkDescription.ToLower().StartsWith(".net core")) { _runtime = Clr.DotNet; } else if (RuntimeInformation.FrameworkDescription.ToLower().StartsWith(".net ")) { _runtime = Clr.DotNet; } if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { _os = OS.Windows; } else if (Toolbox.FindAssembly("Mono.Android.dll") != null) { _os = OS.Android; _runtime = Clr.Mono; } else if (Toolbox.FindAssembly("Microsoft.Android.dll") != null) { _os = OS.Android; _runtime = Clr.DotNet; } else if (Toolbox.FindAssembly("Xamarin.iOS.dll") != null) { _os = OS.IOS; _runtime = Clr.Mono; } else if (Toolbox.FindAssembly("Microsoft.iOS.dll") != null) { _os = OS.IOS; _runtime = Clr.DotNet; } else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) { _os = OS.MacOS; } else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) { _os = OS.Linux; } else { _os = OS.Unknown; _runtime = Clr.Unknown; } } } public static class Toolbox { private static Dictionary _assemblyNameDict = new Dictionary(); public static XDocument XmlSerialize(T sourceObject) { StringBuilder stringBuilder = new StringBuilder(); using (StringWriter textWriter = new StringWriter(stringBuilder)) { new XmlSerializer(typeof(T)).Serialize(textWriter, sourceObject); } return XDocument.Parse(stringBuilder.ToString()); } public static XDocument XmlSerialize(T sourceObject, Type[] knownTypes) { StringBuilder stringBuilder = new StringBuilder(); using (StringWriter textWriter = new StringWriter(stringBuilder)) { new XmlSerializer(typeof(T), knownTypes).Serialize(textWriter, sourceObject); } return XDocument.Parse(stringBuilder.ToString()); } public static T XmlDeserialize(XDocument document) { using XmlReader xmlReader = document.Root.CreateReader(); if (xmlReader.CanReadBinaryContent) { return (T)new XmlSerializer(typeof(T)).Deserialize(xmlReader); } return XmlStringDeserialize(document.ToString()); } public static T XmlDeserialize(XDocument xDoc, Type[] knownTypes) { using XmlReader xmlReader = xDoc.Root.CreateReader(); if (xmlReader.CanReadBinaryContent) { return (T)new XmlSerializer(typeof(T), knownTypes).Deserialize(xmlReader); } using StringReader textReader = new StringReader(xDoc.ToString()); return (T)new XmlSerializer(typeof(T), knownTypes).Deserialize(textReader); } public static T XmlStringDeserialize(string xmlString) { using StringReader textReader = new StringReader(xmlString); return (T)new XmlSerializer(typeof(T)).Deserialize(textReader); } public static int SizeOf() { return Marshal.SizeOf(); } public static byte[] MergeBytes(byte[] a, byte[] b) { byte[] array = new byte[a.Length + b.Length]; Buffer.BlockCopy(a, 0, array, 0, a.Length); Buffer.BlockCopy(b, 0, array, a.Length, b.Length); return array; } public static string ExecuteCmd(string execFileName, string arguments) { using Process process = new Process(); process.StartInfo.FileName = execFileName; process.StartInfo.Arguments = arguments; process.StartInfo.UseShellExecute = false; process.StartInfo.RedirectStandardOutput = true; process.StartInfo.RedirectStandardError = true; try { process.Start(); } catch (Exception) { } string result = process.StandardOutput.ReadToEnd(); process.WaitForExit(); process.Close(); return result; } public static Type GetBaseType(Type currentType, string baseClassName) { if (currentType.Name.Equals(baseClassName)) { return currentType; } Type baseType = currentType.BaseType; if (!(baseType == null)) { return GetBaseType(baseType, baseClassName); } return null; } public static byte[] ToBytes(TData[] data) { int num = Marshal.SizeOf() * data.Length; byte[] array = new byte[num]; GCHandle gCHandle = GCHandle.Alloc(data, GCHandleType.Pinned); Marshal.Copy(gCHandle.AddrOfPinnedObject(), array, 0, num); gCHandle.Free(); return array; } public static IEnumerable LinearInterpolate(IEnumerable src, IEnumerable indexes) where T : IInterpolatable, new() { using IEnumerator sampleEnumerator = src.GetEnumerator(); if (!sampleEnumerator.MoveNext()) { yield break; } T old = sampleEnumerator.Current; if (!sampleEnumerator.MoveNext()) { yield break; } T current = sampleEnumerator.Current; foreach (double index in indexes) { while (index > current.InterpolationIndex && sampleEnumerator.MoveNext()) { old = current; current = sampleEnumerator.Current; } yield return old.LinearInterpolate(current, index); } } public static IEnumerable LinearSubsample(IEnumerable src, double subsampleRate) where T : IInterpolatable, new() { using IEnumerator sampleEnumerator = src.GetEnumerator(); if (!sampleEnumerator.MoveNext()) { yield break; } T old = sampleEnumerator.Current; yield return old; if (!sampleEnumerator.MoveNext()) { yield break; } T current = sampleEnumerator.Current; double currentIndex = old.InterpolationIndex + subsampleRate; bool endOfSubsample = false; while (!endOfSubsample) { while (currentIndex > current.InterpolationIndex) { bool flag; endOfSubsample = (flag = !sampleEnumerator.MoveNext()); if (flag) { break; } old = current; current = sampleEnumerator.Current; } if (!endOfSubsample) { yield return old.LinearInterpolate(current, currentIndex); currentIndex += subsampleRate; } } } public static IEnumerable JoinInterpolatables(params IEnumerable[] enums) where T : IInterpolatable, new() { if (enums.Length == 0) { yield break; } if (enums.Length == 1) { foreach (T item in enums[0]) { yield return item; } yield break; } if (enums.Length == 2) { foreach (T item2 in JoinTwoInterpolatables(enums[0], enums[1])) { yield return item2; } yield break; } int num = enums.Length / 2; IEnumerable[] array = new IEnumerable[num]; IEnumerable[] array2 = new IEnumerable[enums.Length - num]; Array.Copy(enums, array, num); Array.Copy(enums, num, array2, 0, enums.Length - num); foreach (T item3 in JoinTwoInterpolatables(JoinInterpolatables(array), JoinInterpolatables(array2))) { yield return item3; } } private static IEnumerable JoinTwoInterpolatables(IEnumerable enum1, IEnumerable enum2) where T : IInterpolatable, new() { IEnumerator l1 = enum1.GetEnumerator(); IEnumerator l2 = enum2.GetEnumerator(); if (!l1.MoveNext()) { while (l2.MoveNext()) { yield return l2.Current; } yield break; } if (!l2.MoveNext()) { while (l1.MoveNext()) { yield return l1.Current; } yield break; } T s1 = l1.Current; T s2 = l2.Current; while (true) { if (s1.InterpolationIndex < s2.InterpolationIndex) { yield return s1; if (!l1.MoveNext()) { while (l2.MoveNext()) { yield return l2.Current; } yield break; } s1 = l1.Current; } else { yield return s2; if (!l2.MoveNext()) { break; } s2 = l2.Current; } } while (l1.MoveNext()) { yield return l1.Current; } } public static Assembly[] LoadAllDependentAssemblies() { Assembly[] array; try { lock (_assemblyNameDict) { Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies(); bool flag = false; array = assemblies; for (int i = 0; i < array.Length; i++) { AssemblyName name = array[i].GetName(); if (!_assemblyNameDict.ContainsKey(name.ToString())) { _assemblyNameDict.Add(name.ToString(), name); } } array = assemblies; for (int i = 0; i < array.Length; i++) { AssemblyName[] referencedAssemblies = array[i].GetReferencedAssemblies(); foreach (AssemblyName assemblyName in referencedAssemblies) { if (!_assemblyNameDict.ContainsKey(assemblyName.ToString())) { try { Assembly.Load(assemblyName); _assemblyNameDict.Add(assemblyName.ToString(), assemblyName); flag = true; } catch (Exception) { } } } } array = ((!flag) ? assemblies : AppDomain.CurrentDomain.GetAssemblies()); } } catch (Exception) { goto IL_00f9; } return array; IL_00f9: return null; } public static Type[] GetInterfaceImplementationFromAssembly() { Assembly[] array = LoadAllDependentAssemblies(); List list = new List(); if (array != null) { Assembly[] array2 = array; for (int i = 0; i < array2.Length; i++) { Type[] types = array2[i].GetTypes(); foreach (Type type in types) { if (typeof(T).IsAssignableFrom(type) && typeof(T) != type) { list.Add(type); } } } } return list.ToArray(); } public static Assembly FindAssembly(string assembleName) { try { Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies(); foreach (Assembly assembly in assemblies) { if (assembly.ManifestModule.Name.Equals(assembleName)) { return assembly; } } } catch (Exception ex) { Trace.WriteLine($"FindAssembly({assembleName}) failed: {ex.Message}"); } return null; } private static IntPtr LoadLibraryExWindows(string dllname, int flags) { IntPtr intPtr = LoadLibraryEx(dllname, IntPtr.Zero, flags); if (intPtr == IntPtr.Zero) { int lastWin32Error = Marshal.GetLastWin32Error(); Win32Exception ex = new Win32Exception(lastWin32Error); Trace.WriteLine(string.Format("LoadLibraryEx(\"{0}\", 0, {3}) failed with error code {1}: {2}", dllname, (uint)lastWin32Error, ex.Message, flags)); if (lastWin32Error == 5) { Trace.WriteLine($"Please check if the current user has execute permission for file: {dllname} "); } } else { Trace.WriteLine($"LoadLibraryEx(\"{dllname}\", 0, {flags}) successfully loaded library."); } return intPtr; } private static IntPtr LoadLibraryWindows(string dllname) { int flags = ((!Path.IsPathRooted(dllname)) ? 4096 : 4352); IntPtr intPtr = LoadLibraryExWindows(dllname, flags); if (intPtr == IntPtr.Zero) { intPtr = LoadLibraryExWindows(dllname, 0); } if (intPtr == IntPtr.Zero && Environment.OSVersion.Version >= new Version(6, 2)) { IntPtr intPtr2 = LoadPackagedLibrary(dllname, 0); if (!(intPtr2 == IntPtr.Zero)) { Trace.WriteLine($"LoadPackagedLibrary loaded: {dllname}"); return intPtr2; } new Win32Exception(Marshal.GetLastWin32Error()); } return intPtr; } public static IntPtr LoadLibrary(string dllname) { if (Platform.OperationSystem == Platform.OS.Windows) { return LoadLibraryWindows(dllname); } IntPtr intPtr; try { intPtr = Dlopen(dllname, 258); if (intPtr == IntPtr.Zero) { Trace.WriteLine($"Failed to use dlopen to load {dllname}"); } } catch { Trace.WriteLine($"Failed to use dlopen from libdl.so to load {dllname}, will try using libdl.so.2 instead"); intPtr = Dlopen2(dllname, 258); if (intPtr == IntPtr.Zero) { Trace.WriteLine($"Failed to use dlopen from libdl.so.2 to load {dllname}"); } } return intPtr; } [DllImport("Kernel32.dll", SetLastError = true)] private static extern IntPtr LoadPackagedLibrary([MarshalAs(UnmanagedType.LPStr)] string fileName, int dwFlags); [DllImport("Kernel32.dll", SetLastError = true)] private static extern IntPtr LoadLibraryEx([MarshalAs(UnmanagedType.LPStr)] string fileName, IntPtr hFile, int dwFlags); [DllImport("dl", EntryPoint = "dlopen")] private static extern IntPtr Dlopen([MarshalAs(UnmanagedType.LPStr)] string dllname, int mode); [DllImport("libdl.so.2", EntryPoint = "dlopen")] private static extern IntPtr Dlopen2([MarshalAs(UnmanagedType.LPStr)] string dllname, int mode); [DllImport("Kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool SetDllDirectory(string path); public static string GetDllDirectory() { int num = 2048; IntPtr intPtr = Marshal.AllocHGlobal(num); try { if (!GetDllDirectory((uint)num, intPtr)) { return null; } return Marshal.PtrToStringUni(intPtr); } catch (Exception ex) { Trace.WriteLine("Failed to call into GetDllDirectory:" + Environment.NewLine + ex.StackTrace); return null; } finally { Marshal.FreeHGlobal(intPtr); } } [DllImport("Kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)] [return: MarshalAs(UnmanagedType.Bool)] private static extern bool GetDllDirectory(uint nBufferLength, IntPtr lpBuffer); [DllImport("Kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool AddDllDirectory(string path); } public abstract class UnmanagedObject : DisposableObject { protected IntPtr _ptr; public IntPtr Ptr => _ptr; public static implicit operator IntPtr(UnmanagedObject obj) { return obj?._ptr ?? IntPtr.Zero; } } } namespace Emgu.Util.TypeEnum { public enum ProgrammingLanguage { CSharp, CPlusPlus } } namespace Emgu.CV { [DebuggerTypeProxy(typeof(DebuggerProxy))] public class Affine3d : UnmanagedObject { internal class DebuggerProxy { private Affine3d _v; public double[] Values => _v.GetValues(); public DebuggerProxy(Affine3d v) { _v = v; } } public Affine3d() { _ptr = CvInvoke.cveAffine3dCreate(); } public static Affine3d Identity() { return new Affine3d(CvInvoke.cveAffine3dGetIdentity()); } private Affine3d(IntPtr ptr) { _ptr = ptr; } public Affine3d Rotate(double r0, double r1, double r2) { return new Affine3d(CvInvoke.cveAffine3dRotate(_ptr, r0, r1, r2)); } public Affine3d Translate(double t0, double t1, double t2) { return new Affine3d(CvInvoke.cveAffine3dTranslate(_ptr, t0, t1, t2)); } public double[] GetValues() { double[] array = new double[9]; GCHandle gCHandle = GCHandle.Alloc(array, GCHandleType.Pinned); CvInvoke.cveAffine3dGetValues(_ptr, gCHandle.AddrOfPinnedObject()); gCHandle.Free(); return array; } protected override void DisposeObject() { if (IntPtr.Zero != _ptr) { CvInvoke.cveAffine3dRelease(ref _ptr); } } } public static class CvInvoke { [UnmanagedFunctionPointer(CallingConvention.Cdecl)] public delegate int CvErrorCallback(int status, IntPtr funcName, IntPtr errMsg, IntPtr fileName, int line, IntPtr userData); private static readonly bool _libraryLoaded; public const UnmanagedType StringMarshalType = UnmanagedType.LPStr; public const UnmanagedType BoolMarshalType = UnmanagedType.U1; public const UnmanagedType BoolToIntMarshalType = UnmanagedType.Bool; public const CallingConvention CvCallingConvention = CallingConvention.Cdecl; public static readonly CvErrorCallback CvErrorHandlerThrowException; public static readonly CvErrorCallback CvErrorHandlerIgnoreError; public const string ExternLibrary = "cvextern"; public const string ExternCudaLibrary = "cvextern"; public const string OpencvFFMpegLibrary = "opencv_videoio_ffmpeg460_64"; public static List OpenCVModuleList; public static MCvScalar MorphologyDefaultBorderValue; public static Backend[] Backends { get { using VectorOfInt vectorOfInt = new VectorOfInt(); cveGetBackends(vectorOfInt); int[] array = vectorOfInt.ToArray(); Backend[] array2 = new Backend[array.Length]; for (int i = 0; i < array.Length; i++) { array2[i] = new Backend(array[i]); } return array2; } } public static Backend[] CameraBackends { get { using VectorOfInt vectorOfInt = new VectorOfInt(); cveGetCameraBackends(vectorOfInt); int[] array = vectorOfInt.ToArray(); Backend[] array2 = new Backend[array.Length]; for (int i = 0; i < array.Length; i++) { array2[i] = new Backend(array[i]); } return array2; } } public static Backend[] StreamBackends { get { using VectorOfInt vectorOfInt = new VectorOfInt(); cveGetStreamBackends(vectorOfInt); int[] array = vectorOfInt.ToArray(); Backend[] array2 = new Backend[array.Length]; for (int i = 0; i < array.Length; i++) { array2[i] = new Backend(array[i]); } return array2; } } public static Backend[] WriterBackends { get { using VectorOfInt vectorOfInt = new VectorOfInt(); cveGetWriterBackends(vectorOfInt); int[] array = vectorOfInt.ToArray(); Backend[] array2 = new Backend[array.Length]; for (int i = 0; i < array.Length; i++) { array2[i] = new Backend(array[i]); } return array2; } } public static LogLevel LogLevel { get { return cveGetLogLevel(); } set { cveSetLogLevel(value); } } public static bool UseOptimized { get { return cveUseOptimized(); } set { cveSetUseOptimized(value); } } public static bool HaveOpenVX => cveHaveOpenVX(); public static bool UseOpenVX { get { return cveUseOpenVX(); } set { cveSetUseOpenVX(value); } } public static string BuildInformation { get { using CvString cvString = new CvString(); cveGetBuildInformation(cvString); return cvString.ToString(); } } public static int NumThreads { get { return cveGetNumThreads(); } set { cveSetNumThreads(value); } } public static int ThreadNum => cveGetThreadNum(); public static int NumberOfCPUs => cveGetNumberOfCPUs(); public static string[] AvailableParallelBackends { get { using VectorOfCvString vectorOfCvString = new VectorOfCvString(); cveGetParallelBackends(vectorOfCvString); return vectorOfCvString.ToArray(); } } public static bool HaveOpenCL => cveHaveOpenCL(); public static bool UseOpenCL { get { return cveUseOpenCL(); } set { cveSetUseOpenCL(value); } } public static bool HaveOpenCLCompatibleGpuDevice { get { if (HaveOpenCL) { using VectorOfOclPlatformInfo vectorOfOclPlatformInfo = OclInvoke.GetPlatformsInfo(); if (vectorOfOclPlatformInfo.Size > 0) { for (int i = 0; i < vectorOfOclPlatformInfo.Size; i++) { PlatformInfo platformInfo = vectorOfOclPlatformInfo[i]; for (int j = 0; j < platformInfo.DeviceNumber; j++) { if (platformInfo.GetDevice(j).Type == DeviceType.Gpu) { return true; } } } } } return false; } } public static Dictionary ConfigDict { get { using VectorOfCvString vectorOfCvString = new VectorOfCvString(); using VectorOfDouble vectorOfDouble = new VectorOfDouble(); cveGetConfigDict(vectorOfCvString, vectorOfDouble); string[] array = vectorOfCvString.ToArray(); double[] array2 = vectorOfDouble.ToArray(); Dictionary dictionary = new Dictionary(); for (int i = 0; i < array.Length; i++) { dictionary[array[i]] = array2[i]; } return dictionary; } } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveAffine3dCreate(); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveAffine3dGetIdentity(); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveAffine3dRotate(IntPtr affine, double r0, double r1, double r2); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveAffine3dTranslate(IntPtr affine, double t0, double t1, double t2); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveAffine3dGetValues(IntPtr affine, IntPtr values); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveAffine3dRelease(ref IntPtr affine); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveStringCreate(); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveStringRelease(ref IntPtr str); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int cveStringGetLength(IntPtr str); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveStringGetCStr(IntPtr str, ref IntPtr cStr, ref int size); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveStringCreateFromStr(IntPtr c); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveDirectxConvertToD3D11Texture2D(IntPtr src, IntPtr pD3D11Texture2D); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveDirectxConvertFromD3D11Texture2D(IntPtr pD3D11Texture2D, IntPtr dst); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveDirectxConvertToD3D10Texture2D(IntPtr src, IntPtr pD3D10Texture2D); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveDirectxConvertFromD3D10Texture2D(IntPtr pD3D10Texture2D, IntPtr dst); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveDirectxConvertToDirect3DSurface9(IntPtr src, IntPtr pDirect3DSurface9, IntPtr surfaceSharedHandle); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveDirectxConvertFromDirect3DSurface9(IntPtr pDirect3DSurface9, IntPtr dst, IntPtr surfaceSharedHandle); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveFileNodeRelease(ref IntPtr node); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveFileNodeReadMat(IntPtr node, IntPtr mat, IntPtr defaultMat); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int cveFileNodeGetType(IntPtr node); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveFileNodeGetName(IntPtr node, IntPtr name); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveFileNodeGetKeys(IntPtr node, IntPtr keys); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveFileNodeReadString(IntPtr node, IntPtr str, IntPtr defaultStr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int cveFileNodeReadInt(IntPtr node, int defaultInt); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern double cveFileNodeReadDouble(IntPtr node, double defaultDouble); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern float cveFileNodeReadFloat(IntPtr node, float defaultFloat); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.U1)] internal static extern bool cveFileNodeIsNamed(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.U1)] internal static extern bool cveFileNodeIsEmpty(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.U1)] internal static extern bool cveFileNodeIsNone(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.U1)] internal static extern bool cveFileNodeIsSeq(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.U1)] internal static extern bool cveFileNodeIsMap(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.U1)] internal static extern bool cveFileNodeIsInt(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.U1)] internal static extern bool cveFileNodeIsReal(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.U1)] internal static extern bool cveFileNodeIsString(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveFileNodeIteratorCreate(); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveFileNodeIteratorRelease(ref IntPtr iterator); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveFileNodeIteratorCreateFromNode(IntPtr node, [MarshalAs(UnmanagedType.U1)] bool seekEnd); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.U1)] internal static extern bool cveFileNodeIteratorEqualTo(IntPtr iterator, IntPtr otherIterator); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveFileNodeIteratorNext(IntPtr iterator); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveFileNodeIteratorGetFileNode(IntPtr iterator); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveFileStorageCreate(IntPtr source, FileStorage.Mode flags, IntPtr encoding); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.U1)] internal static extern bool cveFileStorageIsOpened(IntPtr storage); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveFileStorageReleaseAndGetString(IntPtr storage, IntPtr result); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveFileStorageRelease(ref IntPtr storage); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveFileStorageWriteMat(IntPtr fs, IntPtr name, IntPtr value); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveFileStorageWriteInt(IntPtr fs, IntPtr name, int value); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveFileStorageWriteFloat(IntPtr fs, IntPtr name, float value); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveFileStorageWriteDouble(IntPtr fs, IntPtr name, double value); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveFileStorageWriteString(IntPtr fs, IntPtr name, IntPtr value); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveFileStorageRoot(IntPtr fs, int streamIdx); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveFileStorageGetFirstTopLevelNode(IntPtr fs); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveFileStorageGetNode(IntPtr fs, IntPtr nodeName); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveFileStorageInsertString(IntPtr fs, IntPtr value); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveAlgorithmRead(IntPtr algorithm, IntPtr node); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveAlgorithmWrite(IntPtr algorithm, IntPtr storage); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveAlgorithmWrite2(IntPtr algorithm, IntPtr storage, IntPtr name); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveAlgorithmSave(IntPtr algorithm, IntPtr filename); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveAlgorithmClear(IntPtr algorithm); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.U1)] internal static extern bool cveAlgorithmEmpty(IntPtr algorithm); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveAlgorithmGetDefaultName(IntPtr algorithm, IntPtr defaultName); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveInputArrayRelease(ref IntPtr arr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int cveInputArrayGetDims(IntPtr ia, int idx); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveInputArrayGetSize(IntPtr ia, ref Size size, int idx); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern DepthType cveInputArrayGetDepth(IntPtr ia, int idx); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int cveInputArrayGetChannels(IntPtr ia, int idx); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.U1)] internal static extern bool cveInputArrayIsEmpty(IntPtr ia); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveInputArrayGetMat(IntPtr ia, int idx, IntPtr mat); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveInputArrayGetUMat(IntPtr ia, int idx, IntPtr umat); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveInputArrayCopyTo(IntPtr ia, IntPtr arr, IntPtr mask); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.U1)] internal static extern bool cveInputArrayIsMat(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.U1)] internal static extern bool cveInputArrayIsUMat(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.U1)] internal static extern bool cveInputArrayIsMatVector(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.U1)] internal static extern bool cveInputArrayIsUMatVector(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.U1)] internal static extern bool cveInputArrayIsMatx(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern InputArray.Type cveInputArrayKind(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveInputOutputArrayRelease(ref IntPtr arr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.U1)] internal static extern bool cveMatIsContinuous(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.U1)] internal static extern bool cveMatIsSubmatrix(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern DepthType cveMatDepth(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.U1)] internal static extern bool cveMatIsEmpty(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int cveMatNumberOfChannels(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveMatPopBack(IntPtr obj, int val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveMatPushBack(IntPtr obj, IntPtr val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveMatTotal(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int cveMatGetDims(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveMomentsCreate(); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveMomentsRelease(ref IntPtr moments); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern double cveMomentsGetM00(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveMomentsSetM00(IntPtr obj, double val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern double cveMomentsGetM10(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveMomentsSetM10(IntPtr obj, double val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern double cveMomentsGetM01(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveMomentsSetM01(IntPtr obj, double val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern double cveMomentsGetM20(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveMomentsSetM20(IntPtr obj, double val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern double cveMomentsGetM11(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveMomentsSetM11(IntPtr obj, double val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern double cveMomentsGetM02(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveMomentsSetM02(IntPtr obj, double val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern double cveMomentsGetM30(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveMomentsSetM30(IntPtr obj, double val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern double cveMomentsGetM21(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveMomentsSetM21(IntPtr obj, double val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern double cveMomentsGetM12(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveMomentsSetM12(IntPtr obj, double val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern double cveMomentsGetM03(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveMomentsSetM03(IntPtr obj, double val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern double cveMomentsGetMu20(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveMomentsSetMu20(IntPtr obj, double val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern double cveMomentsGetMu11(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveMomentsSetMu11(IntPtr obj, double val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern double cveMomentsGetMu02(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveMomentsSetMu02(IntPtr obj, double val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern double cveMomentsGetMu30(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveMomentsSetMu30(IntPtr obj, double val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern double cveMomentsGetMu21(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveMomentsSetMu21(IntPtr obj, double val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern double cveMomentsGetMu12(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveMomentsSetMu12(IntPtr obj, double val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern double cveMomentsGetMu03(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveMomentsSetMu03(IntPtr obj, double val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern double cveMomentsGetNu20(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveMomentsSetNu20(IntPtr obj, double val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern double cveMomentsGetNu11(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveMomentsSetNu11(IntPtr obj, double val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern double cveMomentsGetNu02(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveMomentsSetNu02(IntPtr obj, double val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern double cveMomentsGetNu30(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveMomentsSetNu30(IntPtr obj, double val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern double cveMomentsGetNu21(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveMomentsSetNu21(IntPtr obj, double val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern double cveMomentsGetNu12(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveMomentsSetNu12(IntPtr obj, double val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern double cveMomentsGetNu03(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveMomentsSetNu03(IntPtr obj, double val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveOutputArrayRelease(ref IntPtr arr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.U1)] internal static extern bool cveOutputArrayFixedSize(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.U1)] internal static extern bool cveOutputArrayFixedType(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.U1)] internal static extern bool cveOutputArrayNeeded(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveRngCreate(); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveRngCreateWithSeed(ulong state); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveRngFill(IntPtr rng, IntPtr mat, RNG.DistType distType, IntPtr a, IntPtr b, bool saturateRange); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern double cveRngGaussian(IntPtr rng, double sigma); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern uint cveRngNext(IntPtr rng); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int cveRngUniformInt(IntPtr rng, int a, int b); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern float cveRngUniformFloat(IntPtr rng, float a, float b); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern double cveRngUniformDouble(IntPtr rng, double a, double b); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveRngRelease(ref IntPtr rng); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.U1)] internal static extern bool cveUMatIsContinuous(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.U1)] internal static extern bool cveUMatIsSubmatrix(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern DepthType cveUMatDepth(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.U1)] internal static extern bool cveUMatIsEmpty(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int cveUMatNumberOfChannels(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveUMatTotal(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int cveUMatGetDims(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveVideoCaptureCreateFromDevice(int index, VideoCapture.API apiPreference, IntPtr captureProperties); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveVideoCaptureCreateFromFile(IntPtr filename, VideoCapture.API api, IntPtr captureProperties); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveVideoCaptureRelease(ref IntPtr capture); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.Bool)] internal static extern bool cveVideoCaptureRead(IntPtr capture, IntPtr frame); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveVideoCaptureReadToMat(IntPtr capture, IntPtr mat); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveVideoCaptureReadToUMat(IntPtr capture, IntPtr umat); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.Bool)] internal static extern bool cveVideoCaptureGrab(IntPtr capture); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.Bool)] internal static extern bool cveVideoCaptureRetrieve(IntPtr capture, IntPtr image, int flag); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern double cveVideoCaptureGet(IntPtr capture, CapProp prop); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.Bool)] internal static extern bool cveVideoCaptureSet(IntPtr capture, CapProp propertyId, double value); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveVideoCaptureGetBackendName(IntPtr capture, IntPtr backendName); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveGetBackendName(int api, IntPtr name); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.Bool)] internal static extern bool cveVideoCaptureWaitAny(IntPtr streams, IntPtr readyIndex, int timeoutNs); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveGetBackends(IntPtr backends); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveGetCameraBackends(IntPtr backends); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveGetStreamBackends(IntPtr backends); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveGetWriterBackends(IntPtr backends); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.U1)] internal static extern bool cveVideoCaptureIsOpened(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.U1)] internal static extern bool cveVideoCaptureGetExceptionMode(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveVideoCaptureSetExceptionMode(IntPtr obj, [MarshalAs(UnmanagedType.U1)] bool val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveVideoWriterCreate(IntPtr filename, int fourcc, double fps, ref Size frameSize, [MarshalAs(UnmanagedType.U1)] bool isColor); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveVideoWriterCreate2(IntPtr filename, int apiPreference, int fourcc, double fps, ref Size frameSize, [MarshalAs(UnmanagedType.U1)] bool isColor); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveVideoWriterCreate3(IntPtr filename, int apiPreference, int fourcc, double fps, ref Size frameSize, IntPtr parameters); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveVideoWriterRelease(ref IntPtr writer); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveVideoWriterWrite(IntPtr writer, IntPtr image); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int cveVideoWriterFourcc(char c1, char c2, char c3, char c4); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.U1)] internal static extern bool cveVideoWriterIsOpened(IntPtr writer); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.U1)] internal static extern bool cveVideoWriterSet(IntPtr writer, VideoWriter.WriterProperty propId, double value); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern double cveVideoWriterGet(IntPtr writer, VideoWriter.WriterProperty propId); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveVideoWriterGetBackendName(IntPtr writer, IntPtr backendName); public static bool Init() { return _libraryLoaded; } private static string FindValidSubfolders(string baseFolder, List subfolderOptions) { foreach (string subfolderOption in subfolderOptions) { if (Directory.Exists(Path.Combine(baseFolder, subfolderOption))) { return subfolderOption; } } return string.Empty; } public static bool LoadUnmanagedModules(string loadDirectory, params string[] unmanagedModules) { string text = string.Empty; if (loadDirectory == null) { List list = new List(); if (Platform.OperationSystem == Platform.OS.MacOS) { list.Add(Path.Combine("runtimes", "osx", "native")); } else if (Platform.OperationSystem == Platform.OS.Linux) { switch (RuntimeInformation.ProcessArchitecture) { case Architecture.X86: list.Add(Path.Combine("runtimes", "linux-x86", "native")); list.Add(Path.Combine("runtimes", "ubuntu-x86", "native")); list.Add("x86"); break; case Architecture.X64: list.Add(Path.Combine("runtimes", "linux-x64", "native")); list.Add(Path.Combine("runtimes", "ubuntu-x64", "native")); list.Add("x64"); break; case Architecture.Arm: list.Add(Path.Combine("runtimes", "linux-arm", "native")); list.Add(Path.Combine("runtimes", "ubuntu-arm", "native")); list.Add("arm"); break; case Architecture.Arm64: list.Add(Path.Combine("runtimes", "linux-arm64", "native")); list.Add(Path.Combine("runtimes", "ubuntu-arm64", "native")); list.Add("arm64"); break; } } else if (Platform.OperationSystem == Platform.OS.Windows) { string dllDirectory = Toolbox.GetDllDirectory(); if (dllDirectory != null) { list.Add(dllDirectory); } switch (RuntimeInformation.ProcessArchitecture) { case Architecture.X86: list.Add(Path.Combine("runtimes", "win-x86", "native")); list.Add("x86"); break; case Architecture.X64: list.Add(Path.Combine("runtimes", "win-x64", "native")); list.Add("x64"); break; case Architecture.Arm: list.Add(Path.Combine("runtimes", "win-arm", "native")); list.Add("arm"); break; case Architecture.Arm64: list.Add(Path.Combine("runtimes", "win-arm64", "native")); list.Add("arm64"); break; } } string text2 = string.Empty; Assembly assembly = typeof(CvInvoke).Assembly; if (string.IsNullOrEmpty(assembly.Location) || !File.Exists(assembly.Location)) { if (string.IsNullOrEmpty(AppDomain.CurrentDomain.BaseDirectory)) { loadDirectory = string.Empty; } else { DirectoryInfo directoryInfo = new DirectoryInfo(AppDomain.CurrentDomain.BaseDirectory); string text3 = string.Empty; if (directoryInfo.Parent != null) { text3 = Path.Combine(directoryInfo.Parent.FullName, "Packages", "Debugger", "Visualizers"); } loadDirectory = ((text3.Equals(string.Empty) || !Directory.Exists(text3)) ? directoryInfo.FullName : text3); text2 = FindValidSubfolders(loadDirectory, list); } } else { loadDirectory = Path.GetDirectoryName(assembly.Location); if (loadDirectory != null) { text2 = FindValidSubfolders(loadDirectory, list); } } if (!string.IsNullOrEmpty(text2)) { loadDirectory = ((!Directory.Exists(Path.Combine(loadDirectory, text2))) ? Path.Combine(Path.GetFullPath("."), text2) : Path.Combine(loadDirectory, text2)); } if (!Directory.Exists(loadDirectory)) { if (string.IsNullOrEmpty(assembly.Location) || !File.Exists(assembly.Location)) { System.Diagnostics.Trace.WriteLine($"asm.Location is invalid: '{assembly.Location}'"); } else { DirectoryInfo directory = new FileInfo(assembly.Location).Directory; if (directory != null && !string.IsNullOrEmpty(text2) && Directory.Exists(Path.Combine(directory.FullName, text2))) { loadDirectory = Path.Combine(directory.FullName, text2); } else if (directory != null && Directory.Exists(directory.FullName)) { loadDirectory = directory.FullName; } } } } bool flag = false; if (!string.IsNullOrEmpty(loadDirectory) && Directory.Exists(loadDirectory) && Platform.ClrType != Platform.Clr.DotNetNative) { if (Platform.OperationSystem == Platform.OS.Windows) { flag = Toolbox.SetDllDirectory(loadDirectory); if (!flag) { System.Diagnostics.Trace.WriteLine($"Failed to set dll directory: {loadDirectory}"); } } else if (Platform.OperationSystem == Platform.OS.IOS) { System.Diagnostics.Trace.WriteLine("iOS required static linking, Setting loadDirectory is not supported"); } else { text = Environment.CurrentDirectory; Environment.CurrentDirectory = loadDirectory; } } if (flag) { System.Diagnostics.Trace.WriteLine($"Loading Open CV binary from default locations. Current directory: {Environment.CurrentDirectory}; Additional load folder: {loadDirectory}"); } else { System.Diagnostics.Trace.WriteLine($"Loading Open CV binary from default locations. Current directory: {Environment.CurrentDirectory}"); } bool flag2 = true; string empty = string.Empty; foreach (string text4 in unmanagedModules) { string text5 = text4; if (text5.StartsWith("opencv_videoio_ffmpeg") && IntPtr.Size == 4) { text5 = text4.Replace("_64", string.Empty); } bool num = text5.Contains("ffmpeg"); string path = Path.Combine(empty, text5); string text6 = Path.Combine(loadDirectory, path); bool num2 = File.Exists(text6); bool flag3 = false; if (num2) { System.Diagnostics.Trace.WriteLine($"Found full path {text6} for {text5}. Trying to load it."); IntPtr zero = IntPtr.Zero; flag3 = !zero.Equals((object?)(nint)Toolbox.LoadLibrary(text6)); if (flag3) { System.Diagnostics.Trace.WriteLine($"{text5} loaded."); } else { System.Diagnostics.Trace.WriteLine($"Failed to load {text5} from {text6}."); } } if (!flag3) { System.Diagnostics.Trace.WriteLine($"Trying to load {text5} using default path."); IntPtr zero = IntPtr.Zero; flag3 = !zero.Equals((object?)(nint)Toolbox.LoadLibrary(text5)); if (flag3) { System.Diagnostics.Trace.WriteLine($"{text5} loaded using default path"); } else { System.Diagnostics.Trace.WriteLine($"Failed to load {text5} using default path"); } } if (!flag3) { System.Diagnostics.Trace.WriteLine($"!!! Failed to load {text5}."); } if (!num) { flag2 = flag2 && flag3; } } if (!text.Equals(string.Empty)) { Environment.CurrentDirectory = text; } return flag2; } public static string GetModuleFormatString() { string result = "{0}"; if (Platform.OperationSystem == Platform.OS.Windows) { result = "{0}.dll"; } else if (Platform.OperationSystem == Platform.OS.Linux) { result = "lib{0}.so"; } else if (Platform.OperationSystem == Platform.OS.MacOS) { result = "lib{0}.dylib"; } return result; } public static bool DefaultLoadUnmanagedModules(string[] modules, string loadDirectory = null) { bool flag = true; if (Platform.OperationSystem == Platform.OS.IOS) { return flag; } if (Platform.OperationSystem == Platform.OS.Android && Platform.ClrType != Platform.Clr.Unity) { Type type = Toolbox.FindAssembly("Mono.Android.dll").GetType("Java.Lang.JavaSystem"); if (type != null) { MethodInfo method = type.GetMethod("LoadLibrary"); if (method != null) { foreach (string text in modules) { if (text.StartsWith("opencv_videoio_ffmpeg")) { continue; } try { string text2 = ((loadDirectory == null) ? text : Path.Combine(loadDirectory, text)); System.Diagnostics.Trace.WriteLine($"Trying to load {text2} ({IntPtr.Size * 8} bit)."); method.Invoke(null, new object[1] { text2 }); System.Diagnostics.Trace.WriteLine($"Loaded {text2}."); } catch (Exception ex) { flag = false; System.Diagnostics.Trace.WriteLine($"Failed to load {text}: {ex.Message}"); if (ex.InnerException != null && ex.InnerException.Message != null) { System.Diagnostics.Trace.WriteLine($"InnerException {ex.InnerException.Message}"); } } } return flag; } } } else { string moduleFormatString = GetModuleFormatString(); for (int j = 0; j < modules.Length; j++) { modules[j] = string.Format(moduleFormatString, modules[j]); } flag &= LoadUnmanagedModules(loadDirectory, modules); } return flag; } static CvInvoke() { CvErrorHandlerThrowException = CvErrorHandler; CvErrorHandlerIgnoreError = CvIgnoreErrorErrorHandler; OpenCVModuleList = new List { "opencv_videoio_ffmpeg460_64", "cvextern" }; MorphologyDefaultBorderValue = new MCvScalar(double.MaxValue, double.MaxValue, double.MaxValue, double.MaxValue); if (Platform.OperationSystem == Platform.OS.IOS) { _libraryLoaded = true; return; } List openCVModuleList = OpenCVModuleList; openCVModuleList.RemoveAll(string.IsNullOrEmpty); _libraryLoaded = DefaultLoadUnmanagedModules(openCVModuleList.ToArray()); try { RedirectError(CvErrorHandlerThrowException, IntPtr.Zero, IntPtr.Zero); } catch (Exception ex) { System.Diagnostics.Trace.WriteLine($"Failed to register error handler using RedirectError : {ex.StackTrace}"); throw; } } public static Type GetDepthType(DepthType t) { return t switch { DepthType.Cv8U => typeof(byte), DepthType.Cv8S => typeof(sbyte), DepthType.Cv16U => typeof(ushort), DepthType.Cv16S => typeof(short), DepthType.Cv32S => typeof(int), DepthType.Cv32F => typeof(float), DepthType.Cv64F => typeof(double), _ => throw new ArgumentException($"Unable to convert type {t.ToString()} to depth type"), }; } public static DepthType GetDepthType(Type t) { if (t == typeof(byte)) { return DepthType.Cv8U; } if (t == typeof(sbyte)) { return DepthType.Cv8S; } if (t == typeof(ushort)) { return DepthType.Cv16U; } if (t == typeof(short)) { return DepthType.Cv16S; } if (t == typeof(int)) { return DepthType.Cv32S; } if (t == typeof(float)) { return DepthType.Cv32F; } if (t == typeof(double)) { return DepthType.Cv64F; } throw new ArgumentException($"Unable to convert type {t.ToString()} to depth type"); } public static int MakeType(DepthType depth, int channels) { return (int)((depth & (DepthType)7) + (channels - 1 << 3)); } public static bool SanityCheck() { CvStructSizes cvStructSizes = GetCvStructSizes(); int num = 1 & ((cvStructSizes.CvBox2D == Toolbox.SizeOf()) ? 1 : 0) & ((cvStructSizes.CvMat == Toolbox.SizeOf()) ? 1 : 0) & ((cvStructSizes.CvMatND == Toolbox.SizeOf()) ? 1 : 0) & ((cvStructSizes.CvPoint == Toolbox.SizeOf()) ? 1 : 0) & ((cvStructSizes.CvPoint2D32f == Toolbox.SizeOf()) ? 1 : 0) & ((cvStructSizes.CvPoint3D32f == Toolbox.SizeOf()) ? 1 : 0) & ((cvStructSizes.CvRect == Toolbox.SizeOf()) ? 1 : 0) & ((cvStructSizes.CvScalar == Toolbox.SizeOf()) ? 1 : 0) & ((cvStructSizes.CvSize == Toolbox.SizeOf()) ? 1 : 0) & ((cvStructSizes.CvSize2D32f == Toolbox.SizeOf()) ? 1 : 0) & ((cvStructSizes.CvTermCriteria == Toolbox.SizeOf()) ? 1 : 0) & ((2 * Toolbox.SizeOf() == Toolbox.SizeOf()) ? 1 : 0); int num2 = Toolbox.SizeOf(); return (byte)((uint)num & ((cvStructSizes.IplImage == num2) ? 1u : 0u)) != 0; } public static Mat FindHomography(PointF[] srcPoints, PointF[] dstPoints, RobustEstimationAlgorithm method = RobustEstimationAlgorithm.AllPoints, double ransacReprojThreshold = 3.0, IOutputArray mask = null) { GCHandle gCHandle = GCHandle.Alloc(srcPoints, GCHandleType.Pinned); GCHandle gCHandle2 = GCHandle.Alloc(dstPoints, GCHandleType.Pinned); try { using Mat srcPoints2 = new Mat(srcPoints.Length, 2, DepthType.Cv32F, 1, gCHandle.AddrOfPinnedObject(), 8); using Mat dstPoints2 = new Mat(dstPoints.Length, 2, DepthType.Cv32F, 1, gCHandle2.AddrOfPinnedObject(), 8); return FindHomography(srcPoints2, dstPoints2, method, ransacReprojThreshold, mask); } finally { gCHandle.Free(); gCHandle2.Free(); } } public static Mat FindHomography(IInputArray srcPoints, IInputArray dstPoints, RobustEstimationAlgorithm method = RobustEstimationAlgorithm.AllPoints, double ransacReprojThreshold = 3.0, IOutputArray mask = null) { Mat mat = new Mat(); using InputArray inputArray = srcPoints.GetInputArray(); using InputArray inputArray2 = dstPoints.GetInputArray(); using OutputArray outputArray = mat.GetOutputArray(); using OutputArray outputArray2 = ((mask == null) ? OutputArray.GetEmpty() : mask.GetOutputArray()); cveFindHomography(inputArray, inputArray2, outputArray, method, ransacReprojThreshold, outputArray2); return mat; } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveFindHomography(IntPtr srcPoints, IntPtr dstPoints, IntPtr homography, RobustEstimationAlgorithm method, double ransacReprojThreshold, IntPtr mask); public static void Rodrigues(IInputArray src, IOutputArray dst, IOutputArray jacobian = null) { using InputArray inputArray = src.GetInputArray(); using OutputArray outputArray = dst.GetOutputArray(); using OutputArray outputArray2 = ((jacobian == null) ? OutputArray.GetEmpty() : jacobian.GetOutputArray()); cveRodrigues(inputArray, outputArray, outputArray2); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveRodrigues(IntPtr src, IntPtr dst, IntPtr jacobian); public static Mat FindEssentialMat(IInputArray points1, IInputArray points2, IInputArray cameraMatrix, FmType method = FmType.Ransac, double prob = 0.999, double threshold = 1.0, IOutputArray mask = null) { using InputArray inputArray = points1.GetInputArray(); using InputArray inputArray2 = points2.GetInputArray(); using InputArray inputArray3 = cameraMatrix.GetInputArray(); using OutputArray outputArray = ((mask == null) ? OutputArray.GetEmpty() : mask.GetOutputArray()); Mat mat = new Mat(); cveFindEssentialMat(inputArray, inputArray2, inputArray3, method, prob, threshold, outputArray, mat); return mat; } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveFindEssentialMat(IntPtr points1, IntPtr points2, IntPtr cameraMatrix, FmType method, double prob, double threshold, IntPtr mask, IntPtr essentialMat); public static Mat FindFundamentalMat(IInputArray points1, IInputArray points2, FmType method = FmType.Ransac, double param1 = 3.0, double param2 = 0.99, IOutputArray mask = null) { Mat mat = new Mat(); using InputArray inputArray = points1.GetInputArray(); using InputArray inputArray2 = points2.GetInputArray(); using OutputArray outputArray = mat.GetOutputArray(); using OutputArray outputArray2 = ((mask == null) ? OutputArray.GetEmpty() : mask.GetOutputArray()); cveFindFundamentalMat(inputArray, inputArray2, outputArray, method, param1, param2, outputArray2); return mat; } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveFindFundamentalMat(IntPtr points1, IntPtr points2, IntPtr dst, FmType method, double param1, double param2, IntPtr mask); public static void ComputeCorrespondEpilines(IInputArray points, int whichImage, IInputArray fundamentalMatrix, IOutputArray correspondentLines) { using InputArray inputArray = points.GetInputArray(); using InputArray inputArray2 = fundamentalMatrix.GetInputArray(); using OutputArray outputArray = correspondentLines.GetOutputArray(); cveComputeCorrespondEpilines(inputArray, whichImage, inputArray2, outputArray); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveComputeCorrespondEpilines(IntPtr points, int whichImage, IntPtr fundamentalMatrix, IntPtr correspondentLines); public static void ConvertPointsToHomogeneous(IInputArray src, IOutputArray dst) { using InputArray inputArray = src.GetInputArray(); using OutputArray outputArray = dst.GetOutputArray(); cveConvertPointsToHomogeneous(inputArray, outputArray); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveConvertPointsToHomogeneous(IntPtr src, IntPtr dst); public static void ConvertPointsFromHomogeneous(IInputArray src, IOutputArray dst) { using InputArray inputArray = src.GetInputArray(); using OutputArray outputArray = dst.GetOutputArray(); cveConvertPointsFromHomogeneous(inputArray, outputArray); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveConvertPointsFromHomogeneous(IntPtr src, IntPtr dst); public static void ReprojectImageTo3D(IInputArray disparity, IOutputArray image3D, IInputArray q, bool handleMissingValues = false, DepthType ddepth = DepthType.Default) { using InputArray inputArray = disparity.GetInputArray(); using OutputArray outputArray = image3D.GetOutputArray(); using InputArray inputArray2 = q.GetInputArray(); cveReprojectImageTo3D(inputArray, outputArray, inputArray2, handleMissingValues, ddepth); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveReprojectImageTo3D(IntPtr disparity, IntPtr image3D, IntPtr q, [MarshalAs(UnmanagedType.U1)] bool handleMissingValues, DepthType ddepth); public static Mat GetOptimalNewCameraMatrix(IInputArray cameraMatrix, IInputArray distCoeffs, Size imageSize, double alpha, Size newImgSize, ref Rectangle validPixROI, bool centerPrincipalPoint = false) { Mat mat = new Mat(); using InputArray inputArray = cameraMatrix.GetInputArray(); using InputArray inputArray2 = ((distCoeffs == null) ? InputArray.GetEmpty() : distCoeffs.GetInputArray()); cveGetOptimalNewCameraMatrix(inputArray, inputArray2, ref imageSize, alpha, ref newImgSize, ref validPixROI, centerPrincipalPoint, mat); return mat; } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveGetOptimalNewCameraMatrix(IntPtr cameraMatrix, IntPtr distCoeffs, ref Size imageSize, double alpha, ref Size newImgSize, ref Rectangle validPixROI, [MarshalAs(UnmanagedType.U1)] bool centerPrincipalPoint, IntPtr newCameraMatrix); public static Mat InitCameraMatrix2D(IInputArrayOfArrays objectPoints, IInputArrayOfArrays imagePoints, Size imageSize, double aspectRatio = 1.0) { Mat mat = new Mat(); using InputArray inputArray = objectPoints.GetInputArray(); using InputArray inputArray2 = imagePoints.GetInputArray(); cveInitCameraMatrix2D(inputArray, inputArray2, ref imageSize, aspectRatio, mat); return mat; } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveInitCameraMatrix2D(IntPtr objectPoints, IntPtr imagePoints, ref Size imageSize, double aspectRatio, IntPtr cameraMatrix); public static PointF[] ProjectPoints(MCvPoint3D32f[] objectPoints, IInputArray rvec, IInputArray tvec, IInputArray cameraMatrix, IInputArray distCoeffs, IOutputArray jacobian = null, double aspectRatio = 0.0) { PointF[] array = new PointF[objectPoints.Length]; GCHandle gCHandle = GCHandle.Alloc(objectPoints, GCHandleType.Pinned); GCHandle gCHandle2 = GCHandle.Alloc(array, GCHandleType.Pinned); using (Mat objectPoints2 = new Mat(objectPoints.Length, 1, DepthType.Cv32F, 3, gCHandle.AddrOfPinnedObject(), 12)) { using Mat imagePoints = new Mat(array.Length, 1, DepthType.Cv32F, 2, gCHandle2.AddrOfPinnedObject(), 8); ProjectPoints(objectPoints2, rvec, tvec, cameraMatrix, distCoeffs, imagePoints, jacobian, aspectRatio); } gCHandle.Free(); gCHandle2.Free(); return array; } public static void ProjectPoints(IInputArray objectPoints, IInputArray rvec, IInputArray tvec, IInputArray cameraMatrix, IInputArray distCoeffs, IOutputArray imagePoints, IOutputArray jacobian = null, double aspectRatio = 0.0) { using InputArray inputArray = objectPoints.GetInputArray(); using InputArray inputArray2 = rvec.GetInputArray(); using InputArray inputArray3 = tvec.GetInputArray(); using InputArray inputArray4 = cameraMatrix.GetInputArray(); using InputArray inputArray5 = ((distCoeffs == null) ? InputArray.GetEmpty() : distCoeffs.GetInputArray()); using OutputArray outputArray = imagePoints.GetOutputArray(); using OutputArray outputArray2 = ((jacobian == null) ? OutputArray.GetEmpty() : jacobian.GetOutputArray()); cveProjectPoints(inputArray, inputArray2, inputArray3, inputArray4, inputArray5, outputArray, outputArray2, aspectRatio); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveProjectPoints(IntPtr objPoints, IntPtr rvec, IntPtr tvec, IntPtr cameraMatrix, IntPtr distCoeffs, IntPtr imagePoints, IntPtr jacobian, double aspectRatio); public static double CalibrateCamera(MCvPoint3D32f[][] objectPoints, PointF[][] imagePoints, Size imageSize, IInputOutputArray cameraMatrix, IInputOutputArray distortionCoeffs, CalibType calibrationType, MCvTermCriteria termCriteria, out Mat[] rotationVectors, out Mat[] translationVectors) { int num = objectPoints.Length; using VectorOfVectorOfPoint3D32F objectPoints2 = new VectorOfVectorOfPoint3D32F(objectPoints); using VectorOfVectorOfPointF imagePoints2 = new VectorOfVectorOfPointF(imagePoints); double result; using (VectorOfMat vectorOfMat = new VectorOfMat()) { using VectorOfMat vectorOfMat2 = new VectorOfMat(); result = CalibrateCamera(objectPoints2, imagePoints2, imageSize, cameraMatrix, distortionCoeffs, vectorOfMat, vectorOfMat2, calibrationType, termCriteria); rotationVectors = new Mat[num]; translationVectors = new Mat[num]; for (int i = 0; i < num; i++) { rotationVectors[i] = new Mat(); using (Mat mat = vectorOfMat[i]) { mat.CopyTo(rotationVectors[i]); } translationVectors[i] = new Mat(); using Mat mat2 = vectorOfMat2[i]; mat2.CopyTo(translationVectors[i]); } } return result; } public static double CalibrateCamera(IInputArray objectPoints, IInputArray imagePoints, Size imageSize, IInputOutputArray cameraMatrix, IInputOutputArray distortionCoeffs, IOutputArray rotationVectors, IOutputArray translationVectors, CalibType flags, MCvTermCriteria termCriteria) { using InputArray inputArray = objectPoints.GetInputArray(); using InputArray inputArray2 = imagePoints.GetInputArray(); using InputOutputArray inputOutputArray = cameraMatrix.GetInputOutputArray(); using InputOutputArray inputOutputArray2 = distortionCoeffs.GetInputOutputArray(); using OutputArray outputArray = rotationVectors.GetOutputArray(); using OutputArray outputArray2 = translationVectors.GetOutputArray(); return cveCalibrateCamera(inputArray, inputArray2, ref imageSize, inputOutputArray, inputOutputArray2, outputArray, outputArray2, flags, ref termCriteria); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern double cveCalibrateCamera(IntPtr objectPoints, IntPtr imagePoints, ref Size imageSize, IntPtr cameraMatrix, IntPtr distortionCoeffs, IntPtr rotationVectors, IntPtr translationVectors, CalibType flags, ref MCvTermCriteria termCriteria); public static void CalibrationMatrixValues(IInputArray cameraMatrix, Size imageSize, double apertureWidth, double apertureHeight, ref double fovx, ref double fovy, ref double focalLength, ref MCvPoint2D64f principalPoint, ref double aspectRatio) { using InputArray inputArray = cameraMatrix.GetInputArray(); cveCalibrationMatrixValues(inputArray, ref imageSize, apertureWidth, apertureHeight, ref fovx, ref fovy, ref focalLength, ref principalPoint, ref aspectRatio); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveCalibrationMatrixValues(IntPtr cameraMatrix, ref Size imageSize, double apertureWidth, double apertureHeight, ref double fovx, ref double fovy, ref double focalLength, ref MCvPoint2D64f principalPoint, ref double aspectRatio); public static bool SolvePnP(MCvPoint3D32f[] objectPoints, PointF[] imagePoints, IInputArray intrinsicMatrix, IInputArray distortionCoeffs, IOutputArray rotationVector, IOutputArray translationVector, bool useExtrinsicGuess = false, SolvePnpMethod method = SolvePnpMethod.Iterative) { using VectorOfPoint3D32F objectPoints2 = new VectorOfPoint3D32F(objectPoints); using VectorOfPointF imagePoints2 = new VectorOfPointF(imagePoints); return SolvePnP(objectPoints2, imagePoints2, intrinsicMatrix, distortionCoeffs, rotationVector, translationVector, useExtrinsicGuess: false, method); } public static bool SolvePnP(IInputArray objectPoints, IInputArray imagePoints, IInputArray intrinsicMatrix, IInputArray distortionCoeffs, IOutputArray rotationVector, IOutputArray translationVector, bool useExtrinsicGuess = false, SolvePnpMethod flags = SolvePnpMethod.Iterative) { using InputArray inputArray = objectPoints.GetInputArray(); using InputArray inputArray2 = imagePoints.GetInputArray(); using InputArray inputArray3 = intrinsicMatrix.GetInputArray(); using InputArray inputArray4 = distortionCoeffs.GetInputArray(); using OutputArray outputArray = rotationVector.GetOutputArray(); using OutputArray outputArray2 = translationVector.GetOutputArray(); return cveSolvePnP(inputArray, inputArray2, inputArray3, inputArray4, outputArray, outputArray2, useExtrinsicGuess, flags); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.U1)] private static extern bool cveSolvePnP(IntPtr objectPoints, IntPtr imagePoints, IntPtr cameraMatrix, IntPtr distCoeffs, IntPtr rvec, IntPtr tvec, [MarshalAs(UnmanagedType.U1)] bool useExtrinsicGuess, SolvePnpMethod flags); public static bool SolvePnPRansac(IInputArray objectPoints, IInputArray imagePoints, IInputArray cameraMatrix, IInputArray distCoeffs, IOutputArray rvec, IOutputArray tvec, bool useExtrinsicGuess = false, int iterationsCount = 100, float reprojectionError = 8f, double confident = 0.99, IOutputArray inliers = null, SolvePnpMethod flags = SolvePnpMethod.Iterative) { using InputArray inputArray = objectPoints.GetInputArray(); using InputArray inputArray2 = imagePoints.GetInputArray(); using InputArray inputArray3 = cameraMatrix.GetInputArray(); using InputArray inputArray4 = ((distCoeffs == null) ? InputArray.GetEmpty() : distCoeffs.GetInputArray()); using OutputArray outputArray = rvec.GetOutputArray(); using OutputArray outputArray2 = tvec.GetOutputArray(); using OutputArray outputArray3 = ((inliers == null) ? OutputArray.GetEmpty() : inliers.GetOutputArray()); return cveSolvePnPRansac(inputArray, inputArray2, inputArray3, inputArray4, outputArray, outputArray2, useExtrinsicGuess, iterationsCount, reprojectionError, confident, outputArray3, flags); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.U1)] private static extern bool cveSolvePnPRansac(IntPtr objectPoints, IntPtr imagePoints, IntPtr cameraMatrix, IntPtr distCoeffs, IntPtr rvec, IntPtr tvec, [MarshalAs(UnmanagedType.U1)] bool useExtrinsicGuess, int iterationsCount, float reprojectionError, double confident, IntPtr inliers, SolvePnpMethod flags); public static int SolveP3P(IInputArray objectPoints, IInputArray imagePoints, IInputArray cameraMatrix, IInputArray distCoeffs, IOutputArrayOfArrays rvecs, IOutputArrayOfArrays tvecs, SolvePnpMethod flags) { using InputArray inputArray = objectPoints.GetInputArray(); using InputArray inputArray2 = imagePoints.GetInputArray(); using InputArray inputArray3 = cameraMatrix.GetInputArray(); using InputArray inputArray4 = ((distCoeffs == null) ? InputArray.GetEmpty() : distCoeffs.GetInputArray()); using OutputArray outputArray = rvecs.GetOutputArray(); using OutputArray outputArray2 = tvecs.GetOutputArray(); return cveSolveP3P(inputArray, inputArray2, inputArray3, inputArray4, outputArray, outputArray2, flags); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern int cveSolveP3P(IntPtr objectPoints, IntPtr imagePoints, IntPtr cameraMatrix, IntPtr distCoeffs, IntPtr rvec, IntPtr tvec, SolvePnpMethod flags); public static void SolvePnPRefineLM(IInputArray objectPoints, IInputArray imagePoints, IInputArray cameraMatrix, IInputArray distCoeffs, IInputOutputArray rvec, IInputOutputArray tvec, MCvTermCriteria criteria) { using InputArray inputArray = objectPoints.GetInputArray(); using InputArray inputArray2 = imagePoints.GetInputArray(); using InputArray inputArray3 = cameraMatrix.GetInputArray(); using InputArray inputArray4 = ((distCoeffs == null) ? InputArray.GetEmpty() : distCoeffs.GetInputArray()); using InputOutputArray inputOutputArray = rvec.GetInputOutputArray(); using InputOutputArray inputOutputArray2 = tvec.GetInputOutputArray(); cveSolvePnPRefineLM(inputArray, inputArray2, inputArray3, inputArray4, inputOutputArray, inputOutputArray2, ref criteria); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveSolvePnPRefineLM(IntPtr objectPoints, IntPtr imagePoints, IntPtr cameraMatrix, IntPtr distCoeffs, IntPtr rvec, IntPtr tvec, ref MCvTermCriteria criteria); public static void SolvePnPRefineVVS(IInputArray objectPoints, IInputArray imagePoints, IInputArray cameraMatrix, IInputArray distCoeffs, IInputOutputArray rvec, IInputOutputArray tvec, MCvTermCriteria criteria, double VVSlambda) { using InputArray inputArray = objectPoints.GetInputArray(); using InputArray inputArray2 = imagePoints.GetInputArray(); using InputArray inputArray3 = cameraMatrix.GetInputArray(); using InputArray inputArray4 = ((distCoeffs == null) ? InputArray.GetEmpty() : distCoeffs.GetInputArray()); using InputOutputArray inputOutputArray = rvec.GetInputOutputArray(); using InputOutputArray inputOutputArray2 = tvec.GetInputOutputArray(); cveSolvePnPRefineVVS(inputArray, inputArray2, inputArray3, inputArray4, inputOutputArray, inputOutputArray2, ref criteria, VVSlambda); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveSolvePnPRefineVVS(IntPtr objectPoints, IntPtr imagePoints, IntPtr cameraMatrix, IntPtr distCoeffs, IntPtr rvec, IntPtr tvec, ref MCvTermCriteria criteria, double VVSlambda); public static int SolvePnPGeneric(IInputArray objectPoints, IInputArray imagePoints, IInputArray cameraMatrix, IInputArray distCoeffs, IOutputArrayOfArrays rvecs, IOutputArrayOfArrays tvecs, bool useExtrinsicGuess = false, SolvePnpMethod flags = SolvePnpMethod.Iterative, IInputArray rvec = null, IInputArray tvec = null, IOutputArray reprojectionError = null) { using InputArray inputArray = objectPoints.GetInputArray(); using InputArray inputArray2 = imagePoints.GetInputArray(); using InputArray inputArray3 = cameraMatrix.GetInputArray(); using InputArray inputArray4 = distCoeffs.GetInputArray(); using OutputArray outputArray = rvecs.GetOutputArray(); using OutputArray outputArray2 = tvecs.GetOutputArray(); using InputArray inputArray5 = ((rvec == null) ? InputArray.GetEmpty() : rvec.GetInputArray()); using InputArray inputArray6 = ((tvec == null) ? InputArray.GetEmpty() : tvec.GetInputArray()); using OutputArray outputArray3 = ((reprojectionError == null) ? OutputArray.GetEmpty() : reprojectionError.GetOutputArray()); return cveSolvePnPGeneric(inputArray, inputArray2, inputArray3, inputArray4, outputArray, outputArray2, useExtrinsicGuess, flags, inputArray5, inputArray6, outputArray3); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern int cveSolvePnPGeneric(IntPtr objectPoints, IntPtr imagePoints, IntPtr cameraMatrix, IntPtr distCoeffs, IntPtr rvecs, IntPtr tvecs, [MarshalAs(UnmanagedType.U1)] bool useExtrinsicGuess, SolvePnpMethod flags, IntPtr rvec, IntPtr tvec, IntPtr reprojectionError); public static double StereoCalibrate(MCvPoint3D32f[][] objectPoints, PointF[][] imagePoints1, PointF[][] imagePoints2, IInputOutputArray cameraMatrix1, IInputOutputArray distCoeffs1, IInputOutputArray cameraMatrix2, IInputOutputArray distCoeffs2, Size imageSize, IOutputArray r, IOutputArray t, IOutputArray e, IOutputArray f, CalibType flags, MCvTermCriteria termCrit) { using VectorOfVectorOfPoint3D32F objectPoints2 = new VectorOfVectorOfPoint3D32F(objectPoints); using VectorOfVectorOfPointF imagePoints3 = new VectorOfVectorOfPointF(imagePoints1); using VectorOfVectorOfPointF imagePoints4 = new VectorOfVectorOfPointF(imagePoints2); return StereoCalibrate(objectPoints2, imagePoints3, imagePoints4, cameraMatrix1, distCoeffs1, cameraMatrix2, distCoeffs2, imageSize, r, t, e, f, flags, termCrit); } public static double StereoCalibrate(IInputArray objectPoints, IInputArray imagePoints1, IInputArray imagePoints2, IInputOutputArray cameraMatrix1, IInputOutputArray distCoeffs1, IInputOutputArray cameraMatrix2, IInputOutputArray distCoeffs2, Size imageSize, IOutputArray r, IOutputArray t, IOutputArray e, IOutputArray f, CalibType flags, MCvTermCriteria termCrit) { using InputArray inputArray = objectPoints.GetInputArray(); using InputArray inputArray2 = imagePoints1.GetInputArray(); using InputArray inputArray3 = imagePoints2.GetInputArray(); using InputOutputArray inputOutputArray = cameraMatrix1.GetInputOutputArray(); using InputOutputArray inputOutputArray3 = cameraMatrix2.GetInputOutputArray(); using InputOutputArray inputOutputArray2 = distCoeffs1.GetInputOutputArray(); using InputOutputArray inputOutputArray4 = distCoeffs2.GetInputOutputArray(); using OutputArray outputArray = r.GetOutputArray(); using OutputArray outputArray2 = t.GetOutputArray(); using OutputArray outputArray3 = e.GetOutputArray(); using OutputArray outputArray4 = f.GetOutputArray(); return cveStereoCalibrate(inputArray, inputArray2, inputArray3, inputOutputArray, inputOutputArray2, inputOutputArray3, inputOutputArray4, ref imageSize, outputArray, outputArray2, outputArray3, outputArray4, flags, ref termCrit); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern double cveStereoCalibrate(IntPtr objectPoints, IntPtr imagePoints1, IntPtr imagePoints2, IntPtr cameraMatrix1, IntPtr distCoeffs1, IntPtr cameraMatrix2, IntPtr distCoeffs2, ref Size imageSize, IntPtr r, IntPtr t, IntPtr e, IntPtr f, CalibType flags, ref MCvTermCriteria termCrit); public static bool StereoRectifyUncalibrated(IInputArray points1, IInputArray points2, IInputArray f, Size imgSize, IOutputArray h1, IOutputArray h2, double threshold = 5.0) { using InputArray inputArray = points1.GetInputArray(); using InputArray inputArray2 = points2.GetInputArray(); using InputArray inputArray3 = f.GetInputArray(); using OutputArray outputArray = h1.GetOutputArray(); using OutputArray outputArray2 = h2.GetOutputArray(); return cveStereoRectifyUncalibrated(inputArray, inputArray2, inputArray3, ref imgSize, outputArray, outputArray2, threshold); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.U1)] private static extern bool cveStereoRectifyUncalibrated(IntPtr points1, IntPtr points2, IntPtr f, ref Size imgSize, IntPtr h1, IntPtr h2, double threshold); public static void StereoRectify(IInputArray cameraMatrix1, IInputArray distCoeffs1, IInputArray cameraMatrix2, IInputArray distCoeffs2, Size imageSize, IInputArray r, IInputArray t, IOutputArray r1, IOutputArray r2, IOutputArray p1, IOutputArray p2, IOutputArray q, StereoRectifyType flags, double alpha, Size newImageSize, ref Rectangle validPixRoi1, ref Rectangle validPixRoi2) { using InputArray inputArray = cameraMatrix1.GetInputArray(); using InputArray inputArray2 = distCoeffs1.GetInputArray(); using InputArray inputArray3 = cameraMatrix2.GetInputArray(); using InputArray inputArray4 = distCoeffs2.GetInputArray(); using InputArray inputArray5 = r.GetInputArray(); using InputArray inputArray6 = t.GetInputArray(); using OutputArray outputArray = r1.GetOutputArray(); using OutputArray outputArray2 = r2.GetOutputArray(); using OutputArray outputArray3 = p1.GetOutputArray(); using OutputArray outputArray4 = p2.GetOutputArray(); using OutputArray outputArray5 = q.GetOutputArray(); cveStereoRectify(inputArray, inputArray2, inputArray3, inputArray4, ref imageSize, inputArray5, inputArray6, outputArray, outputArray2, outputArray3, outputArray4, outputArray5, flags, alpha, ref newImageSize, ref validPixRoi1, ref validPixRoi2); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveStereoRectify(IntPtr cameraMatrix1, IntPtr distCoeffs1, IntPtr cameraMatrix2, IntPtr distCoeffs2, ref Size imageSize, IntPtr r, IntPtr t, IntPtr r1, IntPtr r2, IntPtr p1, IntPtr p2, IntPtr q, StereoRectifyType flags, double alpha, ref Size newImageSize, ref Rectangle validPixRoi1, ref Rectangle validPixRoi2); public static bool Find4QuadCornerSubpix(IInputArray image, IInputOutputArray corners, Size regionSize) { using InputArray inputArray = image.GetInputArray(); using InputOutputArray inputOutputArray = corners.GetInputOutputArray(); return cveFind4QuadCornerSubpix(inputArray, inputOutputArray, ref regionSize); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.U1)] private static extern bool cveFind4QuadCornerSubpix(IntPtr image, IntPtr corners, ref Size regionSize); public static bool FindChessboardCorners(IInputArray image, Size patternSize, IOutputArray corners, CalibCbType flags = CalibCbType.AdaptiveThresh | CalibCbType.NormalizeImage) { using InputArray inputArray = image.GetInputArray(); using OutputArray outputArray = corners.GetOutputArray(); return cveFindChessboardCorners(inputArray, ref patternSize, outputArray, flags); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.U1)] private static extern bool cveFindChessboardCorners(IntPtr image, ref Size patternSize, IntPtr corners, CalibCbType flags); public static void FilterSpeckles(IInputOutputArray img, double newVal, int maxSpeckleSize, double maxDiff, IInputOutputArray buf = null) { using InputOutputArray inputOutputArray = img.GetInputOutputArray(); using InputOutputArray inputOutputArray2 = ((buf == null) ? InputOutputArray.GetEmpty() : buf.GetInputOutputArray()); cveFilterSpeckles(inputOutputArray, newVal, maxSpeckleSize, maxDiff, inputOutputArray2); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveFilterSpeckles(IntPtr img, double newVal, int maxSpeckleSize, double maxDiff, IntPtr buf); public static bool FindChessboardCornersSB(IInputArray image, Size patternSize, IOutputArray corners, CalibCbType flags = CalibCbType.Default) { using InputArray inputArray = image.GetInputArray(); using OutputArray outputArray = corners.GetOutputArray(); return cveFindChessboardCornersSB(inputArray, ref patternSize, outputArray, flags); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.U1)] private static extern bool cveFindChessboardCornersSB(IntPtr image, ref Size patternSize, IntPtr corners, CalibCbType flags); public static void DrawChessboardCorners(IInputOutputArray image, Size patternSize, IInputArray corners, bool patternWasFound) { using InputOutputArray inputOutputArray = image.GetInputOutputArray(); using InputArray inputArray = corners.GetInputArray(); cveDrawChessboardCorners(inputOutputArray, ref patternSize, inputArray, patternWasFound); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveDrawChessboardCorners(IntPtr image, ref Size patternSize, IntPtr corners, [MarshalAs(UnmanagedType.U1)] bool patternWasFound); public static void TriangulatePoints(IInputArray projMat1, IInputArray projMat2, IInputArray projPoints1, IInputArray projPoints2, IOutputArray points4D) { using InputArray inputArray = projMat1.GetInputArray(); using InputArray inputArray2 = projMat2.GetInputArray(); using InputArray inputArray3 = projPoints1.GetInputArray(); using InputArray inputArray4 = projPoints2.GetInputArray(); using OutputArray outputArray = points4D.GetOutputArray(); cveTriangulatePoints(inputArray, inputArray2, inputArray3, inputArray4, outputArray); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveTriangulatePoints(IntPtr projMat1, IntPtr projMat2, IntPtr projPoints1, IntPtr projPoints2, IntPtr points4D); public static void CorrectMatches(IInputArray f, IInputArray points1, IInputArray points2, IOutputArray newPoints1, IOutputArray newPoints2) { using InputArray inputArray = f.GetInputArray(); using InputArray inputArray2 = points1.GetInputArray(); using InputArray inputArray3 = points2.GetInputArray(); using OutputArray outputArray = newPoints1.GetOutputArray(); using OutputArray outputArray2 = newPoints2.GetOutputArray(); cveCorrectMatches(inputArray, inputArray2, inputArray3, outputArray, outputArray2); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveCorrectMatches(IntPtr f, IntPtr points1, IntPtr points2, IntPtr newPoints1, IntPtr newPoints2); public static MCvScalar EstimateChessboardSharpness(IInputArray image, Size patternSize, IInputArray corners, float riseDistance = 0.8f, bool vertical = false, IOutputArray sharpness = null) { MCvScalar result = default(MCvScalar); using InputArray inputArray = image.GetInputArray(); using InputArray inputArray2 = corners.GetInputArray(); using OutputArray outputArray = ((sharpness == null) ? OutputArray.GetEmpty() : sharpness.GetOutputArray()); cveEstimateChessboardSharpness(inputArray, ref patternSize, inputArray2, riseDistance, vertical, outputArray, ref result); return result; } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveEstimateChessboardSharpness(IntPtr image, ref Size patternSize, IntPtr corners, float riseDistance, [MarshalAs(UnmanagedType.U1)] bool vertical, IntPtr sharpness, ref MCvScalar result); private static int CvIgnoreErrorErrorHandler(int status, IntPtr funcName, IntPtr errMsg, IntPtr fileName, int line, IntPtr userData) { SetErrStatus(ErrorCodes.StsOk); return 0; } private static int CvErrorHandler(int status, IntPtr funcName, IntPtr errMsg, IntPtr fileName, int line, IntPtr userData) { try { SetErrStatus(ErrorCodes.StsOk); int num = 0; } finally { string funcName2 = Marshal.PtrToStringAnsi(funcName); string errMsg2 = Marshal.PtrToStringAnsi(errMsg); string fileName2 = Marshal.PtrToStringAnsi(fileName); throw new CvException(status, funcName2, errMsg2, fileName2, line); } } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl, EntryPoint = "cveRedirectError")] public static extern IntPtr RedirectError(CvErrorCallback errorHandler, IntPtr userdata, IntPtr prevUserdata); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl, EntryPoint = "cveRedirectError")] public static extern IntPtr RedirectError(IntPtr errorHandler, IntPtr userdata, IntPtr prevUserdata); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl, EntryPoint = "cveSetErrMode")] public static extern int SetErrMode(int errorMode); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl, EntryPoint = "cveGetErrMode")] public static extern int GetErrMode(); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl, EntryPoint = "cveGetErrStatus")] public static extern int GetErrStatus(); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl, EntryPoint = "cveSetErrStatus")] public static extern void SetErrStatus(ErrorCodes code); public static string ErrorStr(int status) { IntPtr intPtr = cveErrorStr(status); if (!(intPtr == IntPtr.Zero)) { return Marshal.PtrToStringAnsi(intPtr); } return string.Empty; } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern IntPtr cveErrorStr(int status); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern LogLevel cveSetLogLevel(LogLevel logLevel); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern LogLevel cveGetLogLevel(); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl, EntryPoint = "cveReshape")] public static extern IntPtr cvReshape(IntPtr arr, IntPtr header, int newCn, int newRows); public static void Repeat(IInputArray src, int ny, int nx, IOutputArray dst) { using InputArray inputArray = src.GetInputArray(); using OutputArray outputArray = dst.GetOutputArray(); cveRepeat(inputArray, ny, nx, outputArray); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveRepeat(IntPtr src, int ny, int nx, IntPtr dst); public static void Merge(IInputArrayOfArrays mv, IOutputArray dst) { using InputArray inputArray = mv.GetInputArray(); using OutputArray outputArray = dst.GetOutputArray(); cveMerge(inputArray, outputArray); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveMerge(IntPtr mv, IntPtr dst); public static void MixChannels(IInputArrayOfArrays src, IInputOutputArray dst, int[] fromTo) { GCHandle gCHandle = GCHandle.Alloc(fromTo, GCHandleType.Pinned); using (InputArray inputArray = src.GetInputArray()) { using InputOutputArray inputOutputArray = dst.GetInputOutputArray(); cveMixChannels(inputArray, inputOutputArray, gCHandle.AddrOfPinnedObject(), fromTo.Length >> 1); } gCHandle.Free(); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveMixChannels(IntPtr src, IntPtr dst, IntPtr fromTo, int npairs); public static void ExtractChannel(IInputArray src, IOutputArray dst, int coi) { using InputArray inputArray = src.GetInputArray(); using OutputArray outputArray = dst.GetOutputArray(); cveExtractChannel(inputArray, outputArray, coi); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveExtractChannel(IntPtr src, IntPtr dst, int coi); public static void InsertChannel(IInputArray src, IInputOutputArray dst, int coi) { using InputArray inputArray = src.GetInputArray(); using InputOutputArray inputOutputArray = dst.GetInputOutputArray(); cveInsertChannel(inputArray, inputOutputArray, coi); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveInsertChannel(IntPtr src, IntPtr dst, int coi); public static void RandShuffle(IInputOutputArray mat, double iterFactor, ulong rng) { using InputOutputArray inputOutputArray = mat.GetInputOutputArray(); cveRandShuffle(inputOutputArray, iterFactor, rng); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveRandShuffle(IntPtr mat, double iterFactor, ulong rng); public static void BitwiseNot(IInputArray src, IOutputArray dst, IInputArray mask = null) { using InputArray inputArray = src.GetInputArray(); using OutputArray outputArray = dst.GetOutputArray(); using InputArray inputArray2 = ((mask == null) ? InputArray.GetEmpty() : mask.GetInputArray()); cveBitwiseNot(inputArray, outputArray, inputArray2); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveBitwiseNot(IntPtr src, IntPtr dst, IntPtr mask); public static void Max(IInputArray src1, IInputArray src2, IOutputArray dst) { using InputArray inputArray = src1.GetInputArray(); using InputArray inputArray2 = src2.GetInputArray(); using OutputArray outputArray = dst.GetOutputArray(); cveMax(inputArray, inputArray2, outputArray); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveMax(IntPtr src1, IntPtr src2, IntPtr dst); public static int CountNonZero(IInputArray arr) { using InputArray inputArray = arr.GetInputArray(); return cveCountNonZero(inputArray); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern int cveCountNonZero(IntPtr arr); public static void FindNonZero(IInputArray src, IOutputArray idx) { using InputArray inputArray = src.GetInputArray(); using OutputArray outputArray = idx.GetOutputArray(); cveFindNonZero(inputArray, outputArray); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveFindNonZero(IntPtr src, IntPtr idx); public static double PSNR(IInputArray src1, IInputArray src2) { using InputArray inputArray = src1.GetInputArray(); using InputArray inputArray2 = src2.GetInputArray(); return cvePSNR(inputArray, inputArray2); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern double cvePSNR(IntPtr src1, IntPtr src2); public static void Min(IInputArray src1, IInputArray src2, IOutputArray dst) { using InputArray inputArray = src1.GetInputArray(); using InputArray inputArray2 = src2.GetInputArray(); using OutputArray outputArray = dst.GetOutputArray(); cveMin(inputArray, inputArray2, outputArray); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveMin(IntPtr src1, IntPtr src2, IntPtr dst); public static void Add(IInputArray src1, IInputArray src2, IOutputArray dst, IInputArray mask = null, DepthType dtype = DepthType.Default) { using InputArray inputArray = src1.GetInputArray(); using InputArray inputArray2 = src2.GetInputArray(); using OutputArray outputArray = dst.GetOutputArray(); using InputArray inputArray3 = ((mask == null) ? InputArray.GetEmpty() : mask.GetInputArray()); cveAdd(inputArray, inputArray2, outputArray, inputArray3, dtype); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveAdd(IntPtr src1, IntPtr src2, IntPtr dst, IntPtr mask, DepthType dtype); public static void Subtract(IInputArray src1, IInputArray src2, IOutputArray dst, IInputArray mask = null, DepthType dtype = DepthType.Default) { using InputArray inputArray = src1.GetInputArray(); using InputArray inputArray2 = src2.GetInputArray(); using OutputArray outputArray = dst.GetOutputArray(); using InputArray inputArray3 = ((mask == null) ? InputArray.GetEmpty() : mask.GetInputArray()); cveSubtract(inputArray, inputArray2, outputArray, inputArray3, dtype); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveSubtract(IntPtr src1, IntPtr src2, IntPtr dst, IntPtr mask, DepthType dtype); public static void Divide(IInputArray src1, IInputArray src2, IOutputArray dst, double scale = 1.0, DepthType dtype = DepthType.Default) { using InputArray inputArray = src1.GetInputArray(); using InputArray inputArray2 = src2.GetInputArray(); using OutputArray outputArray = dst.GetOutputArray(); cveDivide(inputArray, inputArray2, outputArray, scale, dtype); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveDivide(IntPtr src1, IntPtr src2, IntPtr dst, double scale, DepthType dtype); public static void Multiply(IInputArray src1, IInputArray src2, IOutputArray dst, double scale = 1.0, DepthType dtype = DepthType.Default) { using InputArray inputArray = src1.GetInputArray(); using InputArray inputArray2 = src2.GetInputArray(); using OutputArray outputArray = dst.GetOutputArray(); cveMultiply(inputArray, inputArray2, outputArray, scale, dtype); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveMultiply(IntPtr src1, IntPtr src2, IntPtr dst, double scale, DepthType dtype); public static void BitwiseAnd(IInputArray src1, IInputArray src2, IOutputArray dst, IInputArray mask = null) { using InputArray inputArray = src1.GetInputArray(); using InputArray inputArray2 = src2.GetInputArray(); using OutputArray outputArray = dst.GetOutputArray(); using InputArray inputArray3 = ((mask == null) ? InputArray.GetEmpty() : mask.GetInputArray()); cveBitwiseAnd(inputArray, inputArray2, outputArray, inputArray3); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveBitwiseAnd(IntPtr src1, IntPtr src2, IntPtr dst, IntPtr mask); public static void BitwiseOr(IInputArray src1, IInputArray src2, IOutputArray dst, IInputArray mask = null) { using InputArray inputArray = src1.GetInputArray(); using InputArray inputArray2 = src2.GetInputArray(); using OutputArray outputArray = dst.GetOutputArray(); using InputArray inputArray3 = ((mask == null) ? InputArray.GetEmpty() : mask.GetInputArray()); cveBitwiseOr(inputArray, inputArray2, outputArray, inputArray3); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveBitwiseOr(IntPtr src1, IntPtr src2, IntPtr dst, IntPtr mask); public static void BitwiseXor(IInputArray src1, IInputArray src2, IOutputArray dst, IInputArray mask = null) { using InputArray inputArray = src1.GetInputArray(); using InputArray inputArray2 = src2.GetInputArray(); using OutputArray outputArray = dst.GetOutputArray(); using InputArray inputArray3 = ((mask == null) ? InputArray.GetEmpty() : mask.GetInputArray()); cveBitwiseXor(inputArray, inputArray2, outputArray, inputArray3); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveBitwiseXor(IntPtr src1, IntPtr src2, IntPtr dst, IntPtr mask); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl, EntryPoint = "cveCopy")] public static extern void cvCopy(IntPtr src, IntPtr des, IntPtr mask); public static void SetIdentity(IInputOutputArray mat, MCvScalar value) { using InputOutputArray inputOutputArray = mat.GetInputOutputArray(); cveSetIdentity(inputOutputArray, ref value); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveSetIdentity(IntPtr mat, ref MCvScalar value); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl, EntryPoint = "cveRange")] public static extern void cvRange(IntPtr mat, double start, double end); public static void CartToPolar(IInputArray x, IInputArray y, IOutputArray magnitude, IOutputArray angle, bool angleInDegrees = false) { using InputArray inputArray = x.GetInputArray(); using InputArray inputArray2 = y.GetInputArray(); using OutputArray outputArray = magnitude.GetOutputArray(); using OutputArray outputArray2 = angle.GetOutputArray(); cveCartToPolar(inputArray, inputArray2, outputArray, outputArray2, angleInDegrees); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveCartToPolar(IntPtr x, IntPtr y, IntPtr magnitude, IntPtr angle, [MarshalAs(UnmanagedType.U1)] bool angleInDegrees); public static void PolarToCart(IInputArray magnitude, IInputArray angle, IOutputArray x, IOutputArray y, bool angleInDegrees = false) { using InputArray inputArray = magnitude.GetInputArray(); using InputArray inputArray2 = angle.GetInputArray(); using OutputArray outputArray = x.GetOutputArray(); using OutputArray outputArray2 = y.GetOutputArray(); cvePolarToCart(inputArray, inputArray2, outputArray, outputArray2, angleInDegrees); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cvePolarToCart(IntPtr magnitude, IntPtr angle, IntPtr x, IntPtr y, [MarshalAs(UnmanagedType.U1)] bool angleInDegrees); public static void Pow(IInputArray src, double power, IOutputArray dst) { using InputArray inputArray = src.GetInputArray(); using OutputArray outputArray = dst.GetOutputArray(); cvePow(inputArray, power, outputArray); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cvePow(IntPtr src, double power, IntPtr dst); public static void Exp(IInputArray src, IOutputArray dst) { using InputArray inputArray = src.GetInputArray(); using OutputArray outputArray = dst.GetOutputArray(); cveExp(inputArray, outputArray); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveExp(IntPtr src, IntPtr dst); public static void Log(IInputArray src, IOutputArray dst) { using InputArray inputArray = src.GetInputArray(); using OutputArray outputArray = dst.GetOutputArray(); cveLog(inputArray, outputArray); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveLog(IntPtr src, IntPtr dst); public static int SolveCubic(IInputArray coeffs, IOutputArray roots) { using InputArray inputArray = coeffs.GetInputArray(); using OutputArray outputArray = roots.GetOutputArray(); return cveSolveCubic(inputArray, outputArray); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern int cveSolveCubic(IntPtr coeffs, IntPtr roots); public static double SolvePoly(IInputArray coeffs, IOutputArray roots, int maxiter = 300) { using InputArray inputArray = coeffs.GetInputArray(); using OutputArray outputArray = roots.GetOutputArray(); return cveSolvePoly(inputArray, outputArray, maxiter); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern double cveSolvePoly(IntPtr coeffs, IntPtr roots, int maxiter); public static bool Solve(IInputArray src1, IInputArray src2, IOutputArray dst, DecompMethod method) { using InputArray inputArray = src1.GetInputArray(); using InputArray inputArray2 = src2.GetInputArray(); using OutputArray outputArray = dst.GetOutputArray(); return cveSolve(inputArray, inputArray2, outputArray, method); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.U1)] private static extern bool cveSolve(IntPtr src1, IntPtr src2, IntPtr dst, DecompMethod method); public static void Sort(IInputArray src, IOutputArray dst, SortFlags flags) { using InputArray inputArray = src.GetInputArray(); using OutputArray outputArray = dst.GetOutputArray(); cveSort(inputArray, outputArray, flags); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveSort(IntPtr src, IntPtr dst, SortFlags flags); public static void SortIdx(IInputArray src, IOutputArray dst, SortFlags flags) { using InputArray inputArray = src.GetInputArray(); using OutputArray outputArray = dst.GetOutputArray(); cveSortIdx(inputArray, outputArray, flags); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveSortIdx(IntPtr src, IntPtr dst, SortFlags flags); public static void Dft(IInputArray src, IOutputArray dst, DxtType flags, int nonzeroRows) { using InputArray inputArray = src.GetInputArray(); using OutputArray outputArray = dst.GetOutputArray(); cveDft(inputArray, outputArray, flags, nonzeroRows); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveDft(IntPtr src, IntPtr dst, DxtType flags, int nonzeroRows); public static int GetOptimalDFTSize(int vecsize) { return cveGetOptimalDFTSize(vecsize); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern int cveGetOptimalDFTSize(int vecsize); public static void MulSpectrums(IInputArray src1, IInputArray src2, IOutputArray dst, MulSpectrumsType flags, bool conjB = false) { using InputArray inputArray = src1.GetInputArray(); using InputArray inputArray2 = src2.GetInputArray(); using OutputArray outputArray = dst.GetOutputArray(); cveMulSpectrums(inputArray, inputArray2, outputArray, flags, conjB); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveMulSpectrums(IntPtr src1, IntPtr src2, IntPtr dst, MulSpectrumsType flags, [MarshalAs(UnmanagedType.U1)] bool conjB); public static void Dct(IInputArray src, IOutputArray dst, DctType flags) { using InputArray inputArray = src.GetInputArray(); using OutputArray outputArray = dst.GetOutputArray(); cveDct(inputArray, outputArray, flags); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveDct(IntPtr src, IntPtr dst, DctType flags); public static bool ClipLine(Rectangle rectangle, ref Point pt1, ref Point pt2) { return cveClipLine(ref rectangle, ref pt1, ref pt2); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.U1)] private static extern bool cveClipLine(ref Rectangle rect, ref Point pt1, ref Point pt2); public static void AbsDiff(IInputArray src1, IInputArray src2, IOutputArray dst) { using InputArray inputArray = src1.GetInputArray(); using InputArray inputArray2 = src2.GetInputArray(); using OutputArray outputArray = dst.GetOutputArray(); cveAbsDiff(inputArray, inputArray2, outputArray); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveAbsDiff(IntPtr src1, IntPtr src2, IntPtr dst); public static void ScaleAdd(IInputArray src1, double alpha, IInputArray src2, IOutputArray dst) { using InputArray inputArray = src1.GetInputArray(); using InputArray inputArray2 = src2.GetInputArray(); using OutputArray outputArray = dst.GetOutputArray(); cveScaleAdd(inputArray, alpha, inputArray2, outputArray); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveScaleAdd(IntPtr src1, double alpha, IntPtr src2, IntPtr dst); public static void AddWeighted(IInputArray src1, double alpha, IInputArray src2, double beta, double gamma, IOutputArray dst, DepthType dtype = DepthType.Default) { using InputArray inputArray = src1.GetInputArray(); using InputArray inputArray2 = src2.GetInputArray(); using OutputArray outputArray = dst.GetOutputArray(); cveAddWeighted(inputArray, alpha, inputArray2, beta, gamma, outputArray, dtype); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveAddWeighted(IntPtr src1, double alpha, IntPtr src2, double beta, double gamma, IntPtr dst, DepthType dtype); public static void InRange(IInputArray src, IInputArray lower, IInputArray upper, IOutputArray dst) { using InputArray inputArray = src.GetInputArray(); using InputArray inputArray2 = lower.GetInputArray(); using InputArray inputArray3 = upper.GetInputArray(); using OutputArray outputArray = dst.GetOutputArray(); cveInRange(inputArray, inputArray2, inputArray3, outputArray); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveInRange(IntPtr src, IntPtr lower, IntPtr upper, IntPtr dst); public static double Norm(IInputArray arr1, IInputOutputArray arr2, NormType normType = NormType.L2, IInputArray mask = null) { using InputArray inputArray = arr1.GetInputArray(); using InputOutputArray inputOutputArray = ((arr2 == null) ? InputOutputArray.GetEmpty() : arr2.GetInputOutputArray()); using InputArray inputArray2 = ((mask == null) ? InputArray.GetEmpty() : mask.GetInputArray()); return cveNorm(inputArray, inputOutputArray, normType, inputArray2); } public static double Norm(IInputArray arr1, NormType normType = NormType.L2, IInputArray mask = null) { return Norm(arr1, null, normType, mask); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern double cveNorm(IntPtr arr1, IntPtr arr2, NormType normType, IntPtr mask); public static IntPtr cvCreateImage(Size size, IplDepth depth, int channels) { return cveCreateImageHeader(ref size, depth, channels); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern IntPtr cveCreateImage(ref Size size, IplDepth depth, int channels); public static IntPtr cvCreateImageHeader(Size size, IplDepth depth, int channels) { return cveCreateImageHeader(ref size, depth, channels); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern IntPtr cveCreateImageHeader(ref Size size, IplDepth depth, int channels); public static IntPtr cvInitImageHeader(IntPtr image, Size size, IplDepth depth, int channels, int origin, int align) { return cveInitImageHeader(image, ref size, depth, channels, origin, align); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern IntPtr cveInitImageHeader(IntPtr image, ref Size size, IplDepth depth, int channels, int origin, int align); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl, EntryPoint = "cveSetData")] public static extern void cvSetData(IntPtr arr, IntPtr data, int step); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl, EntryPoint = "cveReleaseImageHeader")] public static extern void cvReleaseImageHeader(ref IntPtr image); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl, EntryPoint = "cveInitMatHeader")] public static extern IntPtr cvInitMatHeader(IntPtr mat, int rows, int cols, int type, IntPtr data, int step); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl, EntryPoint = "cveSetImageCOI")] public static extern void cvSetImageCOI(IntPtr image, int coi); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl, EntryPoint = "cveGetImageCOI")] public static extern int cvGetImageCOI(IntPtr image); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl, EntryPoint = "cveResetImageROI")] public static extern void cvResetImageROI(IntPtr image); public static void cvSetImageROI(IntPtr image, Rectangle rect) { cveSetImageROI(image, ref rect); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveSetImageROI(IntPtr image, ref Rectangle rect); public static Rectangle cvGetImageROI(IntPtr image) { Rectangle rect = default(Rectangle); cveGetImageROI(image, ref rect); return rect; } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveGetImageROI(IntPtr image, ref Rectangle rect); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl, EntryPoint = "cveCreateMat")] public static extern IntPtr cvCreateMat(int rows, int cols, DepthType type); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl, EntryPoint = "cveInitMatNDHeader")] public static extern IntPtr cvInitMatNDHeader(IntPtr mat, int dims, [In] int[] sizes, DepthType type, IntPtr data); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl, EntryPoint = "cveReleaseMat")] public static extern void cvReleaseMat(ref IntPtr mat); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl, EntryPoint = "cveCreateSparseMat")] public static extern IntPtr cvCreateSparseMat(int dims, IntPtr sizes, DepthType type); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl, EntryPoint = "cveReleaseSparseMat")] public static extern void cvReleaseSparseMat(ref IntPtr mat); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl, EntryPoint = "cveSetReal1D")] public static extern void cvSetReal1D(IntPtr arr, int idx0, double value); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl, EntryPoint = "cveSetReal2D")] public static extern void cvSetReal2D(IntPtr arr, int idx0, int idx1, double value); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl, EntryPoint = "cveSetReal3D")] public static extern void cvSetReal3D(IntPtr arr, int idx0, int idx1, int idx2, double value); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl, EntryPoint = "cveSetRealND")] public static extern void cvSetRealND(IntPtr arr, [In] int[] idx, double value); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl, EntryPoint = "cveClearND")] public static extern void cvClearND(IntPtr arr, [In] int[] idx); public static void cvSet2D(IntPtr arr, int idx0, int idx1, MCvScalar value) { cveSet2D(arr, idx0, idx1, ref value); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveSet2D(IntPtr arr, int idx0, int idx1, ref MCvScalar value); public static void Flip(IInputArray src, IOutputArray dst, FlipType flipType) { using InputArray inputArray = src.GetInputArray(); using OutputArray outputArray = dst.GetOutputArray(); cveFlip(inputArray, outputArray, flipType); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveFlip(IntPtr src, IntPtr dst, FlipType flipMode); public static void Rotate(IInputArray src, IOutputArray dst, RotateFlags rotateCode) { using InputArray inputArray = src.GetInputArray(); using OutputArray outputArray = dst.GetOutputArray(); cveRotate(inputArray, outputArray, rotateCode); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveRotate(IntPtr src, IntPtr dst, RotateFlags rotateCode); public static IntPtr cvGetSubRect(IntPtr arr, IntPtr submat, Rectangle rect) { return cveGetSubRect(arr, submat, ref rect); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern IntPtr cveGetSubRect(IntPtr arr, IntPtr submat, ref Rectangle rect); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl, EntryPoint = "cveGetRows")] public static extern IntPtr cvGetRows(IntPtr arr, IntPtr submat, int startRow, int endRow, int deltaRow); public static IntPtr cvGetRow(IntPtr arr, IntPtr submat, int row) { return cvGetRows(arr, submat, row, row + 1, 1); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl, EntryPoint = "cveGetCols")] public static extern IntPtr cvGetCols(IntPtr arr, IntPtr submat, int startCol, int endCol); public static IntPtr cvGetCol(IntPtr arr, IntPtr submat, int col) { return cvGetCols(arr, submat, col, col + 1); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl, EntryPoint = "cveGetDiag")] public static extern IntPtr cvGetDiag(IntPtr arr, IntPtr submat, int diag); public static Size cvGetSize(IntPtr arr) { int width = 0; int height = 0; cveGetSize(arr, ref width, ref height); return new Size(width, height); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveGetSize(IntPtr arr, ref int width, ref int height); public static void Circle(IInputOutputArray img, Point center, int radius, MCvScalar color, int thickness = 1, LineType lineType = LineType.EightConnected, int shift = 0) { using InputOutputArray inputOutputArray = img.GetInputOutputArray(); cveCircle(inputOutputArray, ref center, radius, ref color, thickness, lineType, shift); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveCircle(IntPtr img, ref Point center, int radius, ref MCvScalar color, int thickness, LineType lineType, int shift); public static void Split(IInputArray src, IOutputArray mv) { using InputArray inputArray = src.GetInputArray(); using OutputArray outputArray = mv.GetOutputArray(); cveSplit(inputArray, outputArray); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveSplit(IntPtr src, IntPtr mv); public static void Ellipse(IInputOutputArray img, Point center, Size axes, double angle, double startAngle, double endAngle, MCvScalar color, int thickness = 1, LineType lineType = LineType.EightConnected, int shift = 0) { using InputOutputArray inputOutputArray = img.GetInputOutputArray(); cveEllipse(inputOutputArray, ref center, ref axes, angle, startAngle, endAngle, ref color, thickness, lineType, shift); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveEllipse(IntPtr img, ref Point center, ref Size axes, double angle, double startAngle, double endAngle, ref MCvScalar color, int thickness, LineType lineType, int shift); public static void Ellipse(IInputOutputArray img, RotatedRect box, MCvScalar color, int thickness = 1, LineType lineType = LineType.EightConnected, int shift = 0) { Size axes = default(Size); axes.Width = (int)Math.Round((double)box.Size.Height * 0.5); axes.Height = (int)Math.Round((double)box.Size.Width * 0.5); Ellipse(img, Point.Round(box.Center), axes, box.Angle, 0.0, 360.0, color, thickness, lineType, shift); } public static void DrawMarker(IInputOutputArray img, Point position, MCvScalar color, MarkerTypes markerType, int markerSize = 20, int thickness = 1, LineType lineType = LineType.EightConnected) { using InputOutputArray inputOutputArray = img.GetInputOutputArray(); cveDrawMarker(inputOutputArray, ref position, ref color, markerType, markerSize, thickness, lineType); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveDrawMarker(IntPtr img, ref Point position, ref MCvScalar color, MarkerTypes markerType, int markerSize, int thickness, LineType lineType); public static void LUT(IInputArray src, IInputArray lut, IOutputArray dst) { using InputArray inputArray = src.GetInputArray(); using InputArray inputArray2 = lut.GetInputArray(); using OutputArray outputArray = dst.GetOutputArray(); cveLUT(inputArray, inputArray2, outputArray); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveLUT(IntPtr src, IntPtr lut, IntPtr dst); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl, EntryPoint = "cveConvertScale")] public static extern void cvConvertScale(IntPtr src, IntPtr dst, double scale, double shift); public static void ConvertScaleAbs(IInputArray src, IOutputArray dst, double scale, double shift) { using InputArray inputArray = src.GetInputArray(); using OutputArray outputArray = dst.GetOutputArray(); cveConvertScaleAbs(inputArray, outputArray, scale, shift); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveConvertScaleAbs(IntPtr src, IntPtr dst, double scale, double shift); public static MCvScalar Mean(IInputArray arr, IInputArray mask = null) { MCvScalar result = default(MCvScalar); using InputArray inputArray = arr.GetInputArray(); using InputArray inputArray2 = ((mask == null) ? InputArray.GetEmpty() : mask.GetInputArray()); cveMean(inputArray, inputArray2, ref result); return result; } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveMean(IntPtr src, IntPtr mask, ref MCvScalar result); public static void MeanStdDev(IInputArray arr, ref MCvScalar mean, ref MCvScalar stdDev, IInputArray mask = null) { using VectorOfDouble vectorOfDouble = new VectorOfDouble(4); using VectorOfDouble vectorOfDouble2 = new VectorOfDouble(4); MeanStdDev(arr, vectorOfDouble, vectorOfDouble2, mask); double[] array = vectorOfDouble.ToArray(); double[] array2 = vectorOfDouble2.ToArray(); mean.V0 = array[0]; stdDev.V0 = array2[0]; if (array.Length > 1) { mean.V1 = array[1]; stdDev.V1 = array2[1]; } if (array.Length > 2) { mean.V2 = array[2]; stdDev.V2 = array2[2]; } if (array.Length > 3) { mean.V3 = array[3]; stdDev.V3 = array2[3]; } } public static void MeanStdDev(IInputArray arr, IOutputArray mean, IOutputArray stdDev, IInputArray mask = null) { using InputArray inputArray = arr.GetInputArray(); using OutputArray outputArray = mean.GetOutputArray(); using OutputArray outputArray2 = stdDev.GetOutputArray(); using InputArray inputArray2 = ((mask == null) ? InputArray.GetEmpty() : mask.GetInputArray()); cveMeanStdDev(inputArray, outputArray, outputArray2, inputArray2); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveMeanStdDev(IntPtr arr, IntPtr mean, IntPtr stdDev, IntPtr mask); public static MCvScalar Sum(IInputArray src) { MCvScalar result = default(MCvScalar); using InputArray inputArray = src.GetInputArray(); cveSum(inputArray, ref result); return result; } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveSum(IntPtr src, ref MCvScalar result); public static void Reduce(IInputArray src, IOutputArray dst, ReduceDimension dim = ReduceDimension.Auto, ReduceType type = ReduceType.ReduceSum, DepthType dtype = DepthType.Default) { using InputArray inputArray = src.GetInputArray(); using OutputArray outputArray = dst.GetOutputArray(); cveReduce(inputArray, outputArray, dim, type, dtype); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveReduce(IntPtr src, IntPtr dst, ReduceDimension dim, ReduceType type, DepthType dtype); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl, EntryPoint = "cveReleaseImage")] public static extern void cvReleaseImage(ref IntPtr image); public static void DrawContours(IInputOutputArray image, IInputArrayOfArrays contours, int contourIdx, MCvScalar color, int thickness = 1, LineType lineType = LineType.EightConnected, IInputArray hierarchy = null, int maxLevel = int.MaxValue, Point offset = default(Point)) { using InputOutputArray inputOutputArray = image.GetInputOutputArray(); using InputArray inputArray = contours.GetInputArray(); using InputArray inputArray2 = ((hierarchy == null) ? InputArray.GetEmpty() : hierarchy.GetInputArray()); cveDrawContours(inputOutputArray, inputArray, contourIdx, ref color, thickness, lineType, inputArray2, maxLevel, ref offset); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveDrawContours(IntPtr image, IntPtr contour, int coutourIdx, ref MCvScalar color, int thickness, LineType lineType, IntPtr hierarchy, int maxLevel, ref Point offset); public static void FillConvexPoly(IInputOutputArray img, IInputArray points, MCvScalar color, LineType lineType = LineType.EightConnected, int shift = 0) { using InputOutputArray inputOutputArray = img.GetInputOutputArray(); using InputArray inputArray = points.GetInputArray(); cveFillConvexPoly(inputOutputArray, inputArray, ref color, lineType, shift); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveFillConvexPoly(IntPtr img, IntPtr pts, ref MCvScalar color, LineType lineType, int shift); public static void FillPoly(IInputOutputArray img, IInputArray points, MCvScalar color, LineType lineType = LineType.EightConnected, int shift = 0, Point offset = default(Point)) { using InputOutputArray inputOutputArray = img.GetInputOutputArray(); using InputArray inputArray = points.GetInputArray(); cveFillPoly(inputOutputArray, inputArray, ref color, lineType, shift, ref offset); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveFillPoly(IntPtr img, IntPtr pts, ref MCvScalar color, LineType lineType, int shift, ref Point offset); public static void PutText(IInputOutputArray img, string text, Point org, FontFace fontFace, double fontScale, MCvScalar color, int thickness = 1, LineType lineType = LineType.EightConnected, bool bottomLeftOrigin = false) { using CvString cvString = new CvString(text); using InputOutputArray inputOutputArray = img.GetInputOutputArray(); cvePutText(inputOutputArray, cvString, ref org, fontFace, fontScale, ref color, thickness, lineType, bottomLeftOrigin); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cvePutText(IntPtr img, IntPtr text, ref Point org, FontFace fontFace, double fontScale, ref MCvScalar color, int thickness, LineType lineType, [MarshalAs(UnmanagedType.U1)] bool bottomLeftOrigin); public static Size GetTextSize(string text, FontFace fontFace, double fontScale, int thickness, ref int baseLine) { Size size = default(Size); using CvString cvString = new CvString(text); cveGetTextSize(cvString, fontFace, fontScale, thickness, ref baseLine, ref size); return size; } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveGetTextSize(IntPtr text, FontFace fontFace, double fontScale, int thickness, ref int baseLine, ref Size size); internal static void MinMax(IInputArray arr, out double[] minValues, out double[] maxValues, out Point[] minLocations, out Point[] maxLocations) { using InputArray inputArray = arr.GetInputArray(); int channels = inputArray.GetChannels(); minValues = new double[channels]; maxValues = new double[channels]; minLocations = new Point[channels]; maxLocations = new Point[channels]; double minVal = 0.0; double maxVal = 0.0; Point minLoc = default(Point); Point maxLoc = default(Point); if (channels == 1) { if (inputArray.IsUMat) { using Mat arr2 = inputArray.GetMat(); MinMaxLoc(arr2, ref minVal, ref maxVal, ref minLoc, ref maxLoc); } else { MinMaxLoc(arr, ref minVal, ref maxVal, ref minLoc, ref maxLoc); } minValues[0] = minVal; maxValues[0] = maxVal; minLocations[0] = minLoc; maxLocations[0] = maxLoc; return; } using Mat mat = new Mat(); for (int i = 0; i < channels; i++) { ExtractChannel(arr, mat, i); MinMaxLoc(mat, ref minVal, ref maxVal, ref minLoc, ref maxLoc); minValues[i] = minVal; maxValues[i] = maxVal; minLocations[i] = minLoc; maxLocations[i] = maxLoc; } } public static void MinMaxLoc(IInputArray arr, ref double minVal, ref double maxVal, ref Point minLoc, ref Point maxLoc, IInputArray mask = null) { using InputArray inputArray = arr.GetInputArray(); using InputArray inputArray2 = ((mask == null) ? InputArray.GetEmpty() : mask.GetInputArray()); cveMinMaxLoc(inputArray, ref minVal, ref maxVal, ref minLoc, ref maxLoc, inputArray2); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveMinMaxLoc(IntPtr arr, ref double minVal, ref double maxVal, ref Point minLoc, ref Point maxLoc, IntPtr mask); public static void CopyMakeBorder(IInputArray src, IOutputArray dst, int top, int bottom, int left, int right, BorderType bordertype, MCvScalar value = default(MCvScalar)) { using InputArray inputArray = src.GetInputArray(); using OutputArray outputArray = dst.GetOutputArray(); cveCopyMakeBorder(inputArray, outputArray, top, bottom, left, right, bordertype, ref value); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveCopyMakeBorder(IntPtr src, IntPtr dst, int top, int bottom, int left, int right, BorderType bordertype, ref MCvScalar value); public static MCvScalar cvGet1D(IntPtr arr, int idx0) { MCvScalar value = default(MCvScalar); cveGet1D(arr, idx0, ref value); return value; } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveGet1D(IntPtr arr, int idx0, ref MCvScalar value); public static MCvScalar cvGet2D(IntPtr arr, int idx0, int idx1) { MCvScalar value = default(MCvScalar); cveGet2D(arr, idx0, idx1, ref value); return value; } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveGet2D(IntPtr arr, int idx0, int idx1, ref MCvScalar value); public static MCvScalar cvGet3D(IntPtr arr, int idx0, int idx1, int idx2) { MCvScalar value = default(MCvScalar); cveGet3D(arr, idx0, idx1, idx2, ref value); return value; } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveGet3D(IntPtr arr, int idx0, int idx1, int idx2, ref MCvScalar value); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl, EntryPoint = "cveGetReal1D")] public static extern double cvGetReal1D(IntPtr arr, int idx0); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl, EntryPoint = "cveGetReal2D")] public static extern double cvGetReal2D(IntPtr arr, int idx0, int idx1); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl, EntryPoint = "cveGetReal3D")] public static extern double cvGetReal3D(IntPtr arr, int idx0, int idx1, int idx2); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.U1)] private static extern bool cveUseOptimized(); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveSetUseOptimized([MarshalAs(UnmanagedType.U1)] bool onoff); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.U1)] private static extern bool cveHaveOpenVX(); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.U1)] private static extern bool cveUseOpenVX(); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveSetUseOpenVX([MarshalAs(UnmanagedType.U1)] bool flag); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveGetBuildInformation(IntPtr buildInformation); public static void Randn(IInputOutputArray dst, MCvScalar mean, MCvScalar stddev) { using ScalarArray mean2 = new ScalarArray(mean); using ScalarArray stddev2 = new ScalarArray(stddev); Randn(dst, mean2, stddev2); } public static void Randn(IInputOutputArray dst, IInputArray mean, IInputArray stddev) { using InputOutputArray inputOutputArray = dst.GetInputOutputArray(); using InputArray inputArray = mean.GetInputArray(); using InputArray inputArray2 = stddev.GetInputArray(); cveRandn(inputOutputArray, inputArray, inputArray2); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveRandn(IntPtr dst, IntPtr mean, IntPtr stddev); public static void Randu(IInputOutputArray dst, MCvScalar low, MCvScalar high) { using ScalarArray low2 = new ScalarArray(low); using ScalarArray high2 = new ScalarArray(high); Randu(dst, low2, high2); } public static void Randu(IInputOutputArray dst, IInputArray low, IInputArray high) { using InputOutputArray inputOutputArray = dst.GetInputOutputArray(); using InputArray inputArray = low.GetInputArray(); using InputArray inputArray2 = high.GetInputArray(); cveRandu(inputOutputArray, inputArray, inputArray2); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveRandu(IntPtr dst, IntPtr low, IntPtr high); public static void Eigen(IInputArray src, IOutputArray eigenValues, IOutputArray eigenVectors = null) { using InputArray inputArray = src.GetInputArray(); using OutputArray outputArray = eigenValues.GetOutputArray(); using OutputArray outputArray2 = ((eigenVectors == null) ? OutputArray.GetEmpty() : eigenVectors.GetOutputArray()); cveEigen(inputArray, outputArray, outputArray2); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveEigen(IntPtr src, IntPtr eigenValues, IntPtr eigenVectors); public static void Normalize(IInputArray src, IOutputArray dst, double alpha = 1.0, double beta = 0.0, NormType normType = NormType.L2, DepthType dType = DepthType.Default, IInputArray mask = null) { using InputArray inputArray = src.GetInputArray(); using OutputArray outputArray = dst.GetOutputArray(); using InputArray inputArray2 = ((mask == null) ? InputArray.GetEmpty() : mask.GetInputArray()); cveNormalize(inputArray, outputArray, alpha, beta, normType, dType, inputArray2); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveNormalize(IntPtr src, IntPtr dst, double alpha, double beta, NormType normType, DepthType dType, IntPtr mask); public static void Gemm(IInputArray src1, IInputArray src2, double alpha, IInputArray src3, double beta, IOutputArray dst, GemmType tAbc = GemmType.Default) { using InputArray inputArray = src1.GetInputArray(); using InputArray inputArray2 = src2.GetInputArray(); using InputArray inputArray3 = ((src3 == null) ? InputArray.GetEmpty() : src3.GetInputArray()); using OutputArray outputArray = dst.GetOutputArray(); cveGemm(inputArray, inputArray2, alpha, inputArray3, beta, outputArray, tAbc); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveGemm(IntPtr src1, IntPtr src2, double alpha, IntPtr src3, double beta, IntPtr dst, GemmType tAbc); public static void Transform(IInputArray src, IOutputArray dst, IInputArray m) { using InputArray inputArray = src.GetInputArray(); using OutputArray outputArray = dst.GetOutputArray(); using InputArray inputArray2 = m.GetInputArray(); cveTransform(inputArray, outputArray, inputArray2); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveTransform(IntPtr src, IntPtr dst, IntPtr transmat); public static PointF[] PerspectiveTransform(PointF[] src, IInputArray mat) { PointF[] array = new PointF[src.Length]; GCHandle gCHandle = GCHandle.Alloc(src, GCHandleType.Pinned); GCHandle gCHandle2 = GCHandle.Alloc(array, GCHandleType.Pinned); using (Matrix src2 = new Matrix(src.Length, 1, 2, gCHandle.AddrOfPinnedObject(), 0)) { using Mat dst = new Mat(array.Length, 1, DepthType.Cv32F, 2, gCHandle2.AddrOfPinnedObject(), 8); PerspectiveTransform(src2, dst, mat); } gCHandle.Free(); gCHandle2.Free(); return array; } public static void PerspectiveTransform(IInputArray src, IOutputArray dst, IInputArray mat) { using InputArray inputArray = src.GetInputArray(); using OutputArray outputArray = dst.GetOutputArray(); using InputArray inputArray2 = mat.GetInputArray(); cvePerspectiveTransform(inputArray, outputArray, inputArray2); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cvePerspectiveTransform(IntPtr src, IntPtr dst, IntPtr mat); public static void MulTransposed(IInputArray src, IOutputArray dst, bool aTa, IInputArray delta = null, double scale = 1.0, DepthType dtype = DepthType.Default) { using InputArray inputArray = src.GetInputArray(); using OutputArray outputArray = dst.GetOutputArray(); using InputArray inputArray2 = ((delta == null) ? InputArray.GetEmpty() : delta.GetInputArray()); cveMulTransposed(inputArray, outputArray, aTa, inputArray2, scale, dtype); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveMulTransposed(IntPtr src, IntPtr dst, [MarshalAs(UnmanagedType.U1)] bool aTa, IntPtr delta, double scale, DepthType dtype); public static MCvScalar Trace(IInputArray mat) { MCvScalar result = default(MCvScalar); using InputArray inputArray = mat.GetInputArray(); cveTrace(inputArray, ref result); return result; } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveTrace(IntPtr mat, ref MCvScalar result); public static void Transpose(IInputArray src, IOutputArray dst) { using InputArray inputArray = src.GetInputArray(); using OutputArray outputArray = dst.GetOutputArray(); cveTranspose(inputArray, outputArray); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveTranspose(IntPtr src, IntPtr dst); public static double Determinant(IInputArray mat) { using InputArray inputArray = mat.GetInputArray(); return cveDeterminant(inputArray); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern double cveDeterminant(IntPtr mat); public static double Invert(IInputArray src, IOutputArray dst, DecompMethod method) { using InputArray inputArray = src.GetInputArray(); using OutputArray outputArray = dst.GetOutputArray(); return cveInvert(inputArray, outputArray, method); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern double cveInvert(IntPtr src, IntPtr dst, DecompMethod method); public static void SVDecomp(IInputArray src, IOutputArray w, IOutputArray u, IOutputArray v, SvdFlag flags) { using InputArray inputArray = src.GetInputArray(); using OutputArray outputArray = w.GetOutputArray(); using OutputArray outputArray2 = u.GetOutputArray(); using OutputArray outputArray3 = v.GetOutputArray(); cveSVDecomp(inputArray, outputArray, outputArray2, outputArray3, flags); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveSVDecomp(IntPtr src, IntPtr w, IntPtr u, IntPtr v, SvdFlag flags); public static void SVBackSubst(IInputArray w, IInputArray u, IInputArray vt, IInputArray rhs, IOutputArray dst) { using InputArray inputArray = w.GetInputArray(); using InputArray inputArray2 = u.GetInputArray(); using InputArray inputArray3 = vt.GetInputArray(); using InputArray inputArray4 = rhs.GetInputArray(); using OutputArray outputArray = dst.GetOutputArray(); cveSVBackSubst(inputArray, inputArray2, inputArray3, inputArray4, outputArray); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveSVBackSubst(IntPtr w, IntPtr u, IntPtr vt, IntPtr rhs, IntPtr dst); public static void CalcCovarMatrix(IInputArray samples, IOutputArray covar, IInputOutputArray mean, CovarMethod flags, DepthType ctype = DepthType.Cv64F) { using InputArray inputArray = samples.GetInputArray(); using OutputArray outputArray = covar.GetOutputArray(); using InputOutputArray inputOutputArray = mean.GetInputOutputArray(); cveCalcCovarMatrix(inputArray, outputArray, inputOutputArray, flags, ctype); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveCalcCovarMatrix(IntPtr samples, IntPtr covar, IntPtr mean, CovarMethod flags, DepthType ctype); public static double Mahalanobis(IInputArray v1, IInputArray v2, IInputArray iconvar) { using InputArray inputArray = v1.GetInputArray(); using InputArray inputArray2 = v2.GetInputArray(); using InputArray inputArray3 = iconvar.GetInputArray(); return cveMahalanobis(inputArray, inputArray2, inputArray3); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern double cveMahalanobis(IntPtr v1, IntPtr v2, IntPtr iconvar); public static void PCACompute(IInputArray data, IInputOutputArray mean, IOutputArray eigenvectors, int maxComponents = 0) { using InputArray inputArray = data.GetInputArray(); using InputOutputArray inputOutputArray = mean.GetInputOutputArray(); using OutputArray outputArray = eigenvectors.GetOutputArray(); cvePCACompute1(inputArray, inputOutputArray, outputArray, maxComponents); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cvePCACompute1(IntPtr data, IntPtr mean, IntPtr eigenvectors, int maxComponents); public static void PCACompute(IInputArray data, IInputOutputArray mean, IOutputArray eigenvectors, double retainedVariance) { using InputArray inputArray = data.GetInputArray(); using InputOutputArray inputOutputArray = mean.GetInputOutputArray(); using OutputArray outputArray = eigenvectors.GetOutputArray(); cvePCACompute2(inputArray, inputOutputArray, outputArray, retainedVariance); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cvePCACompute2(IntPtr data, IntPtr mean, IntPtr eigenvectors, double retainedVariance); public static void PCAProject(IInputArray data, IInputArray mean, IInputArray eigenvectors, IOutputArray result) { using InputArray inputArray = data.GetInputArray(); using InputArray inputArray2 = mean.GetInputArray(); using InputArray inputArray3 = eigenvectors.GetInputArray(); using OutputArray outputArray = result.GetOutputArray(); cvePCAProject(inputArray, inputArray2, inputArray3, outputArray); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cvePCAProject(IntPtr data, IntPtr mean, IntPtr eigenvectors, IntPtr result); public static void PCABackProject(IInputArray data, IInputArray mean, IInputArray eigenvectors, IOutputArray result) { using InputArray inputArray = data.GetInputArray(); using InputArray inputArray2 = mean.GetInputArray(); using InputArray inputArray3 = eigenvectors.GetInputArray(); using OutputArray outputArray = result.GetOutputArray(); cvePCABackProject(inputArray, inputArray2, inputArray3, outputArray); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cvePCABackProject(IntPtr data, IntPtr mean, IntPtr eigenvectors, IntPtr result); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl, EntryPoint = "cveGetRawData")] public static extern void cvGetRawData(IntPtr arr, out IntPtr data, out int step, out Size roiSize); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl, EntryPoint = "cveGetMat")] public static extern IntPtr cvGetMat(IntPtr arr, IntPtr header, out int coi, int allowNd); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl, EntryPoint = "cveGetImage")] public static extern IntPtr cvGetImage(IntPtr arr, IntPtr imageHeader); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl, EntryPoint = "cveCheckArr")] public static extern int cvCheckArr(IntPtr arr, CheckType flags, double minVal, double maxVal); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern int cveGetNumThreads(); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveSetNumThreads(int threadsCount); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern int cveGetThreadNum(); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern int cveGetNumberOfCPUs(); public static bool SetParallelForBackend(string backendName, bool propagateNumThreads = true) { using CvString cvString = new CvString(backendName); return cveSetParallelForBackend(cvString, propagateNumThreads); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.U1)] private static extern bool cveSetParallelForBackend(IntPtr backendName, bool propagateNumThreads); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveGetParallelBackends(IntPtr backendNames); public static void Compare(IInputArray src1, IInputArray src2, IOutputArray dst, CmpType cmpOp) { using InputArray inputArray = src1.GetInputArray(); using InputArray inputArray2 = src2.GetInputArray(); using OutputArray outputArray = dst.GetOutputArray(); cveCompare(inputArray, inputArray2, outputArray, cmpOp); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveCompare(IntPtr src1, IntPtr src2, IntPtr dst, CmpType cmpOp); public static Mat CvArrToMat(IntPtr arr, bool copyData = false, bool allowND = true, int coiMode = 0) { return new Mat(cveArrToMat(arr, copyData, allowND, coiMode), needDispose: true); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern IntPtr cveArrToMat(IntPtr cvArray, [MarshalAs(UnmanagedType.U1)] bool copyData, [MarshalAs(UnmanagedType.U1)] bool allowND, int coiMode); public static void HConcat(IInputArray src1, IInputArray src2, IOutputArray dst) { using InputArray inputArray = src1.GetInputArray(); using InputArray inputArray2 = src2.GetInputArray(); using OutputArray outputArray = dst.GetOutputArray(); cveHConcat(inputArray, inputArray2, outputArray); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveHConcat(IntPtr src1, IntPtr src2, IntPtr dst); public static void HConcat(Mat[] srcs, IOutputArray dst) { using VectorOfMat srcs2 = new VectorOfMat(srcs); HConcat(srcs2, dst); } public static void HConcat(IInputArrayOfArrays srcs, IOutputArray dst) { using InputArray inputArray = srcs.GetInputArray(); using OutputArray outputArray = dst.GetOutputArray(); cveHConcat2(inputArray, outputArray); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveHConcat2(IntPtr src, IntPtr dst); public static void VConcat(IInputArray src1, IInputArray src2, IOutputArray dst) { using InputArray inputArray = src1.GetInputArray(); using InputArray inputArray2 = src2.GetInputArray(); using OutputArray outputArray = dst.GetOutputArray(); cveVConcat(inputArray, inputArray2, outputArray); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveVConcat(IntPtr src1, IntPtr src2, IntPtr dst); public static void VConcat(Mat[] srcs, IOutputArray dst) { using VectorOfMat srcs2 = new VectorOfMat(srcs); VConcat(srcs2, dst); } public static void VConcat(IInputArrayOfArrays srcs, IOutputArray dst) { using InputArray inputArray = srcs.GetInputArray(); using OutputArray outputArray = dst.GetOutputArray(); cveVConcat2(inputArray, outputArray); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveVConcat2(IntPtr src, IntPtr dst); public static void Swap(Mat m1, Mat m2) { cveSwapMat(m1, m2); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveSwapMat(IntPtr mat1, IntPtr mat2); public static void Swap(UMat m1, UMat m2) { cveSwapUMat(m1, m2); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveSwapUMat(IntPtr mat1, IntPtr mat2); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.U1)] private static extern bool cveHaveOpenCL(); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.U1)] private static extern bool cveUseOpenCL(); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveSetUseOpenCL([MarshalAs(UnmanagedType.U1)] bool flag); public static void OclFinish() { cveOclFinish(); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveOclFinish(); public static string OclGetPlatformsSummary() { if (!HaveOpenCL) { return "OpenCL not available."; } Device @default = Device.Default; StringBuilder stringBuilder = new StringBuilder(); using VectorOfOclPlatformInfo vectorOfOclPlatformInfo = OclInvoke.GetPlatformsInfo(); if (vectorOfOclPlatformInfo.Size > 0) { for (int i = 0; i < vectorOfOclPlatformInfo.Size; i++) { PlatformInfo platformInfo = vectorOfOclPlatformInfo[i]; stringBuilder.Append($"Platform {i}: {platformInfo.ToString()}{Environment.NewLine}"); for (int j = 0; j < platformInfo.DeviceNumber; j++) { Device device = platformInfo.GetDevice(j); stringBuilder.Append(string.Format(" Device {0} {2}: {1} {3}", j, device.ToString(), device.NativeDevicePointer.Equals((object?)(nint)@default.NativeDevicePointer) ? "(Default)" : string.Empty, Environment.NewLine)); } } } return stringBuilder.ToString(); } public static void OclSetDefaultDevice(string deviceName) { using (VectorOfOclPlatformInfo vectorOfOclPlatformInfo = OclInvoke.GetPlatformsInfo()) { if (vectorOfOclPlatformInfo.Size > 0) { for (int i = 0; i < vectorOfOclPlatformInfo.Size; i++) { PlatformInfo platformInfo = vectorOfOclPlatformInfo[i]; for (int j = 0; j < platformInfo.DeviceNumber; j++) { Device device = platformInfo.GetDevice(j); if (device.Name.Equals(deviceName)) { Device.Default.Set(device.NativeDevicePointer); return; } } } } } throw new Exception($"OpenCL device with name '{deviceName}' is not found."); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveGetRangeAll(ref Emgu.CV.Structure.Range range); public static double Kmeans(IInputArray data, int k, IOutputArray bestLabels, MCvTermCriteria termcrit, int attempts, KMeansInitType flags, IOutputArray centers = null) { using InputArray inputArray = data.GetInputArray(); using OutputArray outputArray = bestLabels.GetOutputArray(); using OutputArray outputArray2 = ((centers == null) ? OutputArray.GetEmpty() : centers.GetOutputArray()); return cveKmeans(inputArray, k, outputArray, ref termcrit, attempts, flags, outputArray2); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern double cveKmeans(IntPtr data, int k, IntPtr bestLabels, ref MCvTermCriteria termcrit, int attempts, KMeansInitType flags, IntPtr centers); public static void GrabCut(IInputArray img, IInputOutputArray mask, Rectangle rect, IInputOutputArray bgdModel, IInputOutputArray fgdModel, int iterCount, GrabcutInitType type) { using InputArray inputArray = img.GetInputArray(); using InputOutputArray inputOutputArray = ((mask == null) ? InputOutputArray.GetEmpty() : mask.GetInputOutputArray()); using InputOutputArray inputOutputArray2 = bgdModel.GetInputOutputArray(); using InputOutputArray inputOutputArray3 = fgdModel.GetInputOutputArray(); cveGrabCut(inputArray, inputOutputArray, ref rect, inputOutputArray2, inputOutputArray3, iterCount, type); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveGrabCut(IntPtr img, IntPtr mask, ref Rectangle rect, IntPtr bgdModel, IntPtr fgdModel, int iterCount, GrabcutInitType type); public static void Sqrt(IInputArray src, IOutputArray dst) { using InputArray inputArray = src.GetInputArray(); using OutputArray outputArray = dst.GetOutputArray(); cveSqrt(inputArray, outputArray); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveSqrt(IntPtr src, IntPtr dst); public static void ApplyColorMap(IInputArray src, IOutputArray dst, ColorMapType colorMapType) { using InputArray inputArray = src.GetInputArray(); using OutputArray outputArray = dst.GetOutputArray(); cveApplyColorMap1(inputArray, outputArray, colorMapType); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveApplyColorMap1(IntPtr src, IntPtr dst, ColorMapType colorMapType); public static void ApplyColorMap(IInputArray src, IOutputArray dst, IInputArray userColorMap) { using InputArray inputArray = src.GetInputArray(); using OutputArray outputArray = dst.GetOutputArray(); using InputArray inputArray2 = userColorMap.GetInputArray(); cveApplyColorMap2(inputArray, outputArray, inputArray2); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveApplyColorMap2(IntPtr src, IntPtr dst, IntPtr userColorMap); public static bool CheckRange(IInputArray arr, bool quiet, ref Point pos, double minVal, double maxVal) { using InputArray inputArray = arr.GetInputArray(); return cveCheckRange(inputArray, quiet, ref pos, minVal, maxVal); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.U1)] private static extern bool cveCheckRange(IntPtr arr, [MarshalAs(UnmanagedType.U1)] bool quiet, ref Point pos, double minVal, double maxVal); public static void PatchNaNs(IInputOutputArray a, double val = 0.0) { using InputOutputArray inputOutputArray = a.GetInputOutputArray(); cvePatchNaNs(inputOutputArray, val); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cvePatchNaNs(IntPtr a, double val); public static int EstimateAffine3D(MCvPoint3D32f[] src, MCvPoint3D32f[] dst, out Matrix estimate, out byte[] inliers, double ransacThreshold, double confidence) { GCHandle gCHandle = GCHandle.Alloc(src, GCHandleType.Pinned); GCHandle gCHandle2 = GCHandle.Alloc(dst, GCHandleType.Pinned); estimate = new Matrix(3, 4); int num = Toolbox.SizeOf(); int result; using (Matrix src2 = new Matrix(1, src.Length, 3, gCHandle.AddrOfPinnedObject(), num * src.Length)) { using Matrix dst2 = new Matrix(1, dst.Length, 3, gCHandle2.AddrOfPinnedObject(), num * dst.Length); using VectorOfByte vectorOfByte = new VectorOfByte(); result = EstimateAffine3D(src2, dst2, estimate, vectorOfByte, ransacThreshold, confidence); inliers = vectorOfByte.ToArray(); } gCHandle.Free(); gCHandle2.Free(); return result; } public static int EstimateAffine3D(IInputArray src, IInputArray dst, IOutputArray affineEstimate, IOutputArray inliers, double ransacThreshold = 3.0, double confidence = 0.99) { using InputArray inputArray = src.GetInputArray(); using InputArray inputArray2 = dst.GetInputArray(); using OutputArray outputArray = affineEstimate.GetOutputArray(); using OutputArray outputArray2 = inliers.GetOutputArray(); return cveEstimateAffine3D(inputArray, inputArray2, outputArray, outputArray2, ransacThreshold, confidence); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int cveEstimateAffine3D(IntPtr src, IntPtr dst, IntPtr affineEstimate, IntPtr inliers, double ransacThreshold, double confidence); public static void MinMaxIdx(IInputArray src, out double minVal, out double maxVal, int[] minIdx, int[] maxIdx, IInputArray mask = null) { GCHandle gCHandle = GCHandle.Alloc(minIdx, GCHandleType.Pinned); GCHandle gCHandle2 = GCHandle.Alloc(maxIdx, GCHandleType.Pinned); minVal = 0.0; maxVal = 0.0; using (InputArray inputArray = src.GetInputArray()) { using InputArray inputArray2 = ((mask == null) ? InputArray.GetEmpty() : mask.GetInputArray()); cveMinMaxIdx(inputArray, ref minVal, ref maxVal, gCHandle.AddrOfPinnedObject(), gCHandle2.AddrOfPinnedObject(), inputArray2); } gCHandle.Free(); gCHandle2.Free(); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveMinMaxIdx(IntPtr src, ref double minVal, ref double maxVal, IntPtr minIdx, IntPtr maxIdx, IntPtr mask); public static void Filter2D(IInputArray src, IOutputArray dst, IInputArray kernel, Point anchor, double delta = 0.0, BorderType borderType = BorderType.Reflect101) { using InputArray inputArray = src.GetInputArray(); using OutputArray outputArray = dst.GetOutputArray(); using InputArray inputArray2 = kernel.GetInputArray(); cveFilter2D(inputArray, outputArray, inputArray2, ref anchor, delta, borderType); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveFilter2D(IntPtr src, IntPtr dst, IntPtr kernel, ref Point anchor, double delta, BorderType borderType); public static void SepFilter2D(IInputArray src, IOutputArray dst, DepthType ddepth, IInputArray kernelX, IInputArray kernelY, Point anchor, double delta = 0.0, BorderType borderType = BorderType.Reflect101) { using InputArray inputArray = src.GetInputArray(); using OutputArray outputArray = dst.GetOutputArray(); using InputArray inputArray2 = kernelX.GetInputArray(); using InputArray inputArray3 = kernelY.GetInputArray(); cveSepFilter2D(inputArray, outputArray, ddepth, inputArray2, inputArray3, ref anchor, delta, borderType); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveSepFilter2D(IntPtr src, IntPtr dst, DepthType ddepth, IntPtr kernelX, IntPtr kernelY, ref Point anchor, double delta, BorderType borderType); public static void BlendLinear(IInputArray src1, IInputArray src2, IInputArray weights1, IInputArray weights2, IOutputArray dst) { using InputArray inputArray = src1.GetInputArray(); using InputArray inputArray2 = src2.GetInputArray(); using InputArray inputArray3 = weights1.GetInputArray(); using InputArray inputArray4 = weights2.GetInputArray(); using OutputArray outputArray = dst.GetOutputArray(); cveBlendLinear(inputArray, inputArray2, inputArray3, inputArray4, outputArray); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveBlendLinear(IntPtr src1, IntPtr src2, IntPtr weights1, IntPtr weights2, IntPtr dst); public static void CLAHE(IInputArray src, double clipLimit, Size tileGridSize, IOutputArray dst) { using InputArray inputArray = src.GetInputArray(); using OutputArray outputArray = dst.GetOutputArray(); cveCLAHE(inputArray, clipLimit, ref tileGridSize, outputArray); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveCLAHE(IntPtr srcArr, double clipLimit, ref Size tileGridSize, IntPtr dstArr); public static CvStructSizes GetCvStructSizes() { CvStructSizes sizes = default(CvStructSizes); cveGetCvStructSizes(ref sizes); return sizes; } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveGetCvStructSizes(ref CvStructSizes sizes); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveGetConfigDict(IntPtr names, IntPtr values); public static PointF[] FindCirclesGrid(Image image, Size patternSize, CalibCgType flags, Feature2D featureDetector) { using VectorOfPointF vectorOfPointF = new VectorOfPointF(); return FindCirclesGrid(image, patternSize, vectorOfPointF, flags, featureDetector) ? vectorOfPointF.ToArray() : null; } public static bool FindCirclesGrid(IInputArray image, Size patternSize, IOutputArray centers, CalibCgType flags, Feature2D featureDetector) { using InputArray inputArray = image.GetInputArray(); using OutputArray outputArray = centers.GetOutputArray(); return cveFindCirclesGrid(inputArray, ref patternSize, outputArray, flags, featureDetector.Feature2DPtr); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.U1)] private static extern bool cveFindCirclesGrid(IntPtr image, ref Size patternSize, IntPtr centers, CalibCgType flags, IntPtr blobDetector); public static void NamedWindow(string name, WindowFlags flags = WindowFlags.AutoSize) { using CvString cvString = new CvString(name); cveNamedWindow(cvString, flags); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveNamedWindow(IntPtr name, WindowFlags flags); public static void SetWindowProperty(string name, WindowPropertyFlags propId, double propValue) { using CvString cvString = new CvString(name); cveSetWindowProperty(cvString, propId, propValue); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveSetWindowProperty(IntPtr name, WindowPropertyFlags propId, double propValue); public static double GetWindowProperty(string name, WindowPropertyFlags propId) { using CvString cvString = new CvString(name); return cveGetWindowProperty(cvString, propId); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern double cveGetWindowProperty(IntPtr winname, WindowPropertyFlags propId); public static void SetWindowTitle(string winname, string title) { using CvString cvString = new CvString(winname); using CvString cvString2 = new CvString(title); cveSetWindowTitle(cvString, cvString2); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveSetWindowTitle(IntPtr winname, IntPtr title); public static int WaitKey(int delay = 0) { return cveWaitKey(delay); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern int cveWaitKey(int delay); public static int PollKey() { return cvePollKey(); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern int cvePollKey(); public static void Imshow(string name, IInputArray image) { using CvString cvString = new CvString(name); using InputArray inputArray = image.GetInputArray(); cveImshow(cvString, inputArray); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveImshow(IntPtr name, IntPtr image); public static void DestroyWindow(string name) { using CvString cvString = new CvString(name); cveDestroyWindow(cvString); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveDestroyWindow(IntPtr name); public static void DestroyAllWindows() { cveDestroyAllWindows(); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveDestroyAllWindows(); public static Rectangle SelectROI(string windowName, IInputArray img, bool showCrosshair = true, bool fromCenter = false) { Rectangle roi = default(Rectangle); using CvString cvString = new CvString(windowName); using InputArray inputArray = img.GetInputArray(); cveSelectROI(cvString, inputArray, showCrosshair, fromCenter, ref roi); return roi; } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveSelectROI(IntPtr windowName, IntPtr img, [MarshalAs(UnmanagedType.U1)] bool showCrosshair, [MarshalAs(UnmanagedType.U1)] bool fromCenter, ref Rectangle roi); public static Rectangle[] SelectROIs(string windowName, IInputArray img, bool showCrosshair = true, bool fromCenter = false) { using VectorOfRect vectorOfRect = new VectorOfRect(); using CvString cvString = new CvString(windowName); using InputArray inputArray = img.GetInputArray(); cveSelectROIs(cvString, inputArray, vectorOfRect, showCrosshair, fromCenter); return vectorOfRect.ToArray(); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveSelectROIs(IntPtr windowName, IntPtr img, IntPtr boundingBoxs, [MarshalAs(UnmanagedType.U1)] bool showCrosshair, [MarshalAs(UnmanagedType.U1)] bool fromCenter); public static Mat Imread(string filename, ImreadModes loadType = ImreadModes.Color) { return new Mat(filename, loadType); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveImread(IntPtr filename, ImreadModes loadType, IntPtr result); public static bool HaveImageReader(string fileName) { using CvString cvString = new CvString(fileName); return cveHaveImageReader(cvString); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.U1)] internal static extern bool cveHaveImageReader(IntPtr filename); public static bool HaveImageWriter(string fileName) { using CvString cvString = new CvString(fileName); return cveHaveImageWriter(cvString); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.U1)] internal static extern bool cveHaveImageWriter(IntPtr filename); public static bool Imwritemulti(string filename, IInputArrayOfArrays images, params KeyValuePair[] parameters) { using CvString cvString = new CvString(filename); using VectorOfInt vectorOfInt = new VectorOfInt(); using InputArray inputArray = images.GetInputArray(); PushParameters(vectorOfInt, parameters); return cveImwritemulti(cvString, inputArray, vectorOfInt); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.U1)] internal static extern bool cveImwritemulti(IntPtr filename, IntPtr mats, IntPtr flags); public static Mat[] Imreadmulti(string filename, ImreadModes flags = ImreadModes.AnyColor) { using VectorOfMat vectorOfMat = new VectorOfMat(); using CvString cvString = new CvString(filename); if (!cveImreadmulti(cvString, vectorOfMat, flags)) { return null; } Mat[] array = new Mat[vectorOfMat.Size]; for (int i = 0; i < array.Length; i++) { Mat mat = new Mat(); Swap(mat, vectorOfMat[i]); array[i] = mat; } return array; } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.U1)] internal static extern bool cveImreadmulti(IntPtr filename, IntPtr mats, ImreadModes flags); private static void PushParameters(VectorOfInt vec, KeyValuePair[] parameters) { if (parameters != null && parameters.Length != 0) { for (int i = 0; i < parameters.Length; i++) { KeyValuePair keyValuePair = parameters[i]; vec.Push(new int[2] { (int)keyValuePair.Key, keyValuePair.Value }); } } } public static bool Imwrite(string filename, IInputArray image, params KeyValuePair[] parameters) { using VectorOfInt vectorOfInt = new VectorOfInt(); PushParameters(vectorOfInt, parameters); using CvString cvString = new CvString(filename); if (cvString.Length != filename.Length && Platform.OperationSystem != Platform.OS.MacOS && Platform.OperationSystem != Platform.OS.Linux) { FileInfo fileInfo = new FileInfo(filename); using VectorOfByte vectorOfByte = new VectorOfByte(); Imencode(fileInfo.Extension, image, vectorOfByte, parameters); byte[] bytes = vectorOfByte.ToArray(); File.WriteAllBytes(filename, bytes); return true; } using InputArray inputArray = image.GetInputArray(); return cveImwrite(cvString, inputArray, vectorOfInt); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.U1)] private static extern bool cveImwrite(IntPtr filename, IntPtr image, IntPtr parameters); public static void Imdecode(byte[] buf, ImreadModes loadType, Mat dst) { using VectorOfByte buf2 = new VectorOfByte(buf); Imdecode(buf2, loadType, dst); } public static void Imdecode(IInputArray buf, ImreadModes loadType, Mat dst) { using InputArray inputArray = buf.GetInputArray(); cveImdecode(inputArray, loadType, dst); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveImdecode(IntPtr buf, ImreadModes loadType, IntPtr dst); public static byte[] Imencode(string ext, IInputArray image, params KeyValuePair[] parameters) { using VectorOfByte vectorOfByte = new VectorOfByte(); if (!Imencode(ext, image, vectorOfByte, parameters)) { return null; } return vectorOfByte.ToArray(); } public static bool Imencode(string ext, IInputArray image, VectorOfByte buf, params KeyValuePair[] parameters) { using CvString cvString = new CvString(ext); using VectorOfInt vectorOfInt = new VectorOfInt(); PushParameters(vectorOfInt, parameters); using InputArray inputArray = image.GetInputArray(); return cveImencode(cvString, inputArray, buf, vectorOfInt); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.U1)] private static extern bool cveImencode(IntPtr ext, IntPtr image, IntPtr buffer, IntPtr parameters); public static void GetRectSubPix(IInputArray image, Size patchSize, PointF center, IOutputArray patch, DepthType patchType = DepthType.Default) { using InputArray inputArray = image.GetInputArray(); using OutputArray outputArray = patch.GetOutputArray(); cveGetRectSubPix(inputArray, ref patchSize, ref center, outputArray, patchType); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveGetRectSubPix(IntPtr image, ref Size patchSize, ref PointF center, IntPtr patch, DepthType patchType); public static void Resize(IInputArray src, IOutputArray dst, Size dsize, double fx = 0.0, double fy = 0.0, Inter interpolation = Inter.Linear) { using InputArray inputArray = src.GetInputArray(); using OutputArray outputArray = dst.GetOutputArray(); cveResize(inputArray, outputArray, ref dsize, fx, fy, interpolation); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveResize(IntPtr src, IntPtr dst, ref Size dsize, double fx, double fy, Inter interpolation); public static void ResizeForFrame(IInputArray src, IOutputArray dst, Size frameSize, Inter interpolationMethod = Inter.Linear, bool scaleDownOnly = true) { using InputArray inputArray = src.GetInputArray(); Size size = inputArray.GetSize(); if (scaleDownOnly && size.Width <= frameSize.Width && size.Height <= frameSize.Height) { inputArray.CopyTo(dst); } Size dsize = ComputeScalePreservingSize(inputArray.GetSize(), frameSize); Resize(src, dst, dsize, 0.0, 0.0, interpolationMethod); } private static Size ComputeScalePreservingSize(Size current, Size max) { double num = Math.Min((double)max.Width / (double)current.Width, (double)max.Height / (double)current.Height); return new Size((int)((double)current.Width * num), (int)((double)current.Height * num)); } public static void WarpAffine(IInputArray src, IOutputArray dst, IInputArray mapMatrix, Size dsize, Inter interMethod = Inter.Linear, Warp warpMethod = Warp.Default, BorderType borderMode = BorderType.Constant, MCvScalar borderValue = default(MCvScalar)) { using InputArray inputArray = src.GetInputArray(); using OutputArray outputArray = dst.GetOutputArray(); using InputArray inputArray2 = mapMatrix.GetInputArray(); cveWarpAffine(inputArray, outputArray, inputArray2, ref dsize, (int)interMethod | (int)warpMethod, borderMode, ref borderValue); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveWarpAffine(IntPtr src, IntPtr dst, IntPtr mapMatrix, ref Size dsize, int flags, BorderType borderMode, ref MCvScalar fillval); public static Mat GetAffineTransform(PointF[] src, PointF[] dest) { using VectorOfPointF src2 = ((src.Length == 3) ? new VectorOfPointF(src) : new VectorOfPointF(new PointF[3] { src[0], src[1], src[2] })); using VectorOfPointF dst = ((dest.Length == 3) ? new VectorOfPointF(dest) : new VectorOfPointF(new PointF[3] { dest[0], dest[1], dest[2] })); return GetAffineTransform(src2, dst); } public static Mat GetAffineTransform(IInputArray src, IOutputArray dst) { Mat mat = new Mat(); using InputArray inputArray = src.GetInputArray(); using OutputArray outputArray = dst.GetOutputArray(); cveGetAffineTransform(inputArray, outputArray, mat); return mat; } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveGetAffineTransform(IntPtr src, IntPtr dst, IntPtr result); public static void GetRotationMatrix2D(PointF center, double angle, double scale, IOutputArray mapMatrix) { using OutputArray outputArray = mapMatrix.GetOutputArray(); cveGetRotationMatrix2D(ref center, angle, scale, outputArray); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveGetRotationMatrix2D(ref PointF center, double angle, double scale, IntPtr mapMatrix); public static void WarpPerspective(IInputArray src, IOutputArray dst, IInputArray mapMatrix, Size dsize, Inter interpolationType = Inter.Linear, Warp warpType = Warp.Default, BorderType borderMode = BorderType.Constant, MCvScalar borderValue = default(MCvScalar)) { using InputArray inputArray = src.GetInputArray(); using OutputArray outputArray = dst.GetOutputArray(); using InputArray inputArray2 = mapMatrix.GetInputArray(); cveWarpPerspective(inputArray, outputArray, inputArray2, ref dsize, (int)interpolationType | (int)warpType, borderMode, ref borderValue); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveWarpPerspective(IntPtr src, IntPtr dst, IntPtr m, ref Size dsize, int flags, BorderType borderMode, ref MCvScalar fillval); public static Mat GetPerspectiveTransform(IInputArray src, IInputArray dst) { Mat mat = new Mat(); using InputArray inputArray = src.GetInputArray(); using InputArray inputArray2 = dst.GetInputArray(); cveGetPerspectiveTransform(inputArray, inputArray2, mat); return mat; } public static Mat GetPerspectiveTransform(PointF[] src, PointF[] dest) { GCHandle gCHandle = GCHandle.Alloc(src, GCHandleType.Pinned); GCHandle gCHandle2 = GCHandle.Alloc(dest, GCHandleType.Pinned); Mat perspectiveTransform; using (Mat src2 = new Mat(src.Length, 2, DepthType.Cv32F, 1, gCHandle.AddrOfPinnedObject(), 8)) { using Mat dst = new Mat(dest.Length, 2, DepthType.Cv32F, 1, gCHandle2.AddrOfPinnedObject(), 8); perspectiveTransform = GetPerspectiveTransform(src2, dst); } gCHandle.Free(); gCHandle2.Free(); return perspectiveTransform; } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveGetPerspectiveTransform(IntPtr src, IntPtr dst, IntPtr mapMatrix); public static void Remap(IInputArray src, IOutputArray dst, IInputArray map1, IInputArray map2, Inter interpolation, BorderType borderMode = BorderType.Constant, MCvScalar borderValue = default(MCvScalar)) { using InputArray inputArray = src.GetInputArray(); using OutputArray outputArray = dst.GetOutputArray(); using InputArray inputArray2 = map1.GetInputArray(); using InputArray inputArray3 = map2.GetInputArray(); cveRemap(inputArray, outputArray, inputArray2, inputArray3, interpolation, borderMode, ref borderValue); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveRemap(IntPtr src, IntPtr dst, IntPtr map1, IntPtr map2, Inter interpolation, BorderType borderMode, ref MCvScalar borderValue); public static void InvertAffineTransform(IInputArray m, IOutputArray im) { using InputArray inputArray = m.GetInputArray(); using OutputArray outputArray = im.GetOutputArray(); cveInvertAffineTransform(inputArray, outputArray); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveInvertAffineTransform(IntPtr m, IntPtr im); public static void LogPolar(IInputArray src, IOutputArray dst, PointF center, double M, Inter interpolationType = Inter.Linear, Warp warpType = Warp.FillOutliers) { using InputArray inputArray = src.GetInputArray(); using OutputArray outputArray = dst.GetOutputArray(); cveLogPolar(inputArray, outputArray, ref center, M, (int)interpolationType | (int)warpType); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveLogPolar(IntPtr src, IntPtr dst, ref PointF center, double M, int flags); public static void LinearPolar(IInputArray src, IOutputArray dst, PointF center, double maxRadius, Inter interpolationType = Inter.Linear, Warp warpType = Warp.FillOutliers) { using InputArray inputArray = src.GetInputArray(); using OutputArray outputArray = dst.GetOutputArray(); cveLinearPolar(inputArray, outputArray, ref center, maxRadius, (int)interpolationType | (int)warpType); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveLinearPolar(IntPtr src, IntPtr dst, ref PointF center, double maxRadius, int flags); public static void PyrDown(IInputArray src, IOutputArray dst, BorderType borderType = BorderType.Reflect101) { Size size = Size.Empty; using InputArray inputArray = src.GetInputArray(); using OutputArray outputArray = dst.GetOutputArray(); cvePyrDown(inputArray, outputArray, ref size, borderType); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cvePyrDown(IntPtr src, IntPtr dst, ref Size size, BorderType borderType); public static void PyrUp(IInputArray src, IOutputArray dst, BorderType borderType = BorderType.Reflect101) { Size size = Size.Empty; using InputArray inputArray = src.GetInputArray(); using OutputArray outputArray = dst.GetOutputArray(); cvePyrUp(inputArray, outputArray, ref size, borderType); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cvePyrUp(IntPtr src, IntPtr dst, ref Size size, BorderType borderType); public static void BuildPyramid(IInputArray src, IOutputArrayOfArrays dst, int maxlevel, BorderType borderType = BorderType.Reflect101) { using InputArray inputArray = src.GetInputArray(); using OutputArray outputArray = dst.GetOutputArray(); cveBuildPyramid(inputArray, outputArray, maxlevel, borderType); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveBuildPyramid(IntPtr src, IntPtr dst, int maxlevel, BorderType borderType); public static void Watershed(IInputArray image, IInputOutputArray markers) { using InputArray inputArray = image.GetInputArray(); using InputOutputArray inputOutputArray = markers.GetInputOutputArray(); cveWatershed(inputArray, inputOutputArray); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveWatershed(IntPtr image, IntPtr markers); public static Rectangle cvMaxRect(Rectangle rect1, Rectangle rect2) { Rectangle result = default(Rectangle); cveMaxRect(ref rect1, ref rect2, ref result); return result; } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveMaxRect(ref Rectangle rect1, ref Rectangle rect2, ref Rectangle result); public static void FitLine(IInputArray points, IOutputArray line, Emgu.CV.CvEnum.DistType distType, double param, double reps, double aeps) { using InputArray inputArray = points.GetInputArray(); using OutputArray outputArray = line.GetOutputArray(); cveFitLine(inputArray, outputArray, distType, param, reps, aeps); } public static void FitLine(PointF[] points, out PointF direction, out PointF pointOnLine, Emgu.CV.CvEnum.DistType distType, double param, double reps, double aeps) { using VectorOfPointF vectorOfPointF = new VectorOfPointF(points); using VectorOfFloat vectorOfFloat = new VectorOfFloat(); using InputArray inputArray = vectorOfPointF.GetInputArray(); using OutputArray outputArray = vectorOfFloat.GetOutputArray(); cveFitLine(inputArray, outputArray, distType, param, reps, aeps); float[] array = vectorOfFloat.ToArray(); direction = new PointF(array[0], array[1]); pointOnLine = new PointF(array[2], array[3]); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveFitLine(IntPtr points, IntPtr line, Emgu.CV.CvEnum.DistType distType, double param, double reps, double aeps); public static RectIntersectType RotatedRectangleIntersection(RotatedRect rect1, RotatedRect rect2, IOutputArray intersectingRegion) { using OutputArray outputArray = intersectingRegion.GetOutputArray(); return cveRotatedRectangleIntersection(ref rect1, ref rect2, outputArray); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern RectIntersectType cveRotatedRectangleIntersection(ref RotatedRect rect1, ref RotatedRect rect2, IntPtr intersectingRegion); public static PointF[] BoxPoints(RotatedRect box) { PointF[] array = new PointF[4]; GCHandle gCHandle = GCHandle.Alloc(array, GCHandleType.Pinned); using (Mat mat = new Mat(4, 2, DepthType.Cv32F, 1, gCHandle.AddrOfPinnedObject(), 8)) { using OutputArray outputArray = mat.GetOutputArray(); cveBoxPoints(ref box, outputArray); } gCHandle.Free(); return array; } public static void BoxPoints(RotatedRect box, IOutputArray points) { using OutputArray outputArray = points.GetOutputArray(); cveBoxPoints(ref box, outputArray); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveBoxPoints(ref RotatedRect box, IntPtr pt); public static RotatedRect FitEllipse(IInputArray points) { RotatedRect ellipse = default(RotatedRect); using InputArray inputArray = points.GetInputArray(); cveFitEllipse(inputArray, ref ellipse); return ellipse; } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveFitEllipse(IntPtr points, ref RotatedRect ellipse); public static RotatedRect FitEllipseAMS(IInputArray points) { RotatedRect ellipse = default(RotatedRect); using InputArray inputArray = points.GetInputArray(); cveFitEllipseAMS(inputArray, ref ellipse); return ellipse; } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveFitEllipseAMS(IntPtr points, ref RotatedRect ellipse); public static RotatedRect FitEllipseDirect(IInputArray points) { RotatedRect ellipse = default(RotatedRect); using InputArray inputArray = points.GetInputArray(); cveFitEllipseDirect(inputArray, ref ellipse); return ellipse; } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveFitEllipseDirect(IntPtr points, ref RotatedRect ellipse); public static PointF[] ConvexHull(PointF[] points, bool clockwise = false) { using VectorOfPointF points2 = new VectorOfPointF(points); using VectorOfPointF vectorOfPointF = new VectorOfPointF(); ConvexHull(points2, vectorOfPointF, clockwise); return vectorOfPointF.ToArray(); } public static void ConvexHull(IInputArray points, IOutputArray hull, bool clockwise = false, bool returnPoints = true) { using InputArray inputArray = points.GetInputArray(); using OutputArray outputArray = hull.GetOutputArray(); cveConvexHull(inputArray, outputArray, clockwise, returnPoints); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveConvexHull(IntPtr points, IntPtr hull, [MarshalAs(UnmanagedType.U1)] bool clockwise, [MarshalAs(UnmanagedType.U1)] bool returnPoints); public static void Erode(IInputArray src, IOutputArray dst, IInputArray element, Point anchor, int iterations, BorderType borderType, MCvScalar borderValue) { using InputArray inputArray = src.GetInputArray(); using OutputArray outputArray = dst.GetOutputArray(); using InputArray inputArray2 = ((element == null) ? InputArray.GetEmpty() : element.GetInputArray()); cveErode(inputArray, outputArray, inputArray2, ref anchor, iterations, borderType, ref borderValue); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveErode(IntPtr src, IntPtr dst, IntPtr kernel, ref Point anchor, int iterations, BorderType borderType, ref MCvScalar borderValue); public static void Dilate(IInputArray src, IOutputArray dst, IInputArray element, Point anchor, int iterations, BorderType borderType, MCvScalar borderValue) { using InputArray inputArray = src.GetInputArray(); using OutputArray outputArray = dst.GetOutputArray(); using InputArray inputArray2 = ((element == null) ? InputArray.GetEmpty() : element.GetInputArray()); cveDilate(inputArray, outputArray, inputArray2, ref anchor, iterations, borderType, ref borderValue); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveDilate(IntPtr src, IntPtr dst, IntPtr kernel, ref Point anchor, int iterations, BorderType borderType, ref MCvScalar borderValue); public static void GaussianBlur(IInputArray src, IOutputArray dst, Size ksize, double sigmaX, double sigmaY = 0.0, BorderType borderType = BorderType.Reflect101) { using InputArray inputArray = src.GetInputArray(); using OutputArray outputArray = dst.GetOutputArray(); cveGaussianBlur(inputArray, outputArray, ref ksize, sigmaX, sigmaY, borderType); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveGaussianBlur(IntPtr src, IntPtr dst, ref Size ksize, double sigmaX, double sigmaY, BorderType borderType); public static void Blur(IInputArray src, IOutputArray dst, Size ksize, Point anchor, BorderType borderType = BorderType.Reflect101) { using InputArray inputArray = src.GetInputArray(); using OutputArray outputArray = dst.GetOutputArray(); cveBlur(inputArray, outputArray, ref ksize, ref anchor, borderType); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveBlur(IntPtr src, IntPtr dst, ref Size kSize, ref Point anchor, BorderType borderType); public static void MedianBlur(IInputArray src, IOutputArray dst, int ksize) { using InputArray inputArray = src.GetInputArray(); using OutputArray outputArray = dst.GetOutputArray(); cveMedianBlur(inputArray, outputArray, ksize); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveMedianBlur(IntPtr src, IntPtr dst, int ksize); public static void BoxFilter(IInputArray src, IOutputArray dst, DepthType ddepth, Size ksize, Point anchor, bool normalize = true, BorderType borderType = BorderType.Reflect101) { using InputArray inputArray = src.GetInputArray(); using OutputArray outputArray = dst.GetOutputArray(); cveBoxFilter(inputArray, outputArray, ddepth, ref ksize, ref anchor, normalize, borderType); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveBoxFilter(IntPtr src, IntPtr dst, DepthType ddepth, ref Size ksize, ref Point anchor, [MarshalAs(UnmanagedType.U1)] bool normailize, BorderType borderType); public static void SqrBoxFilter(IInputArray src, IOutputArray dst, DepthType ddepth, Size ksize, Point anchor, bool normalize = true, BorderType borderType = BorderType.Reflect101) { using InputArray inputArray = src.GetInputArray(); using OutputArray outputArray = dst.GetOutputArray(); cveSqrBoxFilter(inputArray, outputArray, ddepth, ref ksize, ref anchor, normalize, borderType); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveSqrBoxFilter(IntPtr src, IntPtr dst, DepthType ddepth, ref Size ksize, ref Point anchor, [MarshalAs(UnmanagedType.U1)] bool normalize, BorderType borderType); public static void BilateralFilter(IInputArray src, IOutputArray dst, int d, double sigmaColor, double sigmaSpace, BorderType borderType = BorderType.Reflect101) { using InputArray inputArray = src.GetInputArray(); using OutputArray outputArray = dst.GetOutputArray(); cveBilateralFilter(inputArray, outputArray, d, sigmaColor, sigmaSpace, borderType); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveBilateralFilter(IntPtr src, IntPtr dst, int d, double sigmaColor, double sigmaSpace, BorderType borderType); public static void Sobel(IInputArray src, IOutputArray dst, DepthType ddepth, int xorder, int yorder, int kSize = 3, double scale = 1.0, double delta = 0.0, BorderType borderType = BorderType.Reflect101) { using InputArray inputArray = src.GetInputArray(); using OutputArray outputArray = dst.GetOutputArray(); cveSobel(inputArray, outputArray, ddepth, xorder, yorder, kSize, scale, delta, borderType); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveSobel(IntPtr src, IntPtr dst, DepthType ddepth, int xorder, int yorder, int apertureSize, double scale, double delta, BorderType borderType); public static void SpatialGradient(IInputArray src, IOutputArray dx, IOutputArray dy, int ksize = 3, BorderType borderType = BorderType.Reflect101) { using InputArray inputArray = src.GetInputArray(); using OutputArray outputArray = dx.GetOutputArray(); using OutputArray outputArray2 = dy.GetOutputArray(); cveSpatialGradient(inputArray, outputArray, outputArray2, ksize, borderType); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveSpatialGradient(IntPtr src, IntPtr dx, IntPtr dy, int ksize, BorderType borderType); public static void Scharr(IInputArray src, IOutputArray dst, DepthType ddepth, int dx, int dy, double scale = 1.0, double delta = 0.0, BorderType borderType = BorderType.Reflect101) { using InputArray inputArray = src.GetInputArray(); using OutputArray outputArray = dst.GetOutputArray(); cveScharr(inputArray, outputArray, ddepth, dx, dy, scale, delta, borderType); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveScharr(IntPtr src, IntPtr dst, DepthType ddepth, int dx, int dy, double scale, double delta, BorderType borderType); public static void Laplacian(IInputArray src, IOutputArray dst, DepthType ddepth, int ksize = 1, double scale = 1.0, double delta = 0.0, BorderType borderType = BorderType.Reflect101) { using InputArray inputArray = src.GetInputArray(); using OutputArray outputArray = dst.GetOutputArray(); cveLaplacian(inputArray, outputArray, ddepth, ksize, scale, delta, borderType); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveLaplacian(IntPtr src, IntPtr dst, DepthType ddepth, int ksize, double scale, double delta, BorderType borderType); public static void Canny(IInputArray image, IOutputArray edges, double threshold1, double threshold2, int apertureSize = 3, bool l2Gradient = false) { using InputArray inputArray = image.GetInputArray(); using OutputArray outputArray = edges.GetOutputArray(); cveCanny(inputArray, outputArray, threshold1, threshold2, apertureSize, l2Gradient); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveCanny(IntPtr image, IntPtr edges, double threshold1, double threshold2, int apertureSize, [MarshalAs(UnmanagedType.U1)] bool l2Gradient); public static void Canny(IInputArray dx, IInputArray dy, IOutputArray edges, double threshold1, double threshold2, bool l2Gradient = false) { using InputArray inputArray = dx.GetInputArray(); using InputArray inputArray2 = dy.GetInputArray(); using OutputArray outputArray = edges.GetOutputArray(); cveCanny2(inputArray, inputArray2, outputArray, threshold1, threshold2, l2Gradient); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveCanny2(IntPtr dx, IntPtr dy, IntPtr edges, double threshold1, double threshold2, [MarshalAs(UnmanagedType.U1)] bool l2Gradient); public static bool IsContourConvex(IInputArray contour) { using InputArray inputArray = contour.GetInputArray(); return cveIsContourConvex(inputArray); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.U1)] private static extern bool cveIsContourConvex(IntPtr contour); public static float IntersectConvexConvex(IInputArray p1, IInputArray p2, IOutputArray p12, bool handleNested = true) { using InputArray inputArray = p1.GetInputArray(); using InputArray inputArray2 = p2.GetInputArray(); using OutputArray outputArray = p12.GetOutputArray(); return cveIntersectConvexConvex(inputArray, inputArray2, outputArray, handleNested); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern float cveIntersectConvexConvex(IntPtr p1, IntPtr p2, IntPtr p12, [MarshalAs(UnmanagedType.U1)] bool handleNested); public static double PointPolygonTest(IInputArray contour, PointF pt, bool measureDist) { using InputArray inputArray = contour.GetInputArray(); return cvePointPolygonTest(inputArray, ref pt, measureDist); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern double cvePointPolygonTest(IntPtr contour, ref PointF pt, [MarshalAs(UnmanagedType.U1)] bool measureDist); public static void ConvexityDefects(IInputArray contour, IInputArray convexhull, IOutputArray convexityDefects) { using InputArray inputArray = contour.GetInputArray(); using InputArray inputArray2 = convexhull.GetInputArray(); using OutputArray outputArray = convexityDefects.GetOutputArray(); cveConvexityDefects(inputArray, inputArray2, outputArray); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveConvexityDefects(IntPtr contour, IntPtr convexhull, IntPtr convexityDefects); public static RotatedRect MinAreaRect(PointF[] points) { using VectorOfPointF points2 = new VectorOfPointF(points); return MinAreaRect(points2); } public static RotatedRect MinAreaRect(IInputArray points) { RotatedRect box = default(RotatedRect); using InputArray inputArray = points.GetInputArray(); cveMinAreaRect(inputArray, ref box); return box; } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveMinAreaRect(IntPtr points, ref RotatedRect box); public static CircleF MinEnclosingCircle(PointF[] points) { using VectorOfPointF points2 = new VectorOfPointF(points); return MinEnclosingCircle(points2); } public static CircleF MinEnclosingCircle(IInputArray points) { PointF center = default(PointF); float radius = 0f; using (InputArray inputArray = points.GetInputArray()) { cveMinEnclosingCircle(inputArray, ref center, ref radius); } return new CircleF(center, radius); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveMinEnclosingCircle(IntPtr points, ref PointF center, ref float radius); public static double MinEnclosingTriangle(IInputArray points, IOutputArray triangles) { using InputArray inputArray = points.GetInputArray(); using OutputArray outputArray = triangles.GetOutputArray(); return cveMinEnclosingTriangle(inputArray, outputArray); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern double cveMinEnclosingTriangle(IntPtr points, IntPtr triangle); public static void ApproxPolyDP(IInputArray curve, IOutputArray approxCurve, double epsilon, bool closed) { using InputArray inputArray = curve.GetInputArray(); using OutputArray outputArray = approxCurve.GetOutputArray(); cveApproxPolyDP(inputArray, outputArray, epsilon, closed); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveApproxPolyDP(IntPtr curve, IntPtr approxCurve, double epsilon, [MarshalAs(UnmanagedType.U1)] bool closed); public static Rectangle BoundingRectangle(Point[] points) { using VectorOfPoint points2 = new VectorOfPoint(points); return BoundingRectangle(points2); } public static Rectangle BoundingRectangle(IInputArray points) { Rectangle boundingRect = default(Rectangle); using InputArray inputArray = points.GetInputArray(); cveBoundingRectangle(inputArray, ref boundingRect); return boundingRect; } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveBoundingRectangle(IntPtr points, ref Rectangle boundingRect); public static double ContourArea(IInputArray contour, bool oriented = false) { using InputArray inputArray = contour.GetInputArray(); return cveContourArea(inputArray, oriented); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern double cveContourArea(IntPtr contour, [MarshalAs(UnmanagedType.U1)] bool oriented); public static double ArcLength(IInputArray curve, bool isClosed) { using InputArray inputArray = curve.GetInputArray(); return cveArcLength(inputArray, isClosed); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern double cveArcLength(IntPtr curve, [MarshalAs(UnmanagedType.U1)] bool isClosed); public static double Threshold(IInputArray src, IOutputArray dst, double threshold, double maxValue, ThresholdType thresholdType) { using InputArray inputArray = src.GetInputArray(); using OutputArray outputArray = dst.GetOutputArray(); return cveThreshold(inputArray, outputArray, threshold, maxValue, thresholdType); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern double cveThreshold(IntPtr src, IntPtr dst, double threshold, double maxValue, ThresholdType thresholdType); public static void AdaptiveThreshold(IInputArray src, IOutputArray dst, double maxValue, AdaptiveThresholdType adaptiveType, ThresholdType thresholdType, int blockSize, double param1) { using InputArray inputArray = src.GetInputArray(); using OutputArray outputArray = dst.GetOutputArray(); cveAdaptiveThreshold(inputArray, outputArray, maxValue, adaptiveType, thresholdType, blockSize, param1); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveAdaptiveThreshold(IntPtr src, IntPtr dst, double maxValue, AdaptiveThresholdType adaptiveType, ThresholdType thresholdType, int blockSize, double param1); public static void FindContours(IInputOutputArray image, IOutputArray contours, IOutputArray hierarchy, RetrType mode, ChainApproxMethod method, Point offset = default(Point)) { using InputOutputArray inputOutputArray = image.GetInputOutputArray(); using OutputArray outputArray = contours.GetOutputArray(); using OutputArray outputArray2 = ((hierarchy == null) ? OutputArray.GetEmpty() : hierarchy.GetOutputArray()); cveFindContours(inputOutputArray, outputArray, outputArray2, mode, method, ref offset); } public static int[,] FindContourTree(IInputOutputArray image, IOutputArray contours, ChainApproxMethod method, Point offset = default(Point)) { using Mat mat = new Mat(); FindContours(image, contours, mat, RetrType.Tree, method, offset); int[,] array = new int[mat.Cols, 4]; GCHandle gCHandle = GCHandle.Alloc(array, GCHandleType.Pinned); using (Mat m = new Mat(mat.Rows, mat.Cols, mat.Depth, 4, gCHandle.AddrOfPinnedObject(), mat.Step)) { mat.CopyTo(m); } gCHandle.Free(); return array; } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveFindContours(IntPtr image, IntPtr contours, IntPtr hierarchy, RetrType mode, ChainApproxMethod method, ref Point offset); public static void CvtColor(IInputArray src, IOutputArray dest, Type srcColor, Type destColor) { try { CvtColor(src, dest, CvToolbox.GetColorCvtCode(srcColor, destColor)); } catch { try { using Mat mat = new Mat(); CvtColor(src, mat, CvToolbox.GetColorCvtCode(srcColor, typeof(Bgr))); CvtColor(mat, dest, CvToolbox.GetColorCvtCode(typeof(Bgr), destColor)); } catch (Exception ex) { throw new NotSupportedException($"There is an error converting {srcColor.ToString()} to {destColor.ToString()}: {ex.Message}", ex); } } } public static void CvtColor(IInputArray src, IOutputArray dst, ColorConversion code, int dstCn = 0) { using InputArray inputArray = src.GetInputArray(); using OutputArray outputArray = dst.GetOutputArray(); cveCvtColor(inputArray, outputArray, code, dstCn); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveCvtColor(IntPtr src, IntPtr dst, ColorConversion code, int dstCn); public static void HoughCircles(IInputArray image, IOutputArray circles, HoughModes method, double dp, double minDist, double param1 = 100.0, double param2 = 100.0, int minRadius = 0, int maxRadius = 0) { using InputArray inputArray = image.GetInputArray(); using OutputArray outputArray = circles.GetOutputArray(); cveHoughCircles(inputArray, outputArray, method, dp, minDist, param1, param2, minRadius, maxRadius); } public static CircleF[] HoughCircles(IInputArray image, HoughModes method, double dp, double minDist, double param1 = 100.0, double param2 = 100.0, int minRadius = 0, int maxRadius = 0) { using VectorOfPoint3D32F vectorOfPoint3D32F = new VectorOfPoint3D32F(); HoughCircles(image, vectorOfPoint3D32F, method, dp, minDist, param1, param2, minRadius, maxRadius); vectorOfPoint3D32F.ToArray(); CircleF[] array = new CircleF[vectorOfPoint3D32F.Size]; for (int i = 0; i < array.Length; i++) { array[i] = new CircleF(new PointF(vectorOfPoint3D32F[i].X, vectorOfPoint3D32F[i].Y), vectorOfPoint3D32F[i].Z); } return array; } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveHoughCircles(IntPtr image, IntPtr circles, HoughModes method, double dp, double minDist, double param1, double param2, int minRadius, int maxRadius); public static void HoughLines(IInputArray image, IOutputArray lines, double rho, double theta, int threshold, double srn = 0.0, double stn = 0.0) { using InputArray inputArray = image.GetInputArray(); using OutputArray outputArray = lines.GetOutputArray(); cveHoughLines(inputArray, outputArray, rho, theta, threshold, srn, stn); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveHoughLines(IntPtr image, IntPtr lines, double rho, double theta, int threshold, double srn, double stn); public static LineSegment2D[] HoughLinesP(IInputArray image, double rho, double theta, int threshold, double minLineLength = 0.0, double maxGap = 0.0) { using Mat mat = new Mat(); HoughLinesP(image, mat, rho, theta, threshold, minLineLength, maxGap); Size size = mat.Size; LineSegment2D[] array = new LineSegment2D[size.Height]; GCHandle gCHandle = GCHandle.Alloc(array, GCHandleType.Pinned); using (Mat m = new Mat(size.Height, size.Width, DepthType.Cv32S, 4, gCHandle.AddrOfPinnedObject(), 16)) { mat.CopyTo(m); } gCHandle.Free(); return array; } public static void HoughLinesP(IInputArray image, IOutputArray lines, double rho, double theta, int threshold, double minLineLength = 0.0, double maxGap = 0.0) { using InputArray inputArray = image.GetInputArray(); using OutputArray outputArray = lines.GetOutputArray(); cveHoughLinesP(inputArray, outputArray, rho, theta, threshold, minLineLength, maxGap); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveHoughLinesP(IntPtr image, IntPtr lines, double rho, double theta, int threshold, double minLineLength, double maxGap); public static Moments Moments(IInputArray arr, bool binaryImage = false) { Moments moments = new Moments(); using InputArray inputArray = arr.GetInputArray(); cveMoments(inputArray, binaryImage, moments); return moments; } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveMoments(IntPtr arr, [MarshalAs(UnmanagedType.U1)] bool binaryImage, IntPtr moments); public static void MatchTemplate(IInputArray image, IInputArray templ, IOutputArray result, TemplateMatchingType method, IInputArray mask = null) { using InputArray inputArray = image.GetInputArray(); using InputArray inputArray2 = templ.GetInputArray(); using OutputArray outputArray = result.GetOutputArray(); using InputArray inputArray3 = ((mask == null) ? InputArray.GetEmpty() : mask.GetInputArray()); cveMatchTemplate(inputArray, inputArray2, outputArray, method, inputArray3); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveMatchTemplate(IntPtr image, IntPtr templ, IntPtr result, TemplateMatchingType method, IntPtr mask); public static double MatchShapes(IInputArray contour1, IInputArray contour2, ContoursMatchType method, double parameter = 0.0) { using InputArray inputArray = contour1.GetInputArray(); using InputArray inputArray2 = contour2.GetInputArray(); return cveMatchShapes(inputArray, inputArray2, method, parameter); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern double cveMatchShapes(IntPtr contour1, IntPtr contour2, ContoursMatchType method, double parameter); public static Mat GetStructuringElement(ElementShape shape, Size ksize, Point anchor) { Mat mat = new Mat(); cveGetStructuringElement(mat, shape, ref ksize, ref anchor); return mat; } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveGetStructuringElement(IntPtr mat, ElementShape shape, ref Size ksize, ref Point anchor); public static void MorphologyEx(IInputArray src, IOutputArray dst, MorphOp operation, IInputArray kernel, Point anchor, int iterations, BorderType borderType, MCvScalar borderValue) { using InputArray inputArray = src.GetInputArray(); using OutputArray outputArray = dst.GetOutputArray(); using InputArray inputArray2 = kernel.GetInputArray(); cveMorphologyEx(inputArray, outputArray, operation, inputArray2, ref anchor, iterations, borderType, ref borderValue); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveMorphologyEx(IntPtr src, IntPtr dst, MorphOp operation, IntPtr kernel, ref Point anchor, int iterations, BorderType borderType, ref MCvScalar borderValue); public static void EqualizeHist(IInputArray src, IOutputArray dst) { using InputArray inputArray = src.GetInputArray(); using OutputArray outputArray = dst.GetOutputArray(); cveEqualizeHist(inputArray, outputArray); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveEqualizeHist(IntPtr src, IntPtr dst); public static void CalcHist(IInputArrayOfArrays images, int[] channels, IInputArray mask, IOutputArray hist, int[] histSize, float[] ranges, bool accumulate) { using VectorOfInt vectorOfInt = new VectorOfInt(channels); using VectorOfInt vectorOfInt2 = new VectorOfInt(histSize); using VectorOfFloat vectorOfFloat = new VectorOfFloat(ranges); using InputArray inputArray = images.GetInputArray(); using InputArray inputArray2 = ((mask == null) ? InputArray.GetEmpty() : mask.GetInputArray()); using OutputArray outputArray = hist.GetOutputArray(); cveCalcHist(inputArray, vectorOfInt, inputArray2, outputArray, vectorOfInt2, vectorOfFloat, accumulate); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveCalcHist(IntPtr images, IntPtr channels, IntPtr mask, IntPtr hist, IntPtr histSize, IntPtr ranges, [MarshalAs(UnmanagedType.U1)] bool accumulate); public static void CalcBackProject(IInputArrayOfArrays images, int[] channels, IInputArray hist, IOutputArray backProject, float[] ranges, double scale = 1.0) { using VectorOfInt vectorOfInt = new VectorOfInt(channels); using VectorOfFloat vectorOfFloat = new VectorOfFloat(ranges); using InputArray inputArray = images.GetInputArray(); using InputArray inputArray2 = hist.GetInputArray(); using OutputArray outputArray = backProject.GetOutputArray(); cveCalcBackProject(inputArray, vectorOfInt, inputArray2, outputArray, vectorOfFloat, scale); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveCalcBackProject(IntPtr images, IntPtr channels, IntPtr hist, IntPtr dst, IntPtr ranges, double scale); public static double CompareHist(IInputArray h1, IInputArray h2, HistogramCompMethod method) { using InputArray inputArray = h1.GetInputArray(); using InputArray inputArray2 = h2.GetInputArray(); return cveCompareHist(inputArray, inputArray2, method); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern double cveCompareHist(IntPtr h1, IntPtr h2, HistogramCompMethod method); public static void Accumulate(IInputArray src, IInputOutputArray dst, IInputArray mask = null) { using InputArray inputArray = src.GetInputArray(); using InputOutputArray inputOutputArray = dst.GetInputOutputArray(); using InputArray inputArray2 = ((mask == null) ? InputArray.GetEmpty() : mask.GetInputArray()); cveAccumulate(inputArray, inputOutputArray, inputArray2); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveAccumulate(IntPtr src, IntPtr dst, IntPtr mask); public static void AccumulateSquare(IInputArray src, IInputOutputArray dst, IInputArray mask = null) { using InputArray inputArray = src.GetInputArray(); using InputOutputArray inputOutputArray = dst.GetInputOutputArray(); using InputArray inputArray2 = ((mask == null) ? InputArray.GetEmpty() : mask.GetInputArray()); cveAccumulateSquare(inputArray, inputOutputArray, inputArray2); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveAccumulateSquare(IntPtr src, IntPtr dst, IntPtr mask); public static void AccumulateProduct(IInputArray src1, IInputArray src2, IInputOutputArray dst, IInputArray mask = null) { using InputArray inputArray = src1.GetInputArray(); using InputArray inputArray2 = src2.GetInputArray(); using InputOutputArray inputOutputArray = dst.GetInputOutputArray(); using InputArray inputArray3 = ((mask == null) ? InputArray.GetEmpty() : mask.GetInputArray()); cveAccumulateProduct(inputArray, inputArray2, inputOutputArray, inputArray3); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveAccumulateProduct(IntPtr src1, IntPtr src2, IntPtr dst, IntPtr mask); public static void AccumulateWeighted(IInputArray src, IInputOutputArray dst, double alpha, IInputArray mask = null) { using InputArray inputArray = src.GetInputArray(); using InputOutputArray inputOutputArray = dst.GetInputOutputArray(); using InputArray inputArray2 = ((mask == null) ? InputArray.GetEmpty() : mask.GetInputArray()); cveAccumulateWeighted(inputArray, inputOutputArray, alpha, inputArray2); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveAccumulateWeighted(IntPtr src, IntPtr dst, double alpha, IntPtr mask); public static void CornerHarris(IInputArray image, IOutputArray harrisResponse, int blockSize, int apertureSize = 3, double k = 0.04, BorderType borderType = BorderType.Reflect101) { using InputArray inputArray = image.GetInputArray(); using OutputArray outputArray = harrisResponse.GetOutputArray(); cveCornerHarris(inputArray, outputArray, blockSize, apertureSize, k, borderType); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveCornerHarris(IntPtr image, IntPtr harrisResponce, int blockSize, int apertureSize, double k, BorderType borderType); public static void CornerSubPix(IInputArray image, IInputOutputArray corners, Size win, Size zeroZone, MCvTermCriteria criteria) { using InputArray inputArray = image.GetInputArray(); using InputOutputArray inputOutputArray = corners.GetInputOutputArray(); cveCornerSubPix(inputArray, inputOutputArray, ref win, ref zeroZone, ref criteria); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveCornerSubPix(IntPtr image, IntPtr corners, ref Size win, ref Size zeroZone, ref MCvTermCriteria criteria); public static void Integral(IInputArray image, IOutputArray sum, IOutputArray sqsum = null, IOutputArray tiltedSum = null, DepthType sdepth = DepthType.Default, DepthType sqdepth = DepthType.Default) { using InputArray inputArray = image.GetInputArray(); using OutputArray outputArray = sum.GetOutputArray(); using OutputArray outputArray2 = ((sqsum == null) ? OutputArray.GetEmpty() : sqsum.GetOutputArray()); using OutputArray outputArray3 = ((tiltedSum == null) ? OutputArray.GetEmpty() : tiltedSum.GetOutputArray()); cveIntegral(inputArray, outputArray, outputArray2, outputArray3, sdepth, sqdepth); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveIntegral(IntPtr image, IntPtr sum, IntPtr sqsum, IntPtr tiltedSum, DepthType sdepth, DepthType sqdepth); public static void DistanceTransform(IInputArray src, IOutputArray dst, IOutputArray labels, Emgu.CV.CvEnum.DistType distanceType, int maskSize, DistLabelType labelType = DistLabelType.CComp) { using InputArray inputArray = src.GetInputArray(); using OutputArray outputArray = dst.GetOutputArray(); using OutputArray outputArray2 = ((labels == null) ? OutputArray.GetEmpty() : labels.GetOutputArray()); cveDistanceTransform(inputArray, outputArray, outputArray2, distanceType, maskSize, labelType); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveDistanceTransform(IntPtr src, IntPtr dst, IntPtr labels, Emgu.CV.CvEnum.DistType distanceType, int maskSize, DistLabelType labelType); public static int FloodFill(IInputOutputArray src, IInputOutputArray mask, Point seedPoint, MCvScalar newVal, out Rectangle rect, MCvScalar loDiff, MCvScalar upDiff, Connectivity connectivity = Connectivity.FourConnected, FloodFillType flags = FloodFillType.Default) { rect = default(Rectangle); using InputOutputArray inputOutputArray = src.GetInputOutputArray(); using InputOutputArray inputOutputArray2 = ((mask == null) ? InputOutputArray.GetEmpty() : mask.GetInputOutputArray()); return cveFloodFill(inputOutputArray, inputOutputArray2, ref seedPoint, ref newVal, ref rect, ref loDiff, ref upDiff, (int)connectivity | (int)flags); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern int cveFloodFill(IntPtr src, IntPtr mask, ref Point seedPoint, ref MCvScalar newVal, ref Rectangle rect, ref MCvScalar loDiff, ref MCvScalar upDiff, int flags); public static void PyrMeanShiftFiltering(IInputArray src, IOutputArray dst, double sp, double sr, int maxLevel, MCvTermCriteria termcrit) { using InputArray inputArray = src.GetInputArray(); using OutputArray outputArray = dst.GetOutputArray(); cvePyrMeanShiftFiltering(inputArray, outputArray, sp, sr, maxLevel, ref termcrit); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cvePyrMeanShiftFiltering(IntPtr src, IntPtr dst, double sp, double sr, int maxLevel, ref MCvTermCriteria termcrit); public static void ConvertMaps(IInputArray map1, IInputArray map2, IOutputArray dstmap1, IOutputArray dstmap2, DepthType dstmap1Depth, int dstmap1Channels, bool nninterpolation = false) { using InputArray inputArray = map1.GetInputArray(); using InputArray inputArray2 = ((map2 == null) ? InputArray.GetEmpty() : map2.GetInputArray()); using OutputArray outputArray = dstmap1.GetOutputArray(); using OutputArray outputArray2 = ((dstmap2 == null) ? OutputArray.GetEmpty() : dstmap2.GetOutputArray()); cveConvertMaps(inputArray, inputArray2, outputArray, outputArray2, MakeType(dstmap1Depth, dstmap1Channels), nninterpolation); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveConvertMaps(IntPtr map1, IntPtr map2, IntPtr dstmap1, IntPtr dstmap2, int dstmap1Type, [MarshalAs(UnmanagedType.U1)] bool nninterpolation); public static float EMD(IInputArray signature1, IInputArray signature2, Emgu.CV.CvEnum.DistType distType, IInputArray cost = null, float[] lowerBound = null, IOutputArray flow = null) { IntPtr lowerBound2 = IntPtr.Zero; GCHandle gCHandle; if (lowerBound != null) { gCHandle = GCHandle.Alloc(lowerBound, GCHandleType.Pinned); lowerBound2 = gCHandle.AddrOfPinnedObject(); } else { gCHandle = default(GCHandle); } try { using InputArray inputArray = signature1.GetInputArray(); using InputArray inputArray2 = signature2.GetInputArray(); using InputArray inputArray3 = ((cost == null) ? InputArray.GetEmpty() : cost.GetInputArray()); using OutputArray outputArray = ((flow == null) ? OutputArray.GetEmpty() : flow.GetOutputArray()); return cveEMD(inputArray, inputArray2, distType, inputArray3, lowerBound2, outputArray); } finally { if (lowerBound != null) { gCHandle.Free(); } } } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern float cveEMD(IntPtr signature1, IntPtr signature2, Emgu.CV.CvEnum.DistType distType, IntPtr cost, IntPtr lowerBound, IntPtr flow); public static MCvPoint2D64f PhaseCorrelate(IInputArray src1, IInputArray src2, IInputArray window, out double response) { MCvPoint2D64f result = default(MCvPoint2D64f); response = 0.0; using InputArray inputArray = src1.GetInputArray(); using InputArray inputArray2 = src2.GetInputArray(); using InputArray inputArray3 = ((window == null) ? InputArray.GetEmpty() : window.GetInputArray()); cvePhaseCorrelate(inputArray, inputArray2, inputArray3, ref response, ref result); return result; } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cvePhaseCorrelate(IntPtr src1, IntPtr src2, IntPtr window, ref double response, ref MCvPoint2D64f result); public static void CreateHanningWindow(IOutputArray dst, Size winSize, DepthType type) { using OutputArray outputArray = dst.GetOutputArray(); cveCreateHanningWindow(outputArray, ref winSize, type); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveCreateHanningWindow(IntPtr dst, ref Size winSize, DepthType type); public static void Line(IInputOutputArray img, Point pt1, Point pt2, MCvScalar color, int thickness = 1, LineType lineType = LineType.EightConnected, int shift = 0) { using InputOutputArray inputOutputArray = img.GetInputOutputArray(); cveLine(inputOutputArray, ref pt1, ref pt2, ref color, thickness, lineType, shift); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveLine(IntPtr img, ref Point pt1, ref Point pt2, ref MCvScalar color, int thickness, LineType lineType, int shift); public static void ArrowedLine(IInputOutputArray img, Point pt1, Point pt2, MCvScalar color, int thickness = 1, LineType lineType = LineType.EightConnected, int shift = 0, double tipLength = 0.1) { using InputOutputArray inputOutputArray = img.GetInputOutputArray(); cveArrowedLine(inputOutputArray, ref pt1, ref pt2, ref color, thickness, lineType, shift, tipLength); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveArrowedLine(IntPtr img, ref Point pt1, ref Point pt2, ref MCvScalar color, int thickness, LineType lineType, int shift, double tipLength); public static void Polylines(IInputOutputArray img, Point[] pts, bool isClosed, MCvScalar color, int thickness = 1, LineType lineType = LineType.EightConnected, int shift = 0) { using VectorOfPoint pts2 = new VectorOfPoint(pts); Polylines(img, pts2, isClosed, color, thickness, lineType, shift); } public static void Polylines(IInputOutputArray img, IInputArray pts, bool isClosed, MCvScalar color, int thickness = 1, LineType lineType = LineType.EightConnected, int shift = 0) { using InputOutputArray inputOutputArray = img.GetInputOutputArray(); using InputArray inputArray = pts.GetInputArray(); cvePolylines(inputOutputArray, inputArray, isClosed, ref color, thickness, lineType, shift); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cvePolylines(IntPtr img, IntPtr pts, [MarshalAs(UnmanagedType.U1)] bool isClosed, ref MCvScalar color, int thickness, LineType lineType, int shift); public static void Rectangle(IInputOutputArray img, Rectangle rect, MCvScalar color, int thickness = 1, LineType lineType = LineType.EightConnected, int shift = 0) { using InputOutputArray inputOutputArray = img.GetInputOutputArray(); cveRectangle(inputOutputArray, ref rect, ref color, thickness, lineType, shift); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveRectangle(IntPtr img, ref Rectangle rect, ref MCvScalar color, int thickness, LineType lineType, int shift); public static int ConnectedComponents(IInputArray image, IOutputArray labels, LineType connectivity = LineType.EightConnected, DepthType labelType = DepthType.Cv32S, ConnectedComponentsAlgorithmsTypes cclType = ConnectedComponentsAlgorithmsTypes.Default) { using InputArray inputArray = image.GetInputArray(); using OutputArray outputArray = labels.GetOutputArray(); return cveConnectedComponents(inputArray, outputArray, connectivity, labelType, cclType); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern int cveConnectedComponents(IntPtr image, IntPtr labels, LineType connectivity, DepthType labelType, ConnectedComponentsAlgorithmsTypes cclType); public static int ConnectedComponentsWithStats(IInputArray image, IOutputArray labels, IOutputArray stats, IOutputArray centroids, LineType connectivity = LineType.EightConnected, DepthType labelType = DepthType.Cv32S, ConnectedComponentsAlgorithmsTypes cclType = ConnectedComponentsAlgorithmsTypes.Default) { using InputArray inputArray = image.GetInputArray(); using OutputArray outputArray = labels.GetOutputArray(); using OutputArray outputArray2 = stats.GetOutputArray(); using OutputArray outputArray3 = centroids.GetOutputArray(); return cveConnectedComponentsWithStats(inputArray, outputArray, outputArray2, outputArray3, connectivity, labelType, cclType); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern int cveConnectedComponentsWithStats(IntPtr image, IntPtr labels, IntPtr stats, IntPtr centroids, LineType connectivity, DepthType type, ConnectedComponentsAlgorithmsTypes cllType); public static void HuMoments(Moments m, IOutputArray hu) { using OutputArray outputArray = hu.GetOutputArray(); cveHuMoments(m, outputArray); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveHuMoments(IntPtr moments, IntPtr huMoments); public static double[] HuMoments(Moments m) { double[] array = new double[7]; GCHandle gCHandle = GCHandle.Alloc(array, GCHandleType.Pinned); cveHuMoments2(m, gCHandle.AddrOfPinnedObject()); gCHandle.Free(); return array; } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveHuMoments2(IntPtr moments, IntPtr hu); public static Mat GetGaussianKernel(int ksize, double sigma, DepthType ktype = DepthType.Cv64F) { Mat mat = new Mat(); cveGetGaussianKernel(ksize, sigma, ktype, mat); return mat; } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveGetGaussianKernel(int ksize, double sigma, DepthType ktype, IntPtr result); public static void GetDerivKernels(IOutputArray kx, IOutputArray ky, int dx, int dy, int ksize, bool normalize = false, DepthType ktype = DepthType.Cv32F) { using OutputArray outputArray = kx.GetOutputArray(); using OutputArray outputArray2 = ky.GetOutputArray(); cveGetDerivKernels(outputArray, outputArray2, dx, dy, ksize, normalize, ktype); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveGetDerivKernels(IntPtr kx, IntPtr ky, int dx, int dy, int ksize, [MarshalAs(UnmanagedType.U1)] bool normalize, DepthType ktype); public static Mat GetGaborKernel(Size ksize, double sigma, double theta, double lambd, double gamma, double psi = Math.PI / 2.0, DepthType ktype = DepthType.Cv64F) { Mat mat = new Mat(); cveGetGaborKernel(ref ksize, sigma, theta, lambd, gamma, psi, ktype, mat); return mat; } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveGetGaborKernel(ref Size ksize, double sigma, double theta, double lambd, double gamma, double psi, DepthType ktype, IntPtr result); public static void GroupRectangles(VectorOfRect rectList, int groupThreshold, double eps = 0.2) { cveGroupRectangles1(rectList, groupThreshold, eps); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveGroupRectangles1(IntPtr rectList, int groupThreshold, double eps = 0.2); public static void GroupRectangles(VectorOfRect rectList, VectorOfInt weights, int groupThreshold, double eps = 0.2) { cveGroupRectangles2(rectList, weights, groupThreshold, eps); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveGroupRectangles2(IntPtr rectList, IntPtr weights, int groupThreshold, double eps = 0.2); public static void GroupRectangles(VectorOfRect rectList, int groupThreshold, double eps, VectorOfInt weights, VectorOfDouble levelWeights) { cveGroupRectangles3(rectList, groupThreshold, eps, weights, levelWeights); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveGroupRectangles3(IntPtr rectList, int groupThreshold, double eps, IntPtr weights, IntPtr levelWeights); public static void GroupRectangles(VectorOfRect rectList, VectorOfInt rejectLevels, VectorOfDouble levelWeights, int groupThreshold, double eps = 0.2) { cveGroupRectangles4(rectList, rejectLevels, levelWeights, groupThreshold, eps); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveGroupRectangles4(IntPtr rectList, IntPtr rejectLevels, IntPtr levelWeights, int groupThreshold, double eps); public static void GroupRectanglesMeanshift(VectorOfRect rectList, VectorOfDouble foundWeights, VectorOfDouble foundScales, double detectThreshold, Size winDetSize) { cveGroupRectanglesMeanshift(rectList, foundWeights, foundScales, detectThreshold, ref winDetSize); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveGroupRectanglesMeanshift(IntPtr rectList, IntPtr foundWeights, IntPtr foundScales, double detectThreshold, ref Size winDetSize); public static SolveLPResult SolveLP(Mat functionMatrix, Mat constraintMatrix, Mat zMatrix) { return cveSolveLP(functionMatrix, constraintMatrix, zMatrix); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern SolveLPResult cveSolveLP(IntPtr functionMatrix, IntPtr constraintMatrix, IntPtr zMatrix); public static void DenoiseTVL1(Mat[] observations, Mat result, double lambda, int niters) { using VectorOfMat vectorOfMat = new VectorOfMat(observations); cveDenoiseTVL1(vectorOfMat, result, lambda, niters); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveDenoiseTVL1(IntPtr observations, IntPtr result, double lambda, int niters); public static void Inpaint(IInputArray src, IInputArray mask, IOutputArray dst, double inpaintRadius, InpaintType flags) { using InputArray inputArray = src.GetInputArray(); using InputArray inputArray2 = mask.GetInputArray(); using OutputArray outputArray = dst.GetOutputArray(); cveInpaint(inputArray, inputArray2, outputArray, inpaintRadius, flags); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveInpaint(IntPtr src, IntPtr mask, IntPtr dst, double inpaintRadius, InpaintType flags); public static void FastNlMeansDenoising(IInputArray src, IOutputArray dst, float h = 3f, int templateWindowSize = 7, int searchWindowSize = 21) { using InputArray inputArray = src.GetInputArray(); using OutputArray outputArray = dst.GetOutputArray(); cveFastNlMeansDenoising(inputArray, outputArray, h, templateWindowSize, searchWindowSize); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveFastNlMeansDenoising(IntPtr src, IntPtr dst, float h, int templateWindowSize, int searchWindowSize); public static void FastNlMeansDenoisingColored(IInputArray src, IOutputArray dst, float h = 3f, float hColor = 3f, int templateWindowSize = 7, int searchWindowSize = 21) { using InputArray inputArray = src.GetInputArray(); using OutputArray outputArray = dst.GetOutputArray(); cveFastNlMeansDenoisingColored(inputArray, outputArray, h, hColor, templateWindowSize, searchWindowSize); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveFastNlMeansDenoisingColored(IntPtr src, IntPtr dst, float h, float hColor, int templateWindowSize, int searchWindowSize); public static void EdgePreservingFilter(IInputArray src, IOutputArray dst, EdgePreservingFilterFlag flags = EdgePreservingFilterFlag.RecursFilter, float sigmaS = 60f, float sigmaR = 0.4f) { using InputArray inputArray = src.GetInputArray(); using OutputArray outputArray = dst.GetOutputArray(); cveEdgePreservingFilter(inputArray, outputArray, flags, sigmaS, sigmaR); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveEdgePreservingFilter(IntPtr src, IntPtr dst, EdgePreservingFilterFlag flags, float sigmaS, float sigmaR); public static void DetailEnhance(IInputArray src, IOutputArray dst, float sigmaS = 10f, float sigmaR = 0.15f) { using InputArray inputArray = src.GetInputArray(); using OutputArray outputArray = dst.GetOutputArray(); cveDetailEnhance(inputArray, outputArray, sigmaS, sigmaR); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveDetailEnhance(IntPtr src, IntPtr dst, float sigmaS, float sigmaR); public static void PencilSketch(IInputArray src, IOutputArray dst1, IOutputArray dst2, float sigmaS = 60f, float sigmaR = 0.07f, float shadeFactor = 0.02f) { using InputArray inputArray = src.GetInputArray(); using OutputArray outputArray = dst1.GetOutputArray(); using OutputArray outputArray2 = dst2.GetOutputArray(); cvePencilSketch(inputArray, outputArray, outputArray2, sigmaS, sigmaR, shadeFactor); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cvePencilSketch(IntPtr src, IntPtr dst1, IntPtr dst2, float sigmaS, float sigmaR, float shadeFactor); public static void Stylization(IInputArray src, IOutputArray dst, float sigmaS = 60f, float sigmaR = 0.45f) { using InputArray inputArray = src.GetInputArray(); using OutputArray outputArray = dst.GetOutputArray(); cveStylization(inputArray, outputArray, sigmaS, sigmaR); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveStylization(IntPtr src, IntPtr dst, float sigmaS, float sigmaR); public static void ColorChange(IInputArray src, IInputArray mask, IOutputArray dst, float redMul = 1f, float greenMul = 1f, float blueMul = 1f) { using InputArray inputArray = src.GetInputArray(); using OutputArray outputArray = dst.GetOutputArray(); using InputArray inputArray2 = ((mask == null) ? InputArray.GetEmpty() : mask.GetInputArray()); cveColorChange(inputArray, inputArray2, outputArray, redMul, greenMul, blueMul); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveColorChange(IntPtr src, IntPtr mask, IntPtr dst, float redMul, float greenMul, float blueMul); public static void IlluminationChange(IInputArray src, IInputArray mask, IOutputArray dst, float alpha = 0.2f, float beta = 0.4f) { using InputArray inputArray = src.GetInputArray(); using OutputArray outputArray = dst.GetOutputArray(); using InputArray inputArray2 = ((mask == null) ? InputArray.GetEmpty() : mask.GetInputArray()); cveIlluminationChange(inputArray, inputArray2, outputArray, alpha, beta); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveIlluminationChange(IntPtr src, IntPtr mask, IntPtr dst, float alpha, float beta); public static void TextureFlattening(IInputArray src, IInputArray mask, IOutputArray dst, float lowThreshold = 30f, float highThreshold = 45f, int kernelSize = 3) { using InputArray inputArray = src.GetInputArray(); using OutputArray outputArray = dst.GetOutputArray(); using InputArray inputArray2 = ((mask == null) ? InputArray.GetEmpty() : mask.GetInputArray()); cveTextureFlattening(inputArray, inputArray2, outputArray, lowThreshold, highThreshold, kernelSize); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveTextureFlattening(IntPtr src, IntPtr mask, IntPtr dst, float lowThreshold, float highThreshold, int kernelSize); public static void Decolor(IInputArray src, IOutputArray grayscale, IOutputArray colorBoost) { using InputArray inputArray = src.GetInputArray(); using OutputArray outputArray = grayscale.GetOutputArray(); using OutputArray outputArray2 = colorBoost.GetOutputArray(); cveDecolor(inputArray, outputArray, outputArray2); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveDecolor(IntPtr src, IntPtr grayscale, IntPtr colorBoost); public static void SeamlessClone(IInputArray src, IInputArray dst, IInputArray mask, Point p, IOutputArray blend, CloningMethod flags) { using InputArray inputArray = src.GetInputArray(); using InputArray inputArray2 = dst.GetInputArray(); using InputArray inputArray3 = mask.GetInputArray(); using OutputArray outputArray = blend.GetOutputArray(); cveSeamlessClone(inputArray, inputArray2, inputArray3, ref p, outputArray, flags); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveSeamlessClone(IntPtr src, IntPtr dst, IntPtr mask, ref Point p, IntPtr blend, CloningMethod flags); public static RotatedRect CamShift(IInputArray probImage, ref Rectangle window, MCvTermCriteria criteria) { RotatedRect box = default(RotatedRect); using InputArray inputArray = probImage.GetInputArray(); cveCamShift(inputArray, ref window, ref criteria, ref box); return box; } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveCamShift(IntPtr probImage, ref Rectangle window, ref MCvTermCriteria criteria, ref RotatedRect box); public static int MeanShift(IInputArray probImage, ref Rectangle window, MCvTermCriteria criteria) { using InputArray inputArray = probImage.GetInputArray(); return cveMeanShift(inputArray, ref window, ref criteria); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern int cveMeanShift(IntPtr probImage, ref Rectangle window, ref MCvTermCriteria criteria); public static int BuildOpticalFlowPyramid(IInputArray img, IOutputArrayOfArrays pyramid, Size winSize, int maxLevel, bool withDerivatives = true, BorderType pyrBorder = BorderType.Reflect101, BorderType derivBorder = BorderType.Constant, bool tryReuseInputImage = true) { using InputArray inputArray = img.GetInputArray(); using OutputArray outputArray = pyramid.GetOutputArray(); return cveBuildOpticalFlowPyramid(inputArray, outputArray, ref winSize, maxLevel, withDerivatives, pyrBorder, derivBorder, tryReuseInputImage); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern int cveBuildOpticalFlowPyramid(IntPtr img, IntPtr pyramid, ref Size winSize, int maxLevel, bool withDerivatives, BorderType pyrBorder, BorderType derivBorder, bool tryReuseInputImage); public static void UpdateMotionHistory(IInputArray silhouette, IInputOutputArray mhi, double timestamp, double duration) { using InputArray inputArray = silhouette.GetInputArray(); using InputOutputArray inputOutputArray = mhi.GetInputOutputArray(); cveUpdateMotionHistory(inputArray, inputOutputArray, timestamp, duration); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveUpdateMotionHistory(IntPtr silhouette, IntPtr mhi, double timestamp, double duration); public static void CalcMotionGradient(IInputArray mhi, IOutputArray mask, IOutputArray orientation, double delta1, double delta2, int apertureSize = 3) { using InputArray inputArray = mhi.GetInputArray(); using OutputArray outputArray = mask.GetOutputArray(); using OutputArray outputArray2 = orientation.GetOutputArray(); cveCalcMotionGradient(inputArray, outputArray, outputArray2, delta1, delta2, apertureSize); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveCalcMotionGradient(IntPtr mhi, IntPtr mask, IntPtr orientation, double delta1, double delta2, int apertureSize); public static void SegmentMotion(IInputArray mhi, IOutputArray segMask, VectorOfRect boundingRects, double timestamp, double segThresh) { using InputArray inputArray = mhi.GetInputArray(); using OutputArray outputArray = segMask.GetOutputArray(); cveSegmentMotion(inputArray, outputArray, boundingRects, timestamp, segThresh); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveSegmentMotion(IntPtr mhi, IntPtr segMask, IntPtr boundingRects, double timestamp, double segThresh); public static double CalcGlobalOrientation(IInputArray orientation, IInputArray mask, IInputArray mhi, double timestamp, double duration) { using InputArray inputArray = orientation.GetInputArray(); using InputArray inputArray2 = mask.GetInputArray(); using InputArray inputArray3 = mhi.GetInputArray(); return cveCalcGlobalOrientation(inputArray, inputArray2, inputArray3, timestamp, duration); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern double cveCalcGlobalOrientation(IntPtr orientation, IntPtr mask, IntPtr mhi, double timestamp, double duration); public static void CalcOpticalFlowPyrLK(IInputArray prev, IInputArray curr, PointF[] prevFeatures, Size winSize, int level, MCvTermCriteria criteria, out PointF[] currFeatures, out byte[] status, out float[] trackError, LKFlowFlag flags = LKFlowFlag.Default, double minEigThreshold = 0.0001) { using VectorOfPointF vectorOfPointF = new VectorOfPointF(); using VectorOfPointF vectorOfPointF2 = new VectorOfPointF(); using VectorOfByte vectorOfByte = new VectorOfByte(); using VectorOfFloat vectorOfFloat = new VectorOfFloat(); vectorOfPointF.Push(prevFeatures); CalcOpticalFlowPyrLK(prev, curr, vectorOfPointF, vectorOfPointF2, vectorOfByte, vectorOfFloat, winSize, level, criteria, flags, minEigThreshold); status = vectorOfByte.ToArray(); trackError = vectorOfFloat.ToArray(); currFeatures = vectorOfPointF2.ToArray(); } public static void CalcOpticalFlowPyrLK(IInputArray prevImg, IInputArray nextImg, IInputArray prevPts, IInputOutputArray nextPts, IOutputArray status, IOutputArray err, Size winSize, int maxLevel, MCvTermCriteria criteria, LKFlowFlag flags = LKFlowFlag.Default, double minEigThreshold = 0.0001) { using InputArray inputArray = prevImg.GetInputArray(); using InputArray inputArray2 = nextImg.GetInputArray(); using InputArray inputArray3 = prevPts.GetInputArray(); using InputOutputArray inputOutputArray = nextPts.GetInputOutputArray(); using OutputArray outputArray = status.GetOutputArray(); using OutputArray outputArray2 = err.GetOutputArray(); cveCalcOpticalFlowPyrLK(inputArray, inputArray2, inputArray3, inputOutputArray, outputArray, outputArray2, ref winSize, maxLevel, ref criteria, flags, minEigThreshold); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveCalcOpticalFlowPyrLK(IntPtr prevImg, IntPtr nextImg, IntPtr prevPts, IntPtr nextPts, IntPtr status, IntPtr err, ref Size winSize, int maxLevel, ref MCvTermCriteria criteria, LKFlowFlag flags, double minEigenThreshold); public static void CalcOpticalFlowFarneback(Image prev0, Image next0, Image flowX, Image flowY, double pyrScale, int levels, int winSize, int iterations, int polyN, double polySigma, OpticalflowFarnebackFlag flags) { using Mat mat = new Mat(prev0.Height, prev0.Width, DepthType.Cv32F, 2); using VectorOfMat mv = new VectorOfMat(flowX.Mat, flowY.Mat); if ((flags & OpticalflowFarnebackFlag.UseInitialFlow) != 0) { Merge(mv, mat); } CalcOpticalFlowFarneback(prev0, next0, mat, pyrScale, levels, winSize, iterations, polyN, polySigma, flags); Split(mat, mv); } public static void CalcOpticalFlowFarneback(IInputArray prev0, IInputArray next0, IInputOutputArray flow, double pyrScale, int levels, int winSize, int iterations, int polyN, double polySigma, OpticalflowFarnebackFlag flags) { using InputArray inputArray = prev0.GetInputArray(); using InputArray inputArray2 = next0.GetInputArray(); using InputOutputArray inputOutputArray = flow.GetInputOutputArray(); cveCalcOpticalFlowFarneback(inputArray, inputArray2, inputOutputArray, pyrScale, levels, winSize, iterations, polyN, polySigma, flags); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveCalcOpticalFlowFarneback(IntPtr prev0, IntPtr next0, IntPtr flow0, double pyrScale, int levels, int winSize, int iterations, int polyN, double polySigma, OpticalflowFarnebackFlag flags); public static double FindTransformECC(IInputArray templateImage, IInputArray inputImage, IInputOutputArray warpMatrix, MotionType motionType, MCvTermCriteria criteria, IInputArray inputMask = null) { using InputArray inputArray = templateImage.GetInputArray(); using InputArray inputArray2 = inputImage.GetInputArray(); using InputOutputArray inputOutputArray = warpMatrix.GetInputOutputArray(); using InputArray inputArray3 = ((inputMask == null) ? InputArray.GetEmpty() : inputMask.GetInputArray()); return cveFindTransformECC(inputArray, inputArray2, inputOutputArray, motionType, ref criteria, inputArray3); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern double cveFindTransformECC(IntPtr templateImage, IntPtr inputImage, IntPtr warpMatrix, MotionType motionType, ref MCvTermCriteria criteria, IntPtr inputMask); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr DataLoggerCreate(int logLevel, int loggerId); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void DataLoggerRelease(ref IntPtr logger); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void DataLoggerRegisterCallback(IntPtr logger, DataLoggerHelper.DataCallback messageCallback); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void DataLoggerLog(IntPtr logger, IntPtr data, int logLevel); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cvGetImageSubRect(IntPtr imagePtr, ref Rectangle rect); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveMemcpy(IntPtr dst, IntPtr src, int length); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr tbbTaskSchedulerInit(); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void tbbTaskSchedulerRelease(ref IntPtr scheduler); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int zlib_compress_bound(int length); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void zlib_compress2(IntPtr dataCompressed, ref int sizeDataCompressed, IntPtr dataOriginal, int sizeDataOriginal, int compressionLevel); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void zlib_uncompress(IntPtr dataUncompressed, ref int sizeDataUncompressed, IntPtr compressedData, int sizeDataCompressed); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveAlignExposuresProcess(IntPtr alignExposures, IntPtr src, IntPtr dst, IntPtr times, IntPtr response); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveAlignMTBCreate(int maxBits, int excludeRange, [MarshalAs(UnmanagedType.U1)] bool cut, ref IntPtr alignExposures, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveAlignMTBRelease(ref IntPtr alignExposures, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveCalibrateCRFProcess(IntPtr calibrateCRF, IntPtr src, IntPtr dst, IntPtr times); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveCalibrateDebevecCreate(int samples, float lambda, [MarshalAs(UnmanagedType.U1)] bool random, ref IntPtr calibrateCRF, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveCalibrateDebevecRelease(ref IntPtr calibrateDebevec, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveCalibrateRobertsonCreate(int maxIter, float threshold, ref IntPtr calibrateCRF, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveCalibrateRobertsonRelease(ref IntPtr calibrateRobertson, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveMergeExposuresProcess(IntPtr mergeExposures, IntPtr src, IntPtr dst, IntPtr times, IntPtr response); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveMergeDebevecCreate(ref IntPtr merge, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveMergeDebevecRelease(ref IntPtr merge, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveMergeMertensCreate(float contrastWeight, float saturationWeight, float exposureWeight, ref IntPtr merge, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveMergeMertensRelease(ref IntPtr merge, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveMergeRobertsonCreate(ref IntPtr merge, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveMergeRobertsonRelease(ref IntPtr merge, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveTonemapProcess(IntPtr tonemap, IntPtr src, IntPtr dst); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveTonemapCreate(float gamma, ref IntPtr algorithm, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveTonemapRelease(ref IntPtr tonemap, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern float cveTonemapGetGamma(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveTonemapSetGamma(IntPtr obj, float val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveTonemapDragoCreate(float gamma, float saturation, float bias, ref IntPtr tonemap, ref IntPtr algorithm, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveTonemapDragoRelease(ref IntPtr tonemap, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern float cveTonemapDragoGetSaturation(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveTonemapDragoSetSaturation(IntPtr obj, float val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern float cveTonemapDragoGetBias(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveTonemapDragoSetBias(IntPtr obj, float val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveTonemapMantiukCreate(float gamma, float scale, float saturation, ref IntPtr tonemap, ref IntPtr algorithm, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveTonemapMantiukRelease(ref IntPtr tonemap, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern float cveTonemapMantiukGetSaturation(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveTonemapMantiukSetSaturation(IntPtr obj, float val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern float cveTonemapMantiukGetScale(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveTonemapMantiukSetScale(IntPtr obj, float val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveTonemapReinhardCreate(float gamma, float intensity, float lightAdapt, float colorAdapt, ref IntPtr tonemap, ref IntPtr algorithm, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveTonemapReinhardRelease(ref IntPtr tonemap, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern float cveTonemapReinhardGetIntensity(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveTonemapReinhardSetIntensity(IntPtr obj, float val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern float cveTonemapReinhardGetLightAdaptation(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveTonemapReinhardSetLightAdaptation(IntPtr obj, float val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern float cveTonemapReinhardGetColorAdaptation(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveTonemapReinhardSetColorAdaptation(IntPtr obj, float val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveViz3dCreate(IntPtr s); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveViz3dShowWidget(IntPtr viz, IntPtr id, IntPtr widget, IntPtr pose); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveViz3dSetWidgetPose(IntPtr viz, IntPtr id, IntPtr pose); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveViz3dRemoveWidget(IntPtr viz, IntPtr id); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveViz3dSpin(IntPtr viz); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveViz3dSpinOnce(IntPtr viz, int time, [MarshalAs(UnmanagedType.U1)] bool forceRedraw); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.U1)] internal static extern bool cveViz3dWasStopped(IntPtr viz); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveViz3dSetBackgroundMeshLab(IntPtr viz); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveViz3dRelease(ref IntPtr viz); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveWArrowCreate(ref MCvPoint3D64f pt1, ref MCvPoint3D64f pt2, double thickness, ref MCvScalar color, ref IntPtr widget3d, ref IntPtr widget); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveWArrowRelease(ref IntPtr arrow); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveWCircleCreateAtOrigin(double radius, double thickness, ref MCvScalar color, ref IntPtr widget3d, ref IntPtr widget); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveWCircleCreate(double radius, ref MCvPoint3D64f center, ref MCvPoint3D64f normal, double thickness, ref MCvScalar color, ref IntPtr widget3d, ref IntPtr widget); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveWCircleRelease(ref IntPtr circle); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveWCloudCreateWithColorArray(IntPtr cloud, IntPtr color, ref IntPtr widget3d, ref IntPtr widget); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveWCloudCreateWithColor(IntPtr cloud, ref MCvScalar color, ref IntPtr widget3d, ref IntPtr widget); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveWCloudRelease(ref IntPtr cloud); public static Mat ReadCloud(string file, IOutputArray colors = null, IOutputArray normals = null) { using CvString cvString = new CvString(file); using OutputArray outputArray = ((colors == null) ? OutputArray.GetEmpty() : colors.GetOutputArray()); using OutputArray outputArray2 = ((normals == null) ? OutputArray.GetEmpty() : normals.GetOutputArray()); Mat mat = new Mat(); cveReadCloud(cvString, mat, outputArray, outputArray2); return mat; } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveReadCloud(IntPtr file, IntPtr cloud, IntPtr colors, IntPtr normals); public static void WriteCloud(string file, IInputArray cloud, IInputArray colors = null, IInputArray normals = null) { using CvString cvString = new CvString(file); using InputArray inputArray = cloud.GetInputArray(); using InputArray inputArray2 = ((colors == null) ? InputArray.GetEmpty() : colors.GetInputArray()); using InputArray inputArray3 = ((normals == null) ? InputArray.GetEmpty() : normals.GetInputArray()); cveWriteCloud(cvString, inputArray, inputArray2, inputArray3); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveWriteCloud(IntPtr file, IntPtr cloud, IntPtr colors, IntPtr normals); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveWConeCreateAtOrigin(double length, double radius, int resolution, ref MCvScalar color, ref IntPtr widget3d, ref IntPtr widget); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveWConeCreate(double radius, ref MCvPoint3D64f center, ref MCvPoint3D64f tip, int resolution, ref MCvScalar color, ref IntPtr widget3d, ref IntPtr widget); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveWConeRelease(ref IntPtr cone); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveWCoordinateSystemCreate(double scale, ref IntPtr widget3d, ref IntPtr widget); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveWCoordinateSystemRelease(ref IntPtr system); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveWCubeCreate(ref MCvPoint3D64f minPoint, ref MCvPoint3D64f maxPoint, [MarshalAs(UnmanagedType.U1)] bool wireFrame, ref MCvScalar color, ref IntPtr widget3d, ref IntPtr widget); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveWCubeRelease(ref IntPtr cube); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveWCylinderCreate(ref MCvPoint3D64f axisPoint1, ref MCvPoint3D64f axisPoint2, double radius, int numsides, ref MCvScalar color, ref IntPtr widget3d, ref IntPtr widget); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveWCylinderRelease(ref IntPtr cylinder); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveWTextCreate(IntPtr text, ref Point pos, int fontSize, ref MCvScalar color, ref IntPtr widget2D, ref IntPtr widget); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveWTextRelease(ref IntPtr text); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveBackgroundSubtractorUpdate(IntPtr bgSubtractor, IntPtr image, IntPtr fgmask, double learningRate); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveBackgroundSubtractorGetBackgroundImage(IntPtr bgSubtractor, IntPtr backgroundImage); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveBackgroundSubtractorKNNCreate(int history, double dist2Threshold, [MarshalAs(UnmanagedType.U1)] bool detectShadows, ref IntPtr bgSubtractor, ref IntPtr algorithm, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveBackgroundSubtractorKNNRelease(ref IntPtr bgSubstractor, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int cveBackgroundSubtractorKNNGetHistory(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveBackgroundSubtractorKNNSetHistory(IntPtr obj, int val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int cveBackgroundSubtractorKNNGetNSamples(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveBackgroundSubtractorKNNSetNSamples(IntPtr obj, int val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern double cveBackgroundSubtractorKNNGetDist2Threshold(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveBackgroundSubtractorKNNSetDist2Threshold(IntPtr obj, double val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int cveBackgroundSubtractorKNNGetKNNSamples(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveBackgroundSubtractorKNNSetKNNSamples(IntPtr obj, int val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.U1)] internal static extern bool cveBackgroundSubtractorKNNGetDetectShadows(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveBackgroundSubtractorKNNSetDetectShadows(IntPtr obj, [MarshalAs(UnmanagedType.U1)] bool val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int cveBackgroundSubtractorKNNGetShadowValue(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveBackgroundSubtractorKNNSetShadowValue(IntPtr obj, int val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern double cveBackgroundSubtractorKNNGetShadowThreshold(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveBackgroundSubtractorKNNSetShadowThreshold(IntPtr obj, double val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveBackgroundSubtractorMOG2Create(int history, float varThreshold, [MarshalAs(UnmanagedType.U1)] bool bShadowDetection, ref IntPtr bgSubtractor, ref IntPtr algorithm, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveBackgroundSubtractorMOG2Release(ref IntPtr bgSubstractor, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int cveBackgroundSubtractorMOG2GetHistory(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveBackgroundSubtractorMOG2SetHistory(IntPtr obj, int val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.U1)] internal static extern bool cveBackgroundSubtractorMOG2GetDetectShadows(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveBackgroundSubtractorMOG2SetDetectShadows(IntPtr obj, [MarshalAs(UnmanagedType.U1)] bool val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int cveBackgroundSubtractorMOG2GetShadowValue(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveBackgroundSubtractorMOG2SetShadowValue(IntPtr obj, int val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern double cveBackgroundSubtractorMOG2GetShadowThreshold(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveBackgroundSubtractorMOG2SetShadowThreshold(IntPtr obj, double val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int cveBackgroundSubtractorMOG2GetNMixtures(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveBackgroundSubtractorMOG2SetNMixtures(IntPtr obj, int val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern double cveBackgroundSubtractorMOG2GetBackgroundRatio(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveBackgroundSubtractorMOG2SetBackgroundRatio(IntPtr obj, double val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern double cveBackgroundSubtractorMOG2GetVarThreshold(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveBackgroundSubtractorMOG2SetVarThreshold(IntPtr obj, double val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern double cveBackgroundSubtractorMOG2GetVarThresholdGen(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveBackgroundSubtractorMOG2SetVarThresholdGen(IntPtr obj, double val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern double cveBackgroundSubtractorMOG2GetVarInit(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveBackgroundSubtractorMOG2SetVarInit(IntPtr obj, double val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern double cveBackgroundSubtractorMOG2GetVarMin(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveBackgroundSubtractorMOG2SetVarMin(IntPtr obj, double val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern double cveBackgroundSubtractorMOG2GetVarMax(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveBackgroundSubtractorMOG2SetVarMax(IntPtr obj, double val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern double cveBackgroundSubtractorMOG2GetComplexityReductionThreshold(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveBackgroundSubtractorMOG2SetComplexityReductionThreshold(IntPtr obj, double val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveDenseOpticalFlowCalc(IntPtr dof, IntPtr i0, IntPtr i1, IntPtr flow); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveDenseOpticalFlowRelease(ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveDISOpticalFlowCreate(DISOpticalFlow.Preset preset, ref IntPtr denseFlow, ref IntPtr algorithm, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveDISOpticalFlowRelease(ref IntPtr flow, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int cveDISOpticalFlowGetFinestScale(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveDISOpticalFlowSetFinestScale(IntPtr obj, int val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int cveDISOpticalFlowGetPatchSize(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveDISOpticalFlowSetPatchSize(IntPtr obj, int val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int cveDISOpticalFlowGetPatchStride(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveDISOpticalFlowSetPatchStride(IntPtr obj, int val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int cveDISOpticalFlowGetGradientDescentIterations(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveDISOpticalFlowSetGradientDescentIterations(IntPtr obj, int val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int cveDISOpticalFlowGetVariationalRefinementIterations(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveDISOpticalFlowSetVariationalRefinementIterations(IntPtr obj, int val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern float cveDISOpticalFlowGetVariationalRefinementAlpha(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveDISOpticalFlowSetVariationalRefinementAlpha(IntPtr obj, float val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern float cveDISOpticalFlowGetVariationalRefinementDelta(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveDISOpticalFlowSetVariationalRefinementDelta(IntPtr obj, float val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern float cveDISOpticalFlowGetVariationalRefinementGamma(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveDISOpticalFlowSetVariationalRefinementGamma(IntPtr obj, float val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.U1)] internal static extern bool cveDISOpticalFlowGetUseMeanNormalization(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveDISOpticalFlowSetUseMeanNormalization(IntPtr obj, [MarshalAs(UnmanagedType.U1)] bool val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.U1)] internal static extern bool cveDISOpticalFlowGetUseSpatialPropagation(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveDISOpticalFlowSetUseSpatialPropagation(IntPtr obj, [MarshalAs(UnmanagedType.U1)] bool val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveFarnebackOpticalFlowRelease(ref IntPtr flow, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveFarnebackOpticalFlowCreate(int numLevels, double pyrScale, [MarshalAs(UnmanagedType.U1)] bool fastPyramids, int winSize, int numIters, int polyN, double polySigma, OpticalflowFarnebackFlag flags, ref IntPtr denseOpticalFlow, ref IntPtr algorithm, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveKalmanFilterCreate(int dynamParams, int measureParams, int controlParams, DepthType type); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveKalmanFilterRelease(ref IntPtr filter); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveKalmanFilterPredict(IntPtr kalman, IntPtr control); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveKalmanFilterCorrect(IntPtr kalman, IntPtr measurement); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveKalmanFilterGetStatePre(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveKalmanFilterGetStatePost(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveKalmanFilterGetTransitionMatrix(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveKalmanFilterGetControlMatrix(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveKalmanFilterGetMeasurementMatrix(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveKalmanFilterGetProcessNoiseCov(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveKalmanFilterGetMeasurementNoiseCov(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveKalmanFilterGetErrorCovPre(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveKalmanFilterGetGain(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveKalmanFilterGetErrorCovPost(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveSparseOpticalFlowCalc(IntPtr sof, IntPtr prevImg, IntPtr nextImg, IntPtr prevPts, IntPtr nextPts, IntPtr status, IntPtr err); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveSparsePyrLKOpticalFlowCreate(ref Size winSize, int maxLevel, ref MCvTermCriteria crit, LKFlowFlag flags, double minEigThreshold, ref IntPtr sparseOpticalFlow, ref IntPtr algorithm, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveSparsePyrLKOpticalFlowRelease(ref IntPtr flow, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveTrackerInit(IntPtr tracker, IntPtr image, ref Rectangle boundingBox); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.U1)] internal static extern bool cveTrackerUpdate(IntPtr tracker, IntPtr image, ref Rectangle boundingBox); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveTrackerDaSiamRPNCreate(IntPtr model, IntPtr kernel_cls1, IntPtr kernel_r1, Emgu.CV.Dnn.Backend backend, Target target, ref IntPtr tracker, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveTrackerDaSiamRPNRelease(ref IntPtr tracker, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern float cveTrackerDaSiamRPNGetTrackingScore(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveTrackerGOTURNCreate(ref IntPtr tracker, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveTrackerGOTURNRelease(ref IntPtr tracker, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveTrackerMILCreate(float samplerInitInRadius, int samplerInitMaxNegNum, float samplerSearchWinSize, float samplerTrackInRadius, int samplerTrackMaxPosNum, int samplerTrackMaxNegNum, int featureSetNumFeatures, ref IntPtr tracker, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveTrackerMILRelease(ref IntPtr tracker, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveVariationalRefinementCreate(ref IntPtr denseFlow, ref IntPtr algorithm, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveVariationalRefinementRelease(ref IntPtr flow, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int cveVariationalRefinementGetFixedPointIterations(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveVariationalRefinementSetFixedPointIterations(IntPtr obj, int val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int cveVariationalRefinementGetSorIterations(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveVariationalRefinementSetSorIterations(IntPtr obj, int val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern float cveVariationalRefinementGetOmega(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveVariationalRefinementSetOmega(IntPtr obj, float val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern float cveVariationalRefinementGetAlpha(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveVariationalRefinementSetAlpha(IntPtr obj, float val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern float cveVariationalRefinementGetDelta(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveVariationalRefinementSetDelta(IntPtr obj, float val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern float cveVariationalRefinementGetGamma(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveVariationalRefinementSetGamma(IntPtr obj, float val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveDenseRLOFOpticalFlowRelease(ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveDenseRLOFOpticalFlowCreate(IntPtr rlofParameter, float forwardBackwardThreshold, ref Size gridStep, DenseRLOFOpticalFlow.InterpolationType interpType, int epicK, float epicSigma, float epicLambda, [MarshalAs(UnmanagedType.U1)] bool usePostProc, float fgsLambda, float fgsSigma, ref IntPtr denseOpticalFlow, ref IntPtr algorithm, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveDualTVL1OpticalFlowRelease(ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveDenseOpticalFlowCreateDualTVL1(ref IntPtr denseOpticalFlow, ref IntPtr algorithm, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern double cveDualTVL1OpticalFlowGetTau(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveDualTVL1OpticalFlowSetTau(IntPtr obj, double val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern double cveDualTVL1OpticalFlowGetLambda(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveDualTVL1OpticalFlowSetLambda(IntPtr obj, double val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern double cveDualTVL1OpticalFlowGetTheta(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveDualTVL1OpticalFlowSetTheta(IntPtr obj, double val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern double cveDualTVL1OpticalFlowGetGamma(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveDualTVL1OpticalFlowSetGamma(IntPtr obj, double val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int cveDualTVL1OpticalFlowGetScalesNumber(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveDualTVL1OpticalFlowSetScalesNumber(IntPtr obj, int val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int cveDualTVL1OpticalFlowGetWarpingsNumber(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveDualTVL1OpticalFlowSetWarpingsNumber(IntPtr obj, int val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern double cveDualTVL1OpticalFlowGetEpsilon(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveDualTVL1OpticalFlowSetEpsilon(IntPtr obj, double val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int cveDualTVL1OpticalFlowGetInnerIterations(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveDualTVL1OpticalFlowSetInnerIterations(IntPtr obj, int val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int cveDualTVL1OpticalFlowGetOuterIterations(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveDualTVL1OpticalFlowSetOuterIterations(IntPtr obj, int val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.U1)] internal static extern bool cveDualTVL1OpticalFlowGetUseInitialFlow(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveDualTVL1OpticalFlowSetUseInitialFlow(IntPtr obj, [MarshalAs(UnmanagedType.U1)] bool val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern double cveDualTVL1OpticalFlowGetScaleStep(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveDualTVL1OpticalFlowSetScaleStep(IntPtr obj, double val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int cveDualTVL1OpticalFlowGetMedianFiltering(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveDualTVL1OpticalFlowSetMedianFiltering(IntPtr obj, int val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveOptFlowDeepFlowCreate(ref IntPtr algorithm, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveOptFlowPCAFlowCreate(ref IntPtr algorithm, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveRLOFOpticalFlowParameterCreate(); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveRLOFOpticalFlowParameterRelease(ref IntPtr p); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern float cveRLOFOpticalFlowParameterGetNormSigma0(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveRLOFOpticalFlowParameterSetNormSigma0(IntPtr obj, float val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern float cveRLOFOpticalFlowParameterGetNormSigma1(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveRLOFOpticalFlowParameterSetNormSigma1(IntPtr obj, float val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern RLOFOpticalFlowParameter.SolverType cveRLOFOpticalFlowParameterGetSolver(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveRLOFOpticalFlowParameterSetSolver(IntPtr obj, RLOFOpticalFlowParameter.SolverType val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern RLOFOpticalFlowParameter.SupportRegionType cveRLOFOpticalFlowParameterGetSupportRegion(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveRLOFOpticalFlowParameterSetSupportRegion(IntPtr obj, RLOFOpticalFlowParameter.SupportRegionType val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int cveRLOFOpticalFlowParameterGetSmallWinSize(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveRLOFOpticalFlowParameterSetSmallWinSize(IntPtr obj, int val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int cveRLOFOpticalFlowParameterGetLargeWinSize(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveRLOFOpticalFlowParameterSetLargeWinSize(IntPtr obj, int val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int cveRLOFOpticalFlowParameterGetCrossSegmentationThreshold(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveRLOFOpticalFlowParameterSetCrossSegmentationThreshold(IntPtr obj, int val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int cveRLOFOpticalFlowParameterGetMaxLevel(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveRLOFOpticalFlowParameterSetMaxLevel(IntPtr obj, int val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.U1)] internal static extern bool cveRLOFOpticalFlowParameterGetUseInitialFlow(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveRLOFOpticalFlowParameterSetUseInitialFlow(IntPtr obj, [MarshalAs(UnmanagedType.U1)] bool val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.U1)] internal static extern bool cveRLOFOpticalFlowParameterGetUseIlluminationModel(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveRLOFOpticalFlowParameterSetUseIlluminationModel(IntPtr obj, [MarshalAs(UnmanagedType.U1)] bool val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.U1)] internal static extern bool cveRLOFOpticalFlowParameterGetUseGlobalMotionPrior(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveRLOFOpticalFlowParameterSetUseGlobalMotionPrior(IntPtr obj, [MarshalAs(UnmanagedType.U1)] bool val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int cveRLOFOpticalFlowParameterGetMaxIteration(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveRLOFOpticalFlowParameterSetMaxIteration(IntPtr obj, int val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern float cveRLOFOpticalFlowParameterGetMinEigenValue(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveRLOFOpticalFlowParameterSetMinEigenValue(IntPtr obj, float val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern float cveRLOFOpticalFlowParameterGetGlobalMotionRansacThreshold(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveRLOFOpticalFlowParameterSetGlobalMotionRansacThreshold(IntPtr obj, float val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveSparseRLOFOpticalFlowRelease(ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveSparseRLOFOpticalFlowCreate(IntPtr rlofParameter, float forwardBackwardThreshold, ref IntPtr sparseOpticalFlow, ref IntPtr algorithm, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveCascadeClassifierCreate(); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveCascadeClassifierCreateFromFile(IntPtr fileName); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.U1)] internal static extern bool cveCascadeClassifierRead(IntPtr classifier, IntPtr node); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveCascadeClassifierRelease(ref IntPtr classifier); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveCascadeClassifierDetectMultiScale(IntPtr classifier, IntPtr image, IntPtr objects, double scaleFactor, int minNeighbors, int flags, ref Size minSize, ref Size maxSize); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.U1)] internal static extern bool cveCascadeClassifierIsOldFormatCascade(IntPtr classifier); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveCascadeClassifierGetOriginalWindowSize(IntPtr classifier, ref Size size); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveFaceDetectorYNCreate(IntPtr model, IntPtr config, ref Size inputSize, float scoreThreshold, float nmsThreshold, int topK, Emgu.CV.Dnn.Backend backendId, Target targetId, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveFaceDetectorYNRelease(ref IntPtr faceDetector); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int cveFaceDetectorYNDetect(IntPtr faceDetector, IntPtr image, IntPtr faces); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveFaceDetectorYNSetScoreThreshold(IntPtr obj, float val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveFaceDetectorYNSetNMSThreshold(IntPtr obj, float val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveFaceDetectorYNSetTopK(IntPtr obj, int val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveFaceDetectorYNGetInputSize(IntPtr obj, ref Size val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveFaceDetectorYNSetInputSize(IntPtr obj, ref Size val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveFaceRecognizerSFCreate(IntPtr model, IntPtr config, Emgu.CV.Dnn.Backend backendId, Target targetId, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveFaceRecognizerSFRelease(ref IntPtr faceRecognizer); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveFaceRecognizerSFAlignCrop(IntPtr faceRecognizer, IntPtr srcImg, IntPtr faceBox, IntPtr alignedImg); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveFaceRecognizerSFFeature(IntPtr faceRecognizer, IntPtr alignedImg, IntPtr faceFeature); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern double cveFaceRecognizerSFMatch(IntPtr faceRecognizer, IntPtr faceFeature1, IntPtr faceFeature2, FaceRecognizerSF.DisType disType); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveHOGDescriptorPeopleDetectorCreate(IntPtr seq); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveHOGDescriptorCreateDefault(); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveHOGDescriptorCreate(ref Size winSize, ref Size blockSize, ref Size blockStride, ref Size cellSize, int nbins, int derivAperture, double winSigma, int histogramNormType, double L2HysThreshold, [MarshalAs(UnmanagedType.U1)] bool gammaCorrection); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveHOGDescriptorRelease(ref IntPtr descriptor); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveHOGSetSVMDetector(IntPtr descriptor, IntPtr svmDetector); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveHOGDescriptorDetectMultiScale(IntPtr descriptor, IntPtr img, IntPtr foundLocations, IntPtr weights, double hitThreshold, ref Size winStride, ref Size padding, double scale, double finalThreshold, [MarshalAs(UnmanagedType.U1)] bool useMeanshiftGrouping); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveHOGDescriptorCompute(IntPtr descriptor, IntPtr img, IntPtr descriptors, ref Size winStride, ref Size padding, IntPtr locations); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern uint cveHOGDescriptorGetDescriptorSize(IntPtr descriptor); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveQRCodeDetectorCreate(); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveQRCodeDetectorRelease(ref IntPtr descriptor); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.U1)] internal static extern bool cveQRCodeDetectorDetect(IntPtr detector, IntPtr input, IntPtr points); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.U1)] internal static extern bool cveQRCodeDetectorDetectMulti(IntPtr detector, IntPtr input, IntPtr points); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveQRCodeDetectorDecode(IntPtr detector, IntPtr img, IntPtr points, IntPtr decodedInfo, IntPtr straightQrcode); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveQRCodeDetectorDecodeCurved(IntPtr detector, IntPtr img, IntPtr points, IntPtr decodedInfo, IntPtr straightQrcode); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.U1)] internal static extern bool cveQRCodeDetectorDecodeMulti(IntPtr detector, IntPtr img, IntPtr points, IntPtr decodedInfo, IntPtr straightQrcode); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveQRCodeDetectorSetEpsX(IntPtr obj, double val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveQRCodeDetectorSetEpsY(IntPtr obj, double val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveIntelligentScissorsMBCreate(); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveIntelligentScissorsMBRelease(ref IntPtr ptr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveIntelligentScissorsMBSetWeights(IntPtr ptr, float weightNonEdge, float weightGradientDirection, float weightGradientMagnitude); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveIntelligentScissorsMBSetEdgeFeatureCannyParameters(IntPtr ptr, double threshold1, double threshold2, int apertureSize, [MarshalAs(UnmanagedType.U1)] bool L2gradient); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveIntelligentScissorsMBApplyImage(IntPtr ptr, IntPtr image); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveIntelligentScissorsMBApplyImageFeatures(IntPtr ptr, IntPtr nonEdge, IntPtr gradientDirection, IntPtr gradientMagnitude, IntPtr image); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveIntelligentScissorsMBBuildMap(IntPtr ptr, ref Point sourcePt); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveIntelligentScissorsMBGetContour(IntPtr ptr, ref Point targetPt, IntPtr contour, [MarshalAs(UnmanagedType.U1)] bool backward); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveIntelligentScissorsMBSetEdgeFeatureZeroCrossingParameters(IntPtr obj, float val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveIntelligentScissorsMBSetGradientMagnitudeMaxLimit(IntPtr obj, float val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveLineIteratorCreate(IntPtr img, ref Point pt1, ref Point pt2, int connectivity, [MarshalAs(UnmanagedType.U1)] bool leftToRight); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveLineIteratorRelease(ref IntPtr iterator); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveLineIteratorGetDataPointer(IntPtr iterator); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveLineIteratorPos(IntPtr iterator, ref Point pos); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveLineIteratorMoveNext(IntPtr iterator); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveLineIteratorSampleLine(IntPtr img, ref Point pt1, ref Point pt2, int connectivity, [MarshalAs(UnmanagedType.U1)] bool leftToRight, IntPtr line); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int cveLineIteratorGetCount(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveLineIteratorSetCount(IntPtr obj, int val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveSubdiv2DCreate(ref Rectangle rect); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveSubdiv2DRelease(ref IntPtr subdiv); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveSubdiv2DInsertMulti(IntPtr subdiv, IntPtr points); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int cveSubdiv2DInsertSingle(IntPtr subdiv, ref PointF pt); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveSubdiv2DGetTriangleList(IntPtr subdiv, IntPtr triangleList); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveSubdiv2DGetVoronoiFacetList(IntPtr subdiv, IntPtr idx, IntPtr facetList, IntPtr facetCenters); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern Subdiv2DPointLocationType cveSubdiv2DFindNearest(IntPtr subdiv, ref PointF pt, ref PointF nearestPt); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern Subdiv2DPointLocationType cveSubdiv2DLocate(IntPtr subdiv, ref PointF pt, ref int edge, ref int vertex); public static void Compute(this IStereoMatcher matcher, IInputArray left, IInputArray right, IOutputArray disparity) { using InputArray inputArray = left.GetInputArray(); using InputArray inputArray2 = right.GetInputArray(); using OutputArray outputArray = disparity.GetOutputArray(); cveStereoMatcherCompute(matcher.StereoMatcherPtr, inputArray, inputArray2, outputArray); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveStereoMatcherCompute(IntPtr disparitySolver, IntPtr left, IntPtr right, IntPtr disparity); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveStereoMatcherRelease(ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveStereoBMCreate(int numberOfDisparities, int blockSize, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveStereoSGBMCreate(int minDisparity, int numDisparities, int blockSize, int P1, int P2, int disp12MaxDiff, int preFilterCap, int uniquenessRatio, int speckleWindowSize, int speckleRange, StereoSGBM.Mode mode, ref IntPtr stereoMatcher, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveStereoSGBMRelease(ref IntPtr sharedPtr); public static void Undistort(IInputArray src, IOutputArray dst, IInputArray cameraMatrix, IInputArray distortionCoeffs, IInputArray newCameraMatrix = null) { using InputArray inputArray = src.GetInputArray(); using OutputArray outputArray = dst.GetOutputArray(); using InputArray inputArray2 = cameraMatrix.GetInputArray(); using InputArray inputArray3 = distortionCoeffs.GetInputArray(); using InputArray inputArray4 = ((newCameraMatrix == null) ? InputArray.GetEmpty() : newCameraMatrix.GetInputArray()); cveUndistort(inputArray, outputArray, inputArray2, inputArray3, inputArray4); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveUndistort(IntPtr src, IntPtr dst, IntPtr cameraMatrix, IntPtr distortionCoeffs, IntPtr newCameraMatrix); public static void InitUndistortRectifyMap(IInputArray cameraMatrix, IInputArray distCoeffs, IInputArray R, IInputArray newCameraMatrix, Size size, DepthType depthType, int channels, IOutputArray map1, IOutputArray map2) { using InputArray inputArray = cameraMatrix.GetInputArray(); using InputArray inputArray2 = distCoeffs.GetInputArray(); using InputArray inputArray3 = ((R == null) ? InputArray.GetEmpty() : R.GetInputArray()); using InputArray inputArray4 = newCameraMatrix.GetInputArray(); using OutputArray outputArray = map1.GetOutputArray(); using OutputArray outputArray2 = ((map2 == null) ? OutputArray.GetEmpty() : map2.GetOutputArray()); cveInitUndistortRectifyMap(inputArray, inputArray2, inputArray3, inputArray4, ref size, MakeType(depthType, channels), outputArray, outputArray2); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveInitUndistortRectifyMap(IntPtr cameraMatrix, IntPtr distCoeffs, IntPtr R, IntPtr newCameraMatrix, ref Size size, int m1type, IntPtr map1, IntPtr map2); public static void UndistortPoints(IInputArray src, IOutputArray dst, IInputArray cameraMatrix, IInputArray distCoeffs, IInputArray R = null, IInputArray P = null) { using InputArray inputArray = src.GetInputArray(); using OutputArray outputArray = dst.GetOutputArray(); using InputArray inputArray2 = cameraMatrix.GetInputArray(); using InputArray inputArray3 = distCoeffs.GetInputArray(); using InputArray inputArray4 = ((R == null) ? InputArray.GetEmpty() : R.GetInputArray()); using InputArray inputArray5 = ((P == null) ? InputArray.GetEmpty() : P.GetInputArray()); cveUndistortPoints(inputArray, outputArray, inputArray2, inputArray3, inputArray4, inputArray5); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveUndistortPoints(IntPtr src, IntPtr dst, IntPtr cameraMatrix, IntPtr distCoeffs, IntPtr R, IntPtr P); public static Mat GetDefaultNewCameraMatrix(IInputArray cameraMatrix, Size imgsize = default(Size), bool centerPrincipalPoint = false) { Mat mat = new Mat(); using InputArray inputArray = cameraMatrix.GetInputArray(); cveGetDefaultNewCameraMatrix(inputArray, ref imgsize, centerPrincipalPoint, mat.Ptr); return mat; } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveGetDefaultNewCameraMatrix(IntPtr cameraMatrix, ref Size imgsize, [MarshalAs(UnmanagedType.U1)] bool centerPrincipalPoint, IntPtr cm); public static Mat EstimateAffine2D(PointF[] from, PointF[] to, IOutputArray inliners = null, RobustEstimationAlgorithm method = RobustEstimationAlgorithm.Ransac, double ransacReprojThreshold = 3.0, int maxIters = 2000, double confidence = 0.99, int refineIters = 10) { using VectorOfPointF from2 = new VectorOfPointF(from); using VectorOfPointF to2 = new VectorOfPointF(to); return EstimateAffine2D(from2, to2, inliners, method, ransacReprojThreshold, maxIters, confidence, refineIters); } public static Mat EstimateAffine2D(IInputArray from, IInputArray to, IOutputArray inliners = null, RobustEstimationAlgorithm method = RobustEstimationAlgorithm.Ransac, double ransacReprojThreshold = 3.0, int maxIters = 2000, double confidence = 0.99, int refineIters = 10) { Mat mat = new Mat(); using InputArray inputArray = from.GetInputArray(); using InputArray inputArray2 = to.GetInputArray(); using OutputArray outputArray = ((inliners == null) ? OutputArray.GetEmpty() : inliners.GetOutputArray()); cveEstimateAffine2D(inputArray, inputArray2, outputArray, method, ransacReprojThreshold, maxIters, confidence, refineIters, mat); return mat; } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveEstimateAffine2D(IntPtr from, IntPtr to, IntPtr inliners, RobustEstimationAlgorithm method, double ransacReprojThreshold, int maxIters, double confidence, int refineIters, IntPtr affine); public static Mat EstimateAffinePartial2D(IInputArray from, IInputArray to, IOutputArray inliners, RobustEstimationAlgorithm method, double ransacReprojThreshold, int maxIters, double confidence, int refineIters) { Mat mat = new Mat(); using InputArray inputArray = from.GetInputArray(); using InputArray inputArray2 = to.GetInputArray(); using OutputArray outputArray = ((inliners == null) ? OutputArray.GetEmpty() : inliners.GetOutputArray()); cveEstimateAffinePartial2D(inputArray, inputArray2, outputArray, method, ransacReprojThreshold, maxIters, confidence, refineIters, mat); return mat; } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveEstimateAffinePartial2D(IntPtr from, IntPtr to, IntPtr inliners, RobustEstimationAlgorithm method, double ransacReprojThreshold, int maxIters, double confidence, int refineIters, IntPtr affine); public static void CalibrateHandEye(IInputArrayOfArrays rGripper2base, IInputArrayOfArrays tGripper2base, IInputArrayOfArrays rTarget2cam, IInputArrayOfArrays tTarget2cam, IOutputArray rCam2gripper, IOutputArray tCam2gripper, HandEyeCalibrationMethod method) { using InputArray inputArray = rGripper2base.GetInputArray(); using InputArray inputArray2 = tGripper2base.GetInputArray(); using InputArray inputArray3 = rTarget2cam.GetInputArray(); using InputArray inputArray4 = tTarget2cam.GetInputArray(); using OutputArray outputArray = rCam2gripper.GetOutputArray(); using OutputArray outputArray2 = tCam2gripper.GetOutputArray(); cveCalibrateHandEye(inputArray, inputArray2, inputArray3, inputArray4, outputArray, outputArray2, method); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveCalibrateHandEye(IntPtr rGripper2base, IntPtr tGripper2base, IntPtr rTarget2cam, IntPtr tTarget2cam, IntPtr rCam2gripper, IntPtr tCam2gripper, HandEyeCalibrationMethod method); public static MCvPoint3D64f RQDecomp3x3(IInputArray src, IOutputArray mtxR, IOutputArray mtxQ, IOutputArray Qx = null, IOutputArray Qy = null, IOutputArray Qz = null) { MCvPoint3D64f result = default(MCvPoint3D64f); using InputArray inputArray = src.GetInputArray(); using OutputArray outputArray = mtxR.GetOutputArray(); using OutputArray outputArray2 = mtxQ.GetOutputArray(); using OutputArray outputArray3 = ((Qx == null) ? OutputArray.GetEmpty() : Qx.GetOutputArray()); using OutputArray outputArray4 = ((Qy == null) ? OutputArray.GetEmpty() : Qy.GetOutputArray()); using OutputArray outputArray5 = ((Qz == null) ? OutputArray.GetEmpty() : Qz.GetOutputArray()); cveRQDecomp3x3(inputArray, ref result, outputArray, outputArray2, outputArray3, outputArray4, outputArray5); return result; } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveRQDecomp3x3(IntPtr src, ref MCvPoint3D64f result, IntPtr mtxR, IntPtr mtxQ, IntPtr Qx, IntPtr Qy, IntPtr Qz); public static void DecomposeProjectionMatrix(IInputArray projMatrix, IOutputArray cameraMatrix, IOutputArray rotMatrix, IOutputArray transVect, IOutputArray rotMatrixX = null, IOutputArray rotMatrixY = null, IOutputArray rotMatrixZ = null, IOutputArray eulerAngles = null) { using InputArray inputArray = projMatrix.GetInputArray(); using OutputArray outputArray = cameraMatrix.GetOutputArray(); using OutputArray outputArray2 = rotMatrix.GetOutputArray(); using OutputArray outputArray3 = transVect.GetOutputArray(); using OutputArray outputArray4 = ((rotMatrixX == null) ? OutputArray.GetEmpty() : rotMatrixX.GetOutputArray()); using OutputArray outputArray5 = ((rotMatrixY == null) ? OutputArray.GetEmpty() : rotMatrixY.GetOutputArray()); using OutputArray outputArray6 = ((rotMatrixZ == null) ? OutputArray.GetEmpty() : rotMatrixZ.GetOutputArray()); using OutputArray outputArray7 = ((eulerAngles == null) ? OutputArray.GetEmpty() : eulerAngles.GetOutputArray()); cveDecomposeProjectionMatrix(inputArray, outputArray, outputArray2, outputArray3, outputArray4, outputArray5, outputArray6, outputArray7); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveDecomposeProjectionMatrix(IntPtr projMatrix, IntPtr cameraMatrix, IntPtr rotMatrix, IntPtr transVect, IntPtr rotMatrixX, IntPtr rotMatrixY, IntPtr rotMatrixZ, IntPtr eulerAngles); public static void DecomposeEssentialMat(IInputArray e, IOutputArray r1, IOutputArray r2, IOutputArray t) { using InputArray inputArray = e.GetInputArray(); using OutputArray outputArray = r1.GetOutputArray(); using OutputArray outputArray2 = r2.GetOutputArray(); using OutputArray outputArray3 = t.GetOutputArray(); cveDecomposeEssentialMat(inputArray, outputArray, outputArray2, outputArray3); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveDecomposeEssentialMat(IntPtr e, IntPtr r1, IntPtr r2, IntPtr t); public static int DecomposeHomographyMat(IInputArray h, IInputArray k, IOutputArrayOfArrays rotations, IOutputArrayOfArrays translations, IOutputArrayOfArrays normals) { using InputArray inputArray = h.GetInputArray(); using InputArray inputArray2 = k.GetInputArray(); using OutputArray outputArray = rotations.GetOutputArray(); using OutputArray outputArray2 = translations.GetOutputArray(); using OutputArray outputArray3 = normals.GetOutputArray(); return cveDecomposeHomographyMat(inputArray, inputArray2, outputArray, outputArray2, outputArray3); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int cveDecomposeHomographyMat(IntPtr h, IntPtr k, IntPtr rotations, IntPtr translations, IntPtr normals); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveFisheyeProjectPoints(IntPtr objectPoints, IntPtr imagePoints, IntPtr rvec, IntPtr tvec, IntPtr K, IntPtr D, double alpha, IntPtr jacobian); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveFisheyeDistortPoints(IntPtr undistored, IntPtr distorted, IntPtr K, IntPtr D, double alpha); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveFisheyeUndistortPoints(IntPtr distorted, IntPtr undistorted, IntPtr K, IntPtr D, IntPtr R, IntPtr P); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveFisheyeInitUndistortRectifyMap(IntPtr K, IntPtr D, IntPtr R, IntPtr P, ref Size size, int m1Type, IntPtr map1, IntPtr map2); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveFisheyeUndistortImage(IntPtr distorted, IntPtr undistored, IntPtr K, IntPtr D, IntPtr Knew, ref Size newSize); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveFisheyeEstimateNewCameraMatrixForUndistortRectify(IntPtr K, IntPtr D, ref Size imageSize, IntPtr R, IntPtr P, double balance, ref Size newSize, double fovScale); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveFisheyeStereoRectify(IntPtr K1, IntPtr D1, IntPtr K2, IntPtr D2, ref Size imageSize, IntPtr R, IntPtr tvec, IntPtr R1, IntPtr R2, IntPtr P1, IntPtr P2, IntPtr Q, int flags, ref Size newImageSize, double balance, double fovScale); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern double cveFisheyeCalibrate(IntPtr objectPoints, IntPtr imagePoints, ref Size imageSize, IntPtr K, IntPtr D, IntPtr rvecs, IntPtr tvecs, int flags, ref MCvTermCriteria criteria); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern double cveFisheyeStereoCalibrate(IntPtr objectPoints, IntPtr imagePoints1, IntPtr imagePoints2, IntPtr K1, IntPtr D1, IntPtr K2, IntPtr D2, ref Size imageSize, IntPtr R, IntPtr T, int flags, ref MCvTermCriteria criteria); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void eulerToQuaternions(double x, double y, double z, ref Quaternions q); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void quaternionsToEuler(ref Quaternions q, ref double x, ref double y, ref double z); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void axisAngleToQuaternions(ref MCvPoint3D64f axisAngle, ref Quaternions q); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void quaternionsToAxisAngle(ref Quaternions q, ref MCvPoint3D64f axisAngle); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void quaternionsToRotationMatrix(ref Quaternions quaternions, IntPtr rotation); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void quaternionsRotatePoint(ref Quaternions quaternions, ref MCvPoint3D64f point, ref MCvPoint3D64f pointDst); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void quaternionsRotatePoints(ref Quaternions quaternions, IntPtr pointSrc, IntPtr pointDst); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void quaternionsMultiply(ref Quaternions quaternions1, ref Quaternions quaternions2, ref Quaternions quaternionsDst); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void quaternionsSlerp(ref Quaternions qa, ref Quaternions qb, double t, ref Quaternions qm); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveInputArrayGetGpuMat(IntPtr ia, IntPtr gpumat); } public abstract class CvArray : UnmanagedObject, IXmlSerializable, IInputOutputArray, IInputArray, IDisposable, IOutputArray, IInputArrayOfArrays, IOutputArrayOfArrays, ISerializable where TDepth : new() { private static readonly int _sizeOfElement = Toolbox.SizeOf(); protected GCHandle _dataHandle; private int _serializationCompressionRatio; protected Mat _cvMat; public int SerializationCompressionRatio { get { return _serializationCompressionRatio; } set { _serializationCompressionRatio = value; } } public static int SizeOfElement => _sizeOfElement; public new IntPtr Ptr { get { return _ptr; } set { _ptr = value; } } public virtual Size Size => CvInvoke.cvGetSize(_ptr); public int Width => Size.Width; public int Height => Size.Height; public abstract int NumberOfChannels { get; } public int Rows => Height; public int Cols => Width; [DebuggerBrowsable(DebuggerBrowsableState.Never)] public byte[] Bytes { get { int num; IntPtr source; if (_dataHandle.IsAllocated) { num = _sizeOfElement * ManagedArray.Length; source = _dataHandle.AddrOfPinnedObject(); } else if (this is Matrix) { MCvMat mCvMat = ((Matrix)this).MCvMat; num = ((mCvMat.Step != 0) ? (mCvMat.Rows * mCvMat.Step) : (mCvMat.Cols * NumberOfChannels * _sizeOfElement)); source = mCvMat.Data; } else { if (this is MatND) { throw new NotImplementedException("Getting Bytes from Pinned MatND is not implemented"); } MIplImage mIplImage = (MIplImage)Marshal.PtrToStructure(Ptr, typeof(MIplImage)); num = mIplImage.Height * mIplImage.WidthStep; source = mIplImage.ImageData; } byte[] array = new byte[num]; Marshal.Copy(source, array, 0, num); if (SerializationCompressionRatio == 0) { return array; } return ZlibCompression.Compress(array, SerializationCompressionRatio); } set { int num = _sizeOfElement * ManagedArray.Length; byte[] array; if (SerializationCompressionRatio == 0) { array = value; } else { try { array = ZlibCompression.Uncompress(value, num); } catch { using MemoryStream stream = new MemoryStream(value); using GZipStream gZipStream = new GZipStream(stream, CompressionMode.Decompress); array = new byte[num]; gZipStream.Read(array, 0, num); } } Marshal.Copy(array, 0, _dataHandle.AddrOfPinnedObject(), num); } } public abstract Array ManagedArray { get; set; } [DebuggerBrowsable(DebuggerBrowsableState.Never)] public MCvScalar Trace => CvInvoke.Trace(this); [DebuggerBrowsable(DebuggerBrowsableState.Never)] public double Norm => CvInvoke.Norm(this); public Mat Mat { get { if (_cvMat == null || _cvMat.Ptr == IntPtr.Zero) { _cvMat = CvInvoke.CvArrToMat(Ptr); _cvMat._parent = this; } return _cvMat; } } protected abstract void AllocateData(int rows, int cols, int numberOfChannels); public double DotProduct(CvArray otherArray) { return Mat.Dot(otherArray.Mat); } public bool CheckRange(double min, double max, ref Point position) { return CvInvoke.CheckRange(this, quiet: true, ref position, min, max); } public void Reduce(CvArray array1D, ReduceDimension dim, ReduceType type) where TOtherDepth : new() { CvInvoke.Reduce(this, array1D, dim, type, CvInvoke.GetDepthType(typeof(TDepth))); } public void CopyTo(CvArray destination) { CvInvoke.cvCopy(Ptr, destination.Ptr, IntPtr.Zero); } public void SetValue(MCvScalar value, CvArray mask = null) { Mat.SetTo(value, mask); } public void SetValue(double value, CvArray mask = null) { SetValue(new MCvScalar(value, value, value, value), mask); } [ExposableMethod(Exposable = true)] public void SetRandUniform(MCvScalar floorValue, MCvScalar ceilingValue) { using ScalarArray low = new ScalarArray(floorValue); using ScalarArray high = new ScalarArray(ceilingValue); CvInvoke.Randu(Mat, low, high); } [ExposableMethod(Exposable = true)] public void SetRandNormal(MCvScalar mean, MCvScalar std) { using ScalarArray mean2 = new ScalarArray(mean); using ScalarArray stddev = new ScalarArray(std); CvInvoke.Randn(Mat, mean2, stddev); } public void SetIdentity(MCvScalar value) { CvInvoke.SetIdentity(this, value); } public void SetZero() { SetValue(0.0); } public void SetIdentity() { SetIdentity(new MCvScalar(1.0, 1.0, 1.0, 1.0)); } public void _Mul(double scale) { CvInvoke.cvConvertScale(Ptr, Ptr, scale, 0.0); } public void _Mul(CvArray src2) { CvInvoke.Multiply(this, src2, this, 1.0, CvInvoke.GetDepthType(typeof(TDepth))); } protected override void DisposeObject() { if (_dataHandle.IsAllocated) { _dataHandle.Free(); } if (_cvMat != null) { _cvMat.Dispose(); } } [ExposableMethod(Exposable = true, Category = "Logic")] public void _Min(double value) { using ScalarArray src = new ScalarArray(value); CvInvoke.Min(this, src, this); } public void _Min(CvArray other) { CvInvoke.Min(this, other, this); } [ExposableMethod(Exposable = true, Category = "Logic")] public void _Max(double value) { using ScalarArray src = new ScalarArray(value); CvInvoke.Max(this, src, this); } public void _Max(CvArray other) { CvInvoke.Max(this, other, this); } public void _And(CvArray otherArray) { CvInvoke.BitwiseAnd(this, otherArray, this); } public void _Or(CvArray otherArray) { CvInvoke.BitwiseOr(this, otherArray, this); } [ExposableMethod(Exposable = true, Category = "Logic")] public void _Not() { CvInvoke.BitwiseNot(this, this); } public virtual void Save(string fileName) { CvInvoke.Imwrite(fileName, this); } public XmlSchema GetSchema() { throw new NotImplementedException("The method or operation is not implemented."); } public virtual void ReadXml(XmlReader reader) { int rows = int.Parse(reader.GetAttribute("Rows")); int cols = int.Parse(reader.GetAttribute("Cols")); int numberOfChannels = int.Parse(reader.GetAttribute("NumberOfChannels")); AllocateData(rows, cols, numberOfChannels); SerializationCompressionRatio = int.Parse(reader.GetAttribute("CompressionRatio")); reader.MoveToContent(); reader.ReadToFollowing("Bytes"); int num = _sizeOfElement * ManagedArray.Length; if (SerializationCompressionRatio == 0) { byte[] array = new byte[num]; reader.ReadElementContentAsBase64(array, 0, array.Length); Bytes = array; } else { int num2 = 20000; byte[] array2 = new byte[num + num2]; int newSize = reader.ReadElementContentAsBase64(array2, 0, array2.Length); Array.Resize(ref array2, newSize); Bytes = array2; } } public virtual void WriteXml(XmlWriter writer) { writer.WriteAttributeString("Rows", Rows.ToString()); writer.WriteAttributeString("Cols", Cols.ToString()); writer.WriteAttributeString("NumberOfChannels", NumberOfChannels.ToString()); writer.WriteAttributeString("CompressionRatio", SerializationCompressionRatio.ToString()); writer.WriteStartElement("Bytes"); byte[] bytes = Bytes; writer.WriteBase64(bytes, 0, bytes.Length); writer.WriteEndElement(); } public virtual void GetObjectData(SerializationInfo info, StreamingContext context) { info.AddValue("Rows", Rows); info.AddValue("Cols", Cols); info.AddValue("NumberOfChannels", NumberOfChannels); info.AddValue("CompressionRatio", SerializationCompressionRatio); info.AddValue("Bytes", Bytes); } protected virtual void DeserializeObjectData(SerializationInfo info, StreamingContext context) { int rows = (int)info.GetValue("Rows", typeof(int)); int cols = (int)info.GetValue("Cols", typeof(int)); int numberOfChannels = (int)info.GetValue("NumberOfChannels", typeof(int)); AllocateData(rows, cols, numberOfChannels); SerializationCompressionRatio = (int)info.GetValue("CompressionRatio", typeof(int)); Bytes = (byte[])info.GetValue("Bytes", typeof(byte[])); } public InputArray GetInputArray() { return Mat.GetInputArray(); } public OutputArray GetOutputArray() { return Mat.GetOutputArray(); } public InputOutputArray GetInputOutputArray() { return Mat.GetInputOutputArray(); } public UMat ToUMat() { UMat uMat = new UMat(); Mat.CopyTo(uMat); return uMat; } } public class CvString : UnmanagedObject { private bool _needDispose; public int Length => CvInvoke.cveStringGetLength(_ptr); internal CvString(IntPtr ptr, bool needDispose) { _ptr = ptr; _needDispose = needDispose; } public CvString(string s) { if (s == null) { _ptr = CvInvoke.cveStringCreate(); } else { byte[] array = Encoding.UTF8.GetBytes(s); Array.Resize(ref array, array.Length + 1); array[^1] = 0; GCHandle gCHandle = GCHandle.Alloc(array, GCHandleType.Pinned); _ptr = CvInvoke.cveStringCreateFromStr(gCHandle.AddrOfPinnedObject()); gCHandle.Free(); } _needDispose = true; } public CvString() { _ptr = CvInvoke.cveStringCreate(); _needDispose = true; } public override string ToString() { IntPtr cStr = IntPtr.Zero; int size = 0; CvInvoke.cveStringGetCStr(_ptr, ref cStr, ref size); byte[] array = new byte[size]; Marshal.Copy(cStr, array, 0, size); return Encoding.UTF8.GetString(array, 0, array.Length); } protected override void DisposeObject() { if (_needDispose && _ptr != IntPtr.Zero) { CvInvoke.cveStringRelease(ref _ptr); } } } public static class DirectX { public static void ConvertToD3D11Texture2D(IInputArray src, IntPtr pD3D11Texture2D) { using InputArray inputArray = src.GetInputArray(); CvInvoke.cveDirectxConvertToD3D11Texture2D(inputArray, pD3D11Texture2D); } public static void ConvertFromD3D11Texture2D(IntPtr pD3D11Texture2D, IOutputArray dst) { using OutputArray outputArray = dst.GetOutputArray(); CvInvoke.cveDirectxConvertFromD3D11Texture2D(pD3D11Texture2D, outputArray); } public static void ConvertToD3D10Texture2D(IInputArray src, IntPtr pD3D10Texture2D) { using InputArray inputArray = src.GetInputArray(); CvInvoke.cveDirectxConvertToD3D10Texture2D(inputArray, pD3D10Texture2D); } public static void ConvertFromD3D10Texture2D(IntPtr pD3D10Texture2D, IOutputArray dst) { using OutputArray outputArray = dst.GetOutputArray(); CvInvoke.cveDirectxConvertFromD3D10Texture2D(pD3D10Texture2D, outputArray); } public static void ConvertToDirect3DSurface9(IInputArray src, IntPtr pDirect3DSurface9, IntPtr surfaceSharedHandle) { using InputArray inputArray = src.GetInputArray(); CvInvoke.cveDirectxConvertToDirect3DSurface9(inputArray, pDirect3DSurface9, surfaceSharedHandle); } public static void ConvertFromDirect3DSurface9(IntPtr pDirect3DSurface9, IOutputArray dst, IntPtr surfaceSharedHandle) { using OutputArray outputArray = dst.GetOutputArray(); CvInvoke.cveDirectxConvertFromDirect3DSurface9(pDirect3DSurface9, outputArray, surfaceSharedHandle); } } public class FileNode : UnmanagedObject, IEnumerable, IEnumerable { public enum Type { None = 0, Int = 1, Real = 2, Float = 2, Str = 3, String = 3, Seq = 4, Map = 5, TypeMask = 7, Flow = 8, Uniform = 8, Empty = 16, Named = 32 } public Type NodeType => (Type)CvInvoke.cveFileNodeGetType(_ptr); public string Name { get { if (!IsNamed) { return string.Empty; } using CvString cvString = new CvString(); CvInvoke.cveFileNodeGetName(_ptr, cvString); return cvString.ToString(); } } public bool IsNamed => CvInvoke.cveFileNodeIsNamed(_ptr); public bool IsEmpty => CvInvoke.cveFileNodeIsEmpty(_ptr); public bool IsNone => CvInvoke.cveFileNodeIsNone(_ptr); public bool IsSeq => CvInvoke.cveFileNodeIsSeq(_ptr); public bool IsMap => CvInvoke.cveFileNodeIsMap(_ptr); public bool IsInt => CvInvoke.cveFileNodeIsInt(_ptr); public bool IsReal => CvInvoke.cveFileNodeIsReal(_ptr); public bool IsString => CvInvoke.cveFileNodeIsString(_ptr); internal FileNode(IntPtr ptr) { _ptr = ptr; } public void ReadMat(Mat mat, Mat defaultMat = null) { if (defaultMat == null) { using (Mat mat2 = new Mat()) { CvInvoke.cveFileNodeReadMat(_ptr, mat, mat2); return; } } CvInvoke.cveFileNodeReadMat(_ptr, mat, defaultMat); } protected override void DisposeObject() { if (_ptr != IntPtr.Zero) { CvInvoke.cveFileNodeRelease(ref _ptr); } } public string ReadString(string defaultString = null) { using CvString cvString = new CvString(); using CvString cvString2 = new CvString(defaultString); CvInvoke.cveFileNodeReadString(_ptr, cvString, cvString2); return cvString.ToString(); } public int ReadInt(int defaultInt = int.MinValue) { return CvInvoke.cveFileNodeReadInt(_ptr, defaultInt); } public float ReadFloat(float defaultFloat = float.MinValue) { return CvInvoke.cveFileNodeReadFloat(_ptr, defaultFloat); } public double ReadDouble(double defaultDouble = double.MinValue) { return CvInvoke.cveFileNodeReadDouble(_ptr, defaultDouble); } public IEnumerator GetEnumerator() { using FileNodeIterator it = new FileNodeIterator(this, seekEnd: false); using FileNodeIterator end = new FileNodeIterator(this, seekEnd: true); while (!it.Equals(end)) { yield return it.GetFileNode(); it.Next(); } } IEnumerator IEnumerable.GetEnumerator() { return GetEnumerator(); } } public class FileNodeIterator : UnmanagedObject, IEquatable { internal FileNodeIterator() { _ptr = CvInvoke.cveFileNodeIteratorCreate(); } public FileNodeIterator(FileNode node, bool seekEnd) { _ptr = CvInvoke.cveFileNodeIteratorCreateFromNode(node, seekEnd); } public bool Equals(FileNodeIterator iterator) { return CvInvoke.cveFileNodeIteratorEqualTo(_ptr, iterator); } public void Next() { CvInvoke.cveFileNodeIteratorNext(_ptr); } public FileNode GetFileNode() { return new FileNode(CvInvoke.cveFileNodeIteratorGetFileNode(_ptr)); } protected override void DisposeObject() { if (_ptr != IntPtr.Zero) { CvInvoke.cveFileNodeIteratorRelease(ref _ptr); } } } public class FileStorage : UnmanagedObject { [Flags] public enum Mode { Read = 0, Write = 1, Append = 2, Memory = 4, FormatMask = 0x38, FormatAuto = 0, FormatXml = 8, FormatYaml = 0x10, FormatJson = 0x18, Base64 = 0x40, WriteBase64 = 0x41 } public bool IsOpened => CvInvoke.cveFileStorageIsOpened(_ptr); public FileNode this[string nodeName] => GetNode(nodeName); public FileStorage(string source, Mode flags, string encoding = null) { using CvString cvString2 = new CvString(encoding); using CvString cvString = new CvString(source); _ptr = CvInvoke.cveFileStorageCreate(cvString, flags, cvString2); } public void Write(Mat m, string nodeName = null) { using CvString cvString = new CvString(nodeName); CvInvoke.cveFileStorageWriteMat(_ptr, cvString, m); } public void Write(int value, string nodeName = null) { using CvString cvString = new CvString(nodeName); CvInvoke.cveFileStorageWriteInt(_ptr, cvString, value); } public void Write(float value, string nodeName = null) { using CvString cvString = new CvString(nodeName); CvInvoke.cveFileStorageWriteFloat(_ptr, cvString, value); } public void Write(double value, string nodeName = null) { using CvString cvString = new CvString(nodeName); CvInvoke.cveFileStorageWriteDouble(_ptr, cvString, value); } public void Write(string value, string nodeName = null) { using CvString cvString = new CvString(nodeName); using CvString cvString2 = new CvString(value); CvInvoke.cveFileStorageWriteString(_ptr, cvString, cvString2); } public string ReleaseAndGetString() { using CvString cvString = new CvString(); CvInvoke.cveFileStorageReleaseAndGetString(_ptr, cvString); return cvString.ToString(); } public FileNode GetRoot(int streamIdx = 0) { return new FileNode(CvInvoke.cveFileStorageRoot(_ptr, streamIdx)); } public FileNode GetFirstTopLevelNode() { return new FileNode(CvInvoke.cveFileStorageGetFirstTopLevelNode(_ptr)); } public FileNode GetNode(string nodeName) { using CvString cvString = new CvString(nodeName); return new FileNode(CvInvoke.cveFileStorageGetNode(_ptr, cvString)); } protected override void DisposeObject() { if (_ptr != IntPtr.Zero) { CvInvoke.cveFileStorageRelease(ref _ptr); } } public void Insert(string value) { using CvString cvString = new CvString(value); CvInvoke.cveFileStorageInsertString(this, cvString); } } public interface IAlgorithm { IntPtr AlgorithmPtr { get; } } public static class AlgorithmExtensions { public static void Read(this IAlgorithm algorithm, FileNode node) { CvInvoke.cveAlgorithmRead(algorithm.AlgorithmPtr, node); } public static void Write(this IAlgorithm algorithm, FileStorage storage) { CvInvoke.cveAlgorithmWrite(algorithm.AlgorithmPtr, storage); } public static void Write(this IAlgorithm algorithm, FileStorage storage, string name) { using CvString cvString = new CvString(name); CvInvoke.cveAlgorithmWrite2(algorithm.AlgorithmPtr, storage, cvString); } public static void Save(this IAlgorithm algorithm, string fileName) { using CvString cvString = new CvString(fileName); CvInvoke.cveAlgorithmSave(algorithm.AlgorithmPtr, cvString); } public static string SaveToString(this IAlgorithm algorithm, string format = ".xml") { using FileStorage fileStorage = new FileStorage(format, FileStorage.Mode.Write | FileStorage.Mode.Memory); fileStorage.Insert(algorithm.GetDefaultName()); fileStorage.Insert("{"); algorithm.Write(fileStorage); fileStorage.Insert("}"); return fileStorage.ReleaseAndGetString(); } public static void Clear(this IAlgorithm algorithm) { CvInvoke.cveAlgorithmClear(algorithm.AlgorithmPtr); } public static bool IsEmpty(this IAlgorithm algorithm) { return CvInvoke.cveAlgorithmEmpty(algorithm.AlgorithmPtr); } public static void Load(this IAlgorithm algorithm, string fileName, string objName = null, string encoding = null) { using FileStorage fileStorage = new FileStorage(fileName, FileStorage.Mode.Read, encoding); using FileNode node = ((objName == null) ? fileStorage.GetFirstTopLevelNode() : fileStorage[objName]); algorithm.Read(node); } public static void LoadFromString(this IAlgorithm algorithm, string strModel, string objName = null, string encoding = null) { using FileStorage fileStorage = new FileStorage(strModel, FileStorage.Mode.Memory, encoding); using FileNode node = ((objName == null) ? fileStorage.GetFirstTopLevelNode() : fileStorage[objName]); algorithm.Read(node); } public static string GetDefaultName(this IAlgorithm algorithm) { using CvString cvString = new CvString(); CvInvoke.cveAlgorithmGetDefaultName(algorithm.AlgorithmPtr, cvString); return cvString.ToString(); } } public interface IFileReaderMat { bool ReadFile(string fileName, Mat mat, ImreadModes loadType); } public interface IFileWriterMat { bool WriteFile(Mat mat, string fileName); } public interface IInputArray : IDisposable { InputArray GetInputArray(); } public interface IInputArrayOfArrays : IInputArray, IDisposable { } public static class IInputArrayExtensions { public static bool IsUmat(this IInputArray arr) { using InputArray inputArray = arr.GetInputArray(); return inputArray.IsUMat; } public static TReturn[] ForEachDuplicateChannel(this IInputArray image, Func conv) { using InputArray inputArray = image.GetInputArray(); int channels = inputArray.GetChannels(); TReturn[] array = new TReturn[channels]; if (channels == 1) { array[0] = conv(image, 0); } else { using Mat mat = new Mat(); for (int i = 0; i < channels; i++) { CvInvoke.ExtractChannel(image, mat, i); array[i] = conv(mat, i); } } return array; } public static void ForEachDuplicateChannel(this IInputArray image, Action action) { using InputArray inputArray = image.GetInputArray(); int channels = inputArray.GetChannels(); if (channels == 1) { action(image, 0); return; } using Mat mat = new Mat(); for (int i = 0; i < channels; i++) { CvInvoke.ExtractChannel(image, mat, i); action(mat, i); } } } public interface IInputOutputArray : IInputArray, IDisposable, IOutputArray, IInputArrayOfArrays, IOutputArrayOfArrays { InputOutputArray GetInputOutputArray(); } [Serializable] public class Image : CvArray, IEquatable>, IInputOutputArray, IInputArray, IDisposable, IOutputArray, IInputArrayOfArrays, IOutputArrayOfArrays where TColor : struct, IColor where TDepth : new() { private ImageDataReleaseMode _imageDataReleaseMode; private TDepth[,,] _array; private static readonly int _numberOfChannels = new TColor().Dimension; public TDepth[,,] Data { get { return _array; } set { AllocateData(value.GetLength(0), value.GetLength(1), NumberOfChannels); int length = value.GetLength(0); int num = value.GetLength(1) * value.GetLength(2); int num2 = _array.GetLength(1) * _array.GetLength(2); for (int i = 0; i < length; i++) { Array.Copy(value, i * num, _array, i * num2, num); } } } public MIplImage MIplImage => (MIplImage)Marshal.PtrToStructure(base.Ptr, typeof(MIplImage)); public Rectangle ROI { get { return CvInvoke.cvGetImageROI(base.Ptr); } set { if (value.Equals((object?)Rectangle.Empty)) { CvInvoke.cvResetImageROI(base.Ptr); } else { CvInvoke.cvSetImageROI(base.Ptr, value); } if (_cvMat != null) { _cvMat.Dispose(); _cvMat = null; } _cvMat = CvInvoke.CvArrToMat(base.Ptr); } } public override int NumberOfChannels => _numberOfChannels; public override Array ManagedArray { get { return _array; } set { if (!(value is TDepth[,,] data)) { throw new InvalidCastException($"Cannot convert ManagedArray to type of {typeof(TDepth).ToString()}[,,]."); } Data = data; } } public static IplDepth CvDepth { get { Type typeFromHandle = typeof(TDepth); if (typeFromHandle == typeof(float)) { return IplDepth.IplDepth32F; } if (typeFromHandle == typeof(byte)) { return IplDepth.IplDepth_8U; } if (typeFromHandle == typeof(double)) { return IplDepth.IplDepth64F; } if (typeFromHandle == typeof(sbyte)) { return IplDepth.IplDepth_8S; } if (typeFromHandle == typeof(ushort)) { return IplDepth.IplDepth16U; } if (typeFromHandle == typeof(short)) { return IplDepth.IplDepth16S; } if (typeFromHandle == typeof(int)) { return IplDepth.IplDepth32S; } throw new NotImplementedException("Unsupported image depth"); } } public bool IsROISet => Marshal.ReadIntPtr(base.Ptr, ImageConstants.RoiOffset) != IntPtr.Zero; public Image this[int channel] { get { Image image = new Image(Size); CvInvoke.MixChannels(this, image, new int[2] { channel, 0 }); return image; } set { CvInvoke.MixChannels(value, this, new int[2] { 0, channel }); } } public TColor this[int row, int column] { get { return new TColor { MCvScalar = CvInvoke.cvGet2D(base.Ptr, row, column) }; } set { CvInvoke.cvSet2D(base.Ptr, row, column, value.MCvScalar); } } public TColor this[Point location] { get { return this[location.Y, location.X]; } set { this[location.Y, location.X] = value; } } public override Size Size { get { MIplImage mIplImage = MIplImage; if (mIplImage.Roi == IntPtr.Zero) { return new Size(mIplImage.Width, mIplImage.Height); } return ROI.Size; } } protected Image() { } public Image(TDepth[,,] data) { Data = data; } public Image(int width, int height, int stride, IntPtr scan0) { MapDataToImage(width, height, stride, scan0); } protected void MapDataToImage(int width, int height, int stride, IntPtr scan0) { _ptr = CvInvoke.cvCreateImageHeader(new Size(width, height), CvDepth, NumberOfChannels); _imageDataReleaseMode = ImageDataReleaseMode.ReleaseHeaderOnly; GC.AddMemoryPressure(StructSize.MIplImage); MIplImage mIplImage = MIplImage; mIplImage.ImageData = scan0; mIplImage.WidthStep = stride; Marshal.StructureToPtr(mIplImage, _ptr, fDeleteOld: false); } internal Image(IntPtr ptr) { _ptr = ptr; } public Image(string fileName) { if (!File.Exists(fileName)) { throw new ArgumentException($"File {fileName} does not exist"); } try { using Mat mat = CvInvoke.Imread(fileName, ImreadModes.AnyDepth | ImreadModes.AnyColor); if (mat.IsEmpty) { throw new NullReferenceException($"Unable to load image from file \"{fileName}\"."); } LoadImageFromMat(mat); } catch (TypeInitializationException ex) { throw ex; } catch (Exception innerException) { throw new ArgumentException($"Unable to decode file: {fileName}", innerException); } } public Image(int width, int height, TColor value) : this(width, height) { SetValue(value); } public Image(int width, int height) { AllocateData(height, width, NumberOfChannels); } public Image(Size size) : this(size.Width, size.Height) { } protected override void AllocateData(int rows, int cols, int numberOfChannels) { DisposeObject(); _ptr = CvInvoke.cvCreateImageHeader(new Size(cols, rows), CvDepth, numberOfChannels); _imageDataReleaseMode = ImageDataReleaseMode.ReleaseHeaderOnly; GC.AddMemoryPressure(StructSize.MIplImage); if (typeof(TDepth) == typeof(byte) && ((uint)cols & 3u) != 0 && ((uint)numberOfChannels & 3u) != 0) { _array = new TDepth[rows, (cols & -4) + 4, numberOfChannels]; } else { _array = new TDepth[rows, cols, numberOfChannels]; } _dataHandle = GCHandle.Alloc(_array, GCHandleType.Pinned); CvInvoke.cvSetData(_ptr, _dataHandle.AddrOfPinnedObject(), _array.GetLength(1) * _array.GetLength(2) * CvArray.SizeOfElement); } public Image(Image[] channels) { AllocateData(channels[0].Height, channels[0].Width, NumberOfChannels); if (NumberOfChannels == 1) { CvInvoke.cvCopy(channels[0].Ptr, base.Ptr, IntPtr.Zero); return; } using VectorOfMat vectorOfMat = new VectorOfMat(); for (int i = 0; i < channels.Length; i++) { vectorOfMat.Push(channels[i].Mat); } CvInvoke.Merge(vectorOfMat, this); } public Image(SerializationInfo info, StreamingContext context) { DeserializeObjectData(info, context); ROI = (Rectangle)info.GetValue("Roi", typeof(Rectangle)); } public override void GetObjectData(SerializationInfo info, StreamingContext context) { if (IsROISet) { Rectangle rOI = ROI; ROI = Rectangle.Empty; base.GetObjectData(info, context); ROI = rOI; info.AddValue("Roi", rOI); } else { base.GetObjectData(info, context); info.AddValue("Roi", ROI); } } public TColor GetAverage() { return GetAverage(null); } public TColor GetAverage(Image mask) { return new TColor { MCvScalar = CvInvoke.Mean(this, mask) }; } public TColor GetSum() { return new TColor { MCvScalar = CvInvoke.Sum(this) }; } public void SetValue(TColor color) { SetValue(color.MCvScalar); } public void SetValue(TColor color, Image mask) { SetValue(color.MCvScalar, mask); } public void Copy(Image dest, Image mask) { CvInvoke.cvCopy(base.Ptr, dest.Ptr, mask?.Ptr ?? IntPtr.Zero); } public Image Copy(Image mask) { Image image = new Image(Size); Copy(image, mask); return image; } public Image Copy(Rectangle roi) { using Image image = GetSubRect(roi); return image.Copy(); } public Image Copy(RotatedRect box) { PointF[] vertices = box.GetVertices(); PointF[] dest = new PointF[4] { new PointF(0f, box.Size.Height - 1f), new PointF(0f, 0f), new PointF(box.Size.Width - 1f, 0f), new PointF(box.Size.Width - 1f, box.Size.Height - 1f) }; using Mat mapMatrix = CvInvoke.GetAffineTransform(vertices, dest); Image image = new Image((int)box.Size.Width, (int)box.Size.Height); CvInvoke.WarpAffine(this, image, mapMatrix, image.Size); return image; } public Image Copy() { return Copy(null); } public Image CopyBlank() { return new Image(Size); } public Image Clone() { int coi = CvInvoke.cvGetImageCOI(base.Ptr); Rectangle rOI = ROI; CvInvoke.cvSetImageCOI(base.Ptr, 0); ROI = Rectangle.Empty; Image image = Copy(); CvInvoke.cvSetImageCOI(image.Ptr, coi); image.ROI = rOI; CvInvoke.cvSetImageCOI(base.Ptr, coi); ROI = rOI; return image; } public Image GetSubRect(Rectangle rect) { Image obj = new Image { _array = _array }; GC.AddMemoryPressure(StructSize.MIplImage); obj._ptr = CvInvoke.cvGetImageSubRect(_ptr, ref rect); return obj; } public virtual void Draw(Rectangle rect, TColor color, int thickness = 1, LineType lineType = LineType.EightConnected, int shift = 0) { CvInvoke.Rectangle(this, rect, color.MCvScalar, thickness, lineType, shift); } public void Draw(Cross2DF cross, TColor color, int thickness) { if (thickness > 0) { Draw(cross.Horizontal, color, thickness); Draw(cross.Vertical, color, thickness); } } public virtual void Draw(LineSegment2DF line, TColor color, int thickness, LineType lineType = LineType.EightConnected, int shift = 0) { if (thickness > 0) { CvInvoke.Line(this, Point.Round(line.P1), Point.Round(line.P2), color.MCvScalar, thickness, lineType, shift); } } public virtual void Draw(LineSegment2D line, TColor color, int thickness, LineType lineType = LineType.EightConnected, int shift = 0) { if (thickness > 0) { CvInvoke.Line(this, line.P1, line.P2, color.MCvScalar, thickness, lineType, shift); } } public virtual void Draw(IConvexPolygonF polygon, TColor color, int thickness) { PointF[] vertices = polygon.GetVertices(); Point[] array = new Point[vertices.Length]; for (int i = 0; i < vertices.Length; i++) { array[i] = Point.Round(vertices[i]); } if (thickness > 0) { DrawPolyline(array, isClosed: true, color, thickness); } else { FillConvexPoly(array, color); } } public void FillConvexPoly(Point[] pts, TColor color, LineType lineType = LineType.EightConnected, int shift = 0) { using VectorOfPoint points = new VectorOfPoint(pts); CvInvoke.FillConvexPoly(this, points, color.MCvScalar, lineType, shift); } public void DrawPolyline(Point[] pts, bool isClosed, TColor color, int thickness = 1, LineType lineType = LineType.EightConnected, int shift = 0) { DrawPolyline(new Point[1][] { pts }, isClosed, color, thickness, lineType, shift); } public void DrawPolyline(Point[][] pts, bool isClosed, TColor color, int thickness = 1, LineType lineType = LineType.EightConnected, int shift = 0) { if (thickness > 0) { using (VectorOfVectorOfPoint pts2 = new VectorOfVectorOfPoint(pts)) { CvInvoke.Polylines(this, pts2, isClosed, color.MCvScalar, thickness, lineType, shift); } } } public virtual void Draw(CircleF circle, TColor color, int thickness = 1, LineType lineType = LineType.EightConnected, int shift = 0) { CvInvoke.Circle(this, Point.Round(circle.Center), (int)circle.Radius, color.MCvScalar, (thickness <= 0) ? (-1) : thickness, lineType, shift); } public void Draw(Ellipse ellipse, TColor color, int thickness = 1, LineType lineType = LineType.EightConnected, int shift = 0) { CvInvoke.Ellipse(this, ellipse.RotatedRect, color.MCvScalar, thickness, lineType, shift); } public virtual void Draw(string message, Point bottomLeft, FontFace fontFace, double fontScale, TColor color, int thickness = 1, LineType lineType = LineType.EightConnected, bool bottomLeftOrigin = false) { CvInvoke.PutText(this, message, bottomLeft, fontFace, fontScale, color.MCvScalar, thickness, lineType, bottomLeftOrigin); } public void Draw(IInputArrayOfArrays contours, int contourIdx, TColor color, int thickness = 1, LineType lineType = LineType.EightConnected, IInputArray hierarchy = null, int maxLevel = int.MaxValue, Point offset = default(Point)) { CvInvoke.DrawContours(this, contours, contourIdx, color.MCvScalar, thickness, lineType, hierarchy, maxLevel, offset); } public void Draw(Point[] contours, TColor color, int thickness = 1, LineType lineType = LineType.EightConnected, Point offset = default(Point)) { using VectorOfPoint value = new VectorOfPoint(contours); using VectorOfVectorOfPoint vectorOfVectorOfPoint = new VectorOfVectorOfPoint(); vectorOfVectorOfPoint.Push(value); Draw(vectorOfVectorOfPoint, 0, color, thickness, lineType); } public LineSegment2D[][] HoughLinesBinary(double rhoResolution, double thetaResolution, int threshold, double minLineWidth, double gapBetweenLines) { return this.ForEachDuplicateChannel((IInputArray img, int channel) => CvInvoke.HoughLinesP(this, rhoResolution, thetaResolution, threshold, minLineWidth, gapBetweenLines)); } public LineSegment2D[][] HoughLines(double cannyThreshold, double cannyThresholdLinking, double rhoResolution, double thetaResolution, int threshold, double minLineWidth, double gapBetweenLines) { using Image image = Canny(cannyThreshold, cannyThresholdLinking); return image.HoughLinesBinary(rhoResolution, thetaResolution, threshold, minLineWidth, gapBetweenLines); } public CircleF[][] HoughCircles(TColor cannyThreshold, TColor accumulatorThreshold, double dp, double minDist, int minRadius = 0, int maxRadius = 0) { double[] cannyThresh = cannyThreshold.MCvScalar.ToArray(); double[] accumulatorThresh = accumulatorThreshold.MCvScalar.ToArray(); return this.ForEachDuplicateChannel((IInputArray img, int channel) => CvInvoke.HoughCircles(img, HoughModes.Gradient, dp, minDist, cannyThresh[channel], accumulatorThresh[channel], minRadius, maxRadius)); } protected static void RoiParam(IntPtr ptr, out long start, out int rows, out int elementCount, out int byteWidth, out int widthStep) { MIplImage mIplImage = (MIplImage)Marshal.PtrToStructure(ptr, typeof(MIplImage)); start = mIplImage.ImageData.ToInt64(); widthStep = mIplImage.WidthStep; if (mIplImage.Roi != IntPtr.Zero) { Rectangle rectangle = CvInvoke.cvGetImageROI(ptr); elementCount = rectangle.Width * mIplImage.NChannels; byteWidth = ((int)mIplImage.Depth >> 3) * elementCount; start += rectangle.Y * widthStep + ((int)mIplImage.Depth >> 3) * rectangle.X; rows = rectangle.Height; } else { byteWidth = widthStep; elementCount = mIplImage.Width * mIplImage.NChannels; rows = mIplImage.Height; } } private TResult[] ForEachChannel(Func conv) { TResult[] array = new TResult[NumberOfChannels]; if (NumberOfChannels == 1) { array[0] = conv(base.Ptr, 0); } else { for (int i = 0; i < NumberOfChannels; i++) { CvInvoke.cvSetImageCOI(base.Ptr, i + 1); array[i] = conv(base.Ptr, i); } CvInvoke.cvSetImageCOI(base.Ptr, 0); } return array; } private void ForEachDuplicateChannel(Action act, Image dest) where TOtherDepth : new() { if (NumberOfChannels == 1) { act(this, dest, 0); return; } using Mat mat = new Mat(); using Mat mat2 = new Mat(); for (int i = 0; i < NumberOfChannels; i++) { CvInvoke.ExtractChannel(this, mat, i); act(mat, mat2, i); CvInvoke.InsertChannel(mat2, dest, i); } } [ExposableMethod(Exposable = true, Category = "Gradients, Edges")] public Image Sobel(int xorder, int yorder, int apertureSize) { Image image = new Image(Size); CvInvoke.Sobel(this, image, CvInvoke.GetDepthType(typeof(float)), xorder, yorder, apertureSize); return image; } [ExposableMethod(Exposable = true, Category = "Gradients, Edges")] public Image Laplace(int apertureSize) { Image image = new Image(Size); CvInvoke.Laplacian(this, image, CvInvoke.GetDepthType(typeof(float)), apertureSize); return image; } [ExposableMethod(Exposable = true, Category = "Gradients, Edges")] public Image Canny(double thresh, double threshLinking) { return Canny(thresh, threshLinking, 3, l2Gradient: false); } public Image Canny(double thresh, double threshLinking, int apertureSize, bool l2Gradient) { Image image = new Image(Size); CvInvoke.Canny(this, image, thresh, threshLinking, apertureSize, l2Gradient); return image; } public void FindCornerSubPix(PointF[][] corners, Size win, Size zeroZone, MCvTermCriteria criteria) { this.ForEachDuplicateChannel(delegate(IInputArray img, int channel) { using VectorOfPointF vectorOfPointF = new VectorOfPointF(); vectorOfPointF.Push(corners[channel]); CvInvoke.CornerSubPix(img, vectorOfPointF, win, zeroZone, criteria); Array.Copy(vectorOfPointF.ToArray(), corners[channel], corners[channel].Length); }); } public Image MatchTemplate(Image template, TemplateMatchingType method) { Image result = new Image(base.Width - template.Width + 1, base.Height - template.Height + 1); CvInvoke.MatchTemplate(this, template, result, method); return result; } public Image And(Image img2) { Image image = new Image(Size); CvInvoke.BitwiseAnd(this, img2, image); return image; } public Image And(Image img2, Image mask) { Image image = new Image(Size); CvInvoke.BitwiseAnd(this, img2, image, mask); return image; } public Image And(TColor val) { return And(val, null); } public Image And(TColor val, Image mask) { Image image = new Image(Size); using ScalarArray src = new ScalarArray(val.MCvScalar); CvInvoke.BitwiseAnd(this, src, image, mask); return image; } public Image Or(Image img2) { return Or(img2, null); } public Image Or(Image img2, Image mask) { Image image = CopyBlank(); CvInvoke.BitwiseOr(this, img2, image, mask); return image; } [ExposableMethod(Exposable = true, Category = "Logic")] public Image Or(TColor val) { return Or(val, null); } public Image Or(TColor val, Image mask) { Image image = CopyBlank(); using ScalarArray src = new ScalarArray(val.MCvScalar); CvInvoke.BitwiseOr(this, src, image, mask); return image; } public Image Xor(Image img2) { return Xor(img2, null); } public Image Xor(Image img2, Image mask) { Image image = CopyBlank(); CvInvoke.BitwiseXor(this, img2, image, mask); return image; } [ExposableMethod(Exposable = true, Category = "Logic")] public Image Xor(TColor val) { return Xor(val, null); } public Image Xor(TColor val, Image mask) { Image image = CopyBlank(); using ScalarArray src = new ScalarArray(val.MCvScalar); CvInvoke.BitwiseXor(this, src, image, mask); return image; } public Image Not() { Image image = CopyBlank(); CvInvoke.BitwiseNot(this, image); return image; } public Image Max(Image img2) { Image image = CopyBlank(); CvInvoke.Max(this, img2, image); return image; } public Image Max(double value) { Image image = CopyBlank(); using ScalarArray src = new ScalarArray(value); CvInvoke.Max(this, src, image); return image; } public Image Min(Image img2) { Image image = CopyBlank(); CvInvoke.Min(this, img2, image); return image; } public Image Min(double value) { Image image = CopyBlank(); using ScalarArray src = new ScalarArray(value); CvInvoke.Min(this, src, image); return image; } [ExposableMethod(Exposable = true, Category = "Logic")] public Image InRange(TColor lower, TColor higher) { Image image = new Image(Size); using ScalarArray lower2 = new ScalarArray(lower.MCvScalar); using ScalarArray upper = new ScalarArray(higher.MCvScalar); CvInvoke.InRange(this, lower2, upper, image); return image; } public Image InRange(Image lower, Image higher) { Image image = new Image(Size); CvInvoke.InRange(this, lower, higher, image); return image; } public Image Cmp(Image img2, CmpType cmpType) { Size size = Size; Image image = new Image(size); if (NumberOfChannels == 1) { CvInvoke.Compare(this, img2, image, cmpType); } else { using (Image image2 = new Image(size)) { using Image image3 = new Image(size); using Image image4 = new Image(size); for (int i = 0; i < NumberOfChannels; i++) { CvInvoke.cvSetImageCOI(base.Ptr, i + 1); CvInvoke.cvSetImageCOI(img2.Ptr, i + 1); CvInvoke.cvCopy(base.Ptr, image2.Ptr, IntPtr.Zero); CvInvoke.cvCopy(img2.Ptr, image3.Ptr, IntPtr.Zero); CvInvoke.Compare(image2, image3, image4, cmpType); CvInvoke.cvSetImageCOI(image.Ptr, i + 1); CvInvoke.cvCopy(image4.Ptr, image.Ptr, IntPtr.Zero); } } CvInvoke.cvSetImageCOI(base.Ptr, 0); CvInvoke.cvSetImageCOI(img2.Ptr, 0); CvInvoke.cvSetImageCOI(image.Ptr, 0); } return image; } [ExposableMethod(Exposable = true, Category = "Logic")] public Image Cmp(double value, CmpType comparisonType) { Image image = new Image(Size); ScalarArray ia = new ScalarArray(value); try { if (NumberOfChannels == 1) { CvInvoke.Compare(this, ia, image, comparisonType); } else { ForEachDuplicateChannel(delegate(IInputArray img1, IOutputArray img2, int channel) { CvInvoke.Compare(img1, ia, img2, comparisonType); }, image); } } finally { if (ia != null) { ((IDisposable)ia).Dispose(); } } return image; } public bool Equals(Image img2) { if (this == img2) { return true; } if (!Size.Equals((object?)img2.Size)) { return false; } using Image image = new Image(Size); CvInvoke.BitwiseXor(this, img2, image); if (NumberOfChannels == 1) { return CvInvoke.CountNonZero(image) == 0; } IntPtr intPtr = Marshal.AllocHGlobal(StructSize.MCvMat); try { CvInvoke.cvReshape(image, intPtr, 1, 0); using Mat arr = CvInvoke.CvArrToMat(intPtr); return CvInvoke.CountNonZero(arr) == 0; } finally { Marshal.FreeHGlobal(intPtr); } } public Image GrabCut(Rectangle rect, int iteration) { Image image = new Image(Size); using Matrix bgdModel = new Matrix(1, 65); using Matrix fgdModel = new Matrix(1, 65); CvInvoke.GrabCut(this, image, rect, bgdModel, fgdModel, 0, GrabcutInitType.InitWithRect); CvInvoke.GrabCut(this, image, rect, bgdModel, fgdModel, iteration, GrabcutInitType.Eval); return image; } public Image Sub(Image img2) { Image image = CopyBlank(); CvInvoke.Subtract(this, img2, image, null, CvInvoke.GetDepthType(typeof(TDepth))); return image; } public Image Sub(Image img2, Image mask) { Image image = CopyBlank(); CvInvoke.Subtract(this, img2, image, mask, CvInvoke.GetDepthType(typeof(TDepth))); return image; } [ExposableMethod(Exposable = true, Category = "Math")] public Image Sub(TColor val) { Image image = CopyBlank(); using ScalarArray src = new ScalarArray(val.MCvScalar); CvInvoke.Subtract(this, src, image, null, CvInvoke.GetDepthType(typeof(TDepth))); return image; } [ExposableMethod(Exposable = true, Category = "Math")] public Image SubR(TColor val) { return SubR(val, null); } public Image SubR(TColor val, Image mask) { Image image = CopyBlank(); using ScalarArray src = new ScalarArray(val.MCvScalar); CvInvoke.Subtract(src, this, image, mask, CvInvoke.GetDepthType(typeof(TDepth))); return image; } public Image Add(Image img2) { return Add(img2, null); } public Image Add(Image img2, Image mask) { Image image = CopyBlank(); CvInvoke.Add(this, img2, image, mask, CvInvoke.GetDepthType(typeof(TDepth))); return image; } [ExposableMethod(Exposable = true, Category = "Math")] public Image Add(TColor val) { Image image = CopyBlank(); using ScalarArray src = new ScalarArray(val.MCvScalar); CvInvoke.Add(this, src, image, null, CvInvoke.GetDepthType(typeof(TDepth))); return image; } public Image Mul(Image img2, double scale) { Image image = CopyBlank(); CvInvoke.Multiply(this, img2, image, scale, CvInvoke.GetDepthType(typeof(TDepth))); return image; } public Image Mul(Image img2) { return Mul(img2, 1.0); } [ExposableMethod(Exposable = true, Category = "Math")] public Image Mul(double scale) { Image image = CopyBlank(); CvInvoke.cvConvertScale(base.Ptr, image.Ptr, scale, 0.0); return image; } public void Accumulate(Image img2, Image mask) { CvInvoke.Accumulate(img2, this, mask); } public void Accumulate(Image img2) { CvInvoke.Accumulate(img2, this); } public Image AddWeighted(Image img2, double alpha, double beta, double gamma) { Image image = CopyBlank(); CvInvoke.AddWeighted(this, alpha, img2, beta, gamma, image, CvInvoke.GetDepthType(typeof(TDepth))); return image; } public void AccumulateWeighted(Image img, double alpha) { AccumulateWeighted(img, alpha, null); } public void AccumulateWeighted(Image img, double alpha, Image mask) { CvInvoke.AccumulateWeighted(img, this, alpha, mask); } public Image AbsDiff(Image img2) { Image image = CopyBlank(); CvInvoke.AbsDiff(this, img2, image); return image; } [ExposableMethod(Exposable = true, Category = "Math")] public Image AbsDiff(TColor color) { Image image = new Image(Size); using ScalarArray src = new ScalarArray(color.MCvScalar); CvInvoke.AbsDiff(this, src, image); return image; } [ExposableMethod(Exposable = true, Category = "Math")] public Image Pow(double power) { Image image = CopyBlank(); CvInvoke.Pow(this, power, image); return image; } [ExposableMethod(Exposable = true, Category = "Math")] public Image Exp() { Image image = CopyBlank(); CvInvoke.Exp(this, image); return image; } [ExposableMethod(Exposable = true, Category = "Math")] public Image Log() { Image image = CopyBlank(); CvInvoke.Log(this, image); return image; } [ExposableMethod(Exposable = true)] public Image Resize(int width, int height, Inter interpolationType) { Image image = new Image(width, height); CvInvoke.Resize(this, image, new Size(width, height), 0.0, 0.0, interpolationType); return image; } public Image Resize(int width, int height, Inter interpolationType, bool preserveScale) { if (!preserveScale) { return Resize(width, height, interpolationType); } return Resize(Math.Min((double)width / (double)base.Width, (double)height / (double)base.Height), interpolationType); } [ExposableMethod(Exposable = true)] public Image Resize(double scale, Inter interpolationType) { return Resize((int)((double)base.Width * scale), (int)((double)base.Height * scale), interpolationType); } public Image Rotate(double angle, TColor background) { return Rotate(angle, background, crop: true); } public Image WarpAffine(Mat mapMatrix, Inter interpolationType, Warp warpType, BorderType borderMode, TColor backgroundColor) { return WarpAffine(mapMatrix, base.Width, base.Height, interpolationType, warpType, borderMode, backgroundColor); } public Image WarpAffine(Mat mapMatrix, int width, int height, Inter interpolationType, Warp warpType, BorderType borderMode, TColor backgroundColor) { Image image = new Image(width, height); CvInvoke.WarpAffine(this, image, mapMatrix, image.Size, interpolationType, warpType, borderMode, backgroundColor.MCvScalar); return image; } public Image WarpPerspective(Matrix mapMatrix, Inter interpolationType, Warp warpType, BorderType borderMode, TColor backgroundColor) where TMapDepth : new() { return WarpPerspective(mapMatrix, base.Width, base.Height, interpolationType, warpType, borderMode, backgroundColor); } public Image WarpPerspective(Matrix mapMatrix, int width, int height, Inter interpolationType, Warp warpType, BorderType borderType, TColor backgroundColor) where TMapDepth : new() { Image image = new Image(width, height); CvInvoke.WarpPerspective(this, image, mapMatrix, image.Size, interpolationType, warpType, borderType, backgroundColor.MCvScalar); return image; } [ExposableMethod(Exposable = true, Category = "Transform")] public Image Rotate(double angle, TColor background, bool crop) { Size size = Size; PointF center = new PointF((float)size.Width * 0.5f, (float)size.Height * 0.5f); return Rotate(angle, center, Inter.Cubic, background, crop); } public Image Rotate(double angle, PointF center, Inter interpolationMethod, TColor background, bool crop) { if (crop) { using (Mat mapMatrix = new Mat()) { CvInvoke.GetRotationMatrix2D(center, 0.0 - angle, 1.0, mapMatrix); return WarpAffine(mapMatrix, interpolationMethod, Warp.FillOutliers, BorderType.Constant, background); } } Size dstImageSize; using Mat mapMatrix2 = RotationMatrix2D.CreateRotationMatrix(center, 0.0 - angle, Size, out dstImageSize); return WarpAffine(mapMatrix2, dstImageSize.Width, dstImageSize.Height, interpolationMethod, Warp.FillOutliers, BorderType.Constant, background); } [ExposableMethod(Exposable = true, Category = "Transform")] public Image LogPolar(PointF center, double magnitude, Inter interpolationType = Inter.Linear, Warp warpType = Warp.FillOutliers) { Image image = CopyBlank(); CvInvoke.LogPolar(this, image, center, magnitude, interpolationType, warpType); return image; } [ExposableMethod(Exposable = true, Category = "Conversion", GenericParametersOptions = new Type[] { typeof(Bgr), typeof(Bgra), typeof(Gray), typeof(Hsv), typeof(Hls), typeof(Lab), typeof(Luv), typeof(Xyz), typeof(Ycc), typeof(float), typeof(byte), typeof(double) }, GenericParametersOptionSizes = new int[] { 9, 3 })] public Image Convert() where TOtherColor : struct, IColor where TOtherDepth : new() { Image image = new Image(Size); image.ConvertFrom(this); return image; } public void ConvertFrom(Image srcImage) where TSrcColor : struct, IColor where TSrcDepth : new() { if (!Size.Equals((object?)srcImage.Size)) { using (Image image = new Image(Size)) { CvInvoke.Resize(srcImage, image, Size); ConvertFrom(image); return; } } if (typeof(TColor) == typeof(TSrcColor)) { if (typeof(TDepth) == typeof(TSrcDepth)) { srcImage.Mat.CopyTo(this); } else if (typeof(TDepth) == typeof(byte) && typeof(TSrcDepth) != typeof(byte)) { srcImage.MinMax(out var minValues, out var maxValues, out var _, out var _); double num = minValues[0]; double num2 = maxValues[0]; for (int i = 1; i < minValues.Length; i++) { num = Math.Min(num, minValues[i]); num2 = Math.Max(num2, maxValues[i]); } double num3 = 1.0; double shift = 0.0; if (num2 > 255.0 || num < 0.0) { num3 = (num2.Equals(num) ? 0.0 : (255.0 / (num2 - num))); shift = (num3.Equals(0.0) ? num : ((0.0 - num) * num3)); } CvInvoke.ConvertScaleAbs(srcImage, this, num3, shift); } else { srcImage.Mat.ConvertTo(this, base.Mat.Depth); } return; } if (typeof(TDepth) == typeof(TSrcDepth)) { CvInvoke.CvtColor(srcImage, this, typeof(TSrcColor), typeof(TColor)); return; } if (typeof(TSrcDepth) == typeof(byte)) { using (Image srcImage2 = srcImage.Convert()) { ConvertFrom(srcImage2); return; } } using Image src = srcImage.Convert(); CvInvoke.CvtColor(src, this, typeof(TSrcColor), typeof(TColor)); } public void ConvertFrom(IInputArray srcImage) { using InputArray inputArray = srcImage.GetInputArray(); Size size = inputArray.GetSize(); if (!Size.Equals((object?)size)) { using (Mat mat = new Mat()) { CvInvoke.Resize(srcImage, mat, Size); ConvertFrom(mat); return; } } int channels = inputArray.GetChannels(); if (NumberOfChannels == channels) { DepthType depth = inputArray.GetDepth(); if (CvInvoke.GetDepthType(typeof(TDepth)) == depth) { inputArray.CopyTo(this); return; } if (typeof(TDepth) == typeof(byte) && CvInvoke.GetDepthType(typeof(byte)) != 0) { CvInvoke.MinMax(srcImage, out var minValues, out var maxValues, out var _, out var _); double num = minValues[0]; double num2 = maxValues[0]; for (int i = 1; i < minValues.Length; i++) { num = Math.Min(num, minValues[i]); num2 = Math.Max(num2, maxValues[i]); } double num3 = 1.0; double shift = 0.0; if (num2 > 255.0 || num < 0.0) { num3 = (num2.Equals(num) ? 0.0 : (255.0 / (num2 - num))); shift = (num3.Equals(0.0) ? num : ((0.0 - num) * num3)); } CvInvoke.ConvertScaleAbs(srcImage, this, num3, shift); return; } using Mat mat2 = inputArray.GetMat(); mat2.ConvertTo(this, base.Mat.Depth); return; } if (channels != 1 && channels != 3 && channels != 4) { throw new Exception("Color conversion not suppported"); } Type srcColor = channels switch { 3 => typeof(Bgr), 1 => typeof(Gray), _ => typeof(Bgra), }; DepthType depth2 = inputArray.GetDepth(); if (CvInvoke.GetDepthType(typeof(TDepth)) == depth2) { CvInvoke.CvtColor(srcImage, this, srcColor, typeof(TColor)); return; } using Mat mat4 = new Mat(); using Mat mat3 = inputArray.GetMat(); mat3.ConvertTo(mat4, CvInvoke.GetDepthType(typeof(TDepth))); CvInvoke.CvtColor(mat4, this, srcColor, typeof(TColor)); } public Image ConvertScale(double scale, double shift) where TOtherDepth : new() { Image image = new Image(base.Width, base.Height); if (typeof(TOtherDepth) == typeof(byte)) { CvInvoke.ConvertScaleAbs(this, image, scale, shift); } else { CvInvoke.cvConvertScale(this, image, scale, shift); } return image; } [ExposableMethod(Exposable = true, Category = "Pyramids")] public Image PyrDown() { Image image = new Image(base.Width >> 1, base.Height >> 1); CvInvoke.PyrDown(this, image); return image; } [ExposableMethod(Exposable = true, Category = "Pyramids")] public Image PyrUp() { Image image = new Image(base.Width << 1, base.Height << 1); CvInvoke.PyrUp(this, image); return image; } public Image[] BuildPyramid(int maxLevel) { Image[] array = new Image[maxLevel + 1]; array[0] = this; for (int i = 1; i <= maxLevel; i++) { array[i] = array[i - 1].PyrDown(); } return array; } public Image InPaint(Image mask, double radius) { Image image = CopyBlank(); CvInvoke.Inpaint(this, mask, image, radius, InpaintType.Telea); return image; } public Image MorphologyEx(MorphOp operation, IInputArray kernel, Point anchor, int iterations, BorderType borderType, MCvScalar borderValue) { Image image = CopyBlank(); CvInvoke.MorphologyEx(this, image, operation, kernel, anchor, iterations, borderType, borderValue); return image; } public void _MorphologyEx(MorphOp operation, IInputArray kernel, Point anchor, int iterations, BorderType borderType, MCvScalar borderValue) { CvInvoke.MorphologyEx(this, this, operation, kernel, anchor, iterations, borderType, borderValue); } public Image Erode(int iterations) { Image image = CopyBlank(); CvInvoke.Erode(this, image, null, new Point(-1, -1), iterations, BorderType.Constant, CvInvoke.MorphologyDefaultBorderValue); return image; } public Image Dilate(int iterations) { Image image = CopyBlank(); CvInvoke.Dilate(this, image, null, new Point(-1, -1), iterations, BorderType.Constant, CvInvoke.MorphologyDefaultBorderValue); return image; } [ExposableMethod(Exposable = true, Category = "Morphology")] public void _Erode(int iterations) { CvInvoke.Erode(this, this, null, new Point(-1, -1), iterations, BorderType.Constant, CvInvoke.MorphologyDefaultBorderValue); } [ExposableMethod(Exposable = true, Category = "Morphology")] public void _Dilate(int iterations) { CvInvoke.Dilate(this, this, null, new Point(-1, -1), iterations, BorderType.Constant, CvInvoke.MorphologyDefaultBorderValue); } public void Action(Action action) { int num = base.Width * new TColor().Dimension; CvInvoke.cvGetRawData(base.Ptr, out var data, out var step, out var _); long num2 = data.ToInt64(); int len = CvArray.SizeOfElement * num; using PinnedArray pinnedArray = new PinnedArray(num); int num3 = 0; while (num3 < base.Height) { CvToolbox.Memcpy(pinnedArray.AddrOfPinnedObject(), new IntPtr(num2), len); TDepth[] array = pinnedArray.Array; foreach (TDepth obj in array) { action(obj); } num3++; num2 += step; } } public void Action(Image img2, Action action) where TOtherDepth : new() { RoiParam(base.Ptr, out var start, out var rows, out var elementCount, out var byteWidth, out var widthStep); RoiParam(img2.Ptr, out var start2, out var _, out var _, out var byteWidth2, out var widthStep2); TDepth[] array = new TDepth[elementCount]; TOtherDepth[] array2 = new TOtherDepth[elementCount]; GCHandle gCHandle = GCHandle.Alloc(array, GCHandleType.Pinned); GCHandle gCHandle2 = GCHandle.Alloc(array2, GCHandleType.Pinned); int num = 0; while (num < rows) { CvToolbox.Memcpy(gCHandle.AddrOfPinnedObject(), (IntPtr)start, byteWidth); CvToolbox.Memcpy(gCHandle2.AddrOfPinnedObject(), (IntPtr)start2, byteWidth2); for (int i = 0; i < elementCount; i++) { action(array[i], array2[i]); } num++; start += widthStep; start2 += widthStep2; } gCHandle.Free(); gCHandle2.Free(); } public Image Convert(Func converter) where TOtherDepth : new() { Image image = new Image(base.Width, base.Height); int nChannels = MIplImage.NChannels; RoiParam(base.Ptr, out var start, out var rows, out var elementCount, out var byteWidth, out var widthStep); RoiParam(image.Ptr, out var start2, out var _, out var _, out var byteWidth2, out var widthStep2); TDepth[] array = new TDepth[elementCount]; TOtherDepth[] array2 = new TOtherDepth[elementCount]; GCHandle gCHandle = GCHandle.Alloc(array, GCHandleType.Pinned); GCHandle gCHandle2 = GCHandle.Alloc(array2, GCHandleType.Pinned); int num = 0; while (num < rows) { CvToolbox.Memcpy(gCHandle.AddrOfPinnedObject(), (IntPtr)start, byteWidth); for (int i = 0; i < elementCount; i++) { array2[i] = converter(array[i], num, i / nChannels); } CvToolbox.Memcpy((IntPtr)start2, gCHandle2.AddrOfPinnedObject(), byteWidth2); num++; start += widthStep; start2 += widthStep2; } gCHandle.Free(); gCHandle2.Free(); return image; } public Image Convert(Func converter) where TOtherDepth : new() { Image image = new Image(Size); RoiParam(base.Ptr, out var start, out var rows, out var elementCount, out var byteWidth, out var widthStep); RoiParam(image.Ptr, out var start2, out var _, out var _, out var byteWidth2, out var widthStep2); TDepth[] array = new TDepth[elementCount]; TOtherDepth[] array2 = new TOtherDepth[elementCount]; GCHandle gCHandle = GCHandle.Alloc(array, GCHandleType.Pinned); GCHandle gCHandle2 = GCHandle.Alloc(array2, GCHandleType.Pinned); int num = 0; while (num < rows) { CvToolbox.Memcpy(gCHandle.AddrOfPinnedObject(), (IntPtr)start, byteWidth); for (int i = 0; i < elementCount; i++) { array2[i] = converter(array[i]); } CvToolbox.Memcpy((IntPtr)start2, gCHandle2.AddrOfPinnedObject(), byteWidth2); num++; start += widthStep; start2 += widthStep2; } gCHandle.Free(); gCHandle2.Free(); return image; } public Image Convert(Image img2, Func converter) where TDepth2 : new() where TDepth3 : new() { Image image = new Image(base.Width, base.Height); RoiParam(base.Ptr, out var start, out var rows, out var elementCount, out var byteWidth, out var widthStep); RoiParam(img2.Ptr, out var start2, out var _, out var _, out var byteWidth2, out var widthStep2); RoiParam(image.Ptr, out var start3, out var _, out var _, out var byteWidth3, out var widthStep3); TDepth[] array = new TDepth[elementCount]; TDepth2[] array2 = new TDepth2[elementCount]; TDepth3[] array3 = new TDepth3[elementCount]; GCHandle gCHandle = GCHandle.Alloc(array, GCHandleType.Pinned); GCHandle gCHandle2 = GCHandle.Alloc(array2, GCHandleType.Pinned); GCHandle gCHandle3 = GCHandle.Alloc(array3, GCHandleType.Pinned); int num = 0; while (num < rows) { CvToolbox.Memcpy(gCHandle.AddrOfPinnedObject(), (IntPtr)start, byteWidth); CvToolbox.Memcpy(gCHandle2.AddrOfPinnedObject(), (IntPtr)start2, byteWidth2); for (int i = 0; i < elementCount; i++) { array3[i] = converter(array[i], array2[i]); } CvToolbox.Memcpy((IntPtr)start3, gCHandle3.AddrOfPinnedObject(), byteWidth3); num++; start += widthStep; start2 += widthStep2; start3 += widthStep3; } gCHandle.Free(); gCHandle2.Free(); gCHandle3.Free(); return image; } public Image Convert(Image img2, Image img3, Func converter) where TDepth2 : new() where TDepth3 : new() where TDepth4 : new() { Image image = new Image(base.Width, base.Height); RoiParam(base.Ptr, out var start, out var rows, out var elementCount, out var byteWidth, out var widthStep); RoiParam(img2.Ptr, out var start2, out var _, out var _, out var byteWidth2, out var widthStep2); RoiParam(img3.Ptr, out var start3, out var _, out var _, out var byteWidth3, out var widthStep3); RoiParam(image.Ptr, out var start4, out var _, out var _, out var byteWidth4, out var widthStep4); TDepth[] array = new TDepth[elementCount]; TDepth2[] array2 = new TDepth2[elementCount]; TDepth3[] array3 = new TDepth3[elementCount]; TDepth4[] array4 = new TDepth4[elementCount]; GCHandle gCHandle = GCHandle.Alloc(array, GCHandleType.Pinned); GCHandle gCHandle2 = GCHandle.Alloc(array2, GCHandleType.Pinned); GCHandle gCHandle3 = GCHandle.Alloc(array3, GCHandleType.Pinned); GCHandle gCHandle4 = GCHandle.Alloc(array4, GCHandleType.Pinned); int num = 0; while (num < rows) { CvToolbox.Memcpy(gCHandle.AddrOfPinnedObject(), (IntPtr)start, byteWidth); CvToolbox.Memcpy(gCHandle2.AddrOfPinnedObject(), (IntPtr)start2, byteWidth2); CvToolbox.Memcpy(gCHandle3.AddrOfPinnedObject(), (IntPtr)start3, byteWidth3); for (int i = 0; i < elementCount; i++) { array4[i] = converter(array[i], array2[i], array3[i]); } CvToolbox.Memcpy((IntPtr)start4, gCHandle4.AddrOfPinnedObject(), byteWidth4); num++; start += widthStep; start2 += widthStep2; start3 += widthStep3; start4 += widthStep4; } gCHandle.Free(); gCHandle2.Free(); gCHandle3.Free(); gCHandle4.Free(); return image; } public Image Convert(Image img2, Image img3, Image img4, Func converter) where TDepth2 : new() where TDepth3 : new() where TDepth4 : new() where TDepth5 : new() { Image image = new Image(base.Width, base.Height); RoiParam(base.Ptr, out var start, out var rows, out var elementCount, out var byteWidth, out var widthStep); RoiParam(img2.Ptr, out var start2, out var _, out var _, out var byteWidth2, out var widthStep2); RoiParam(img3.Ptr, out var start3, out var _, out var _, out var byteWidth3, out var widthStep3); RoiParam(img4.Ptr, out var start4, out var _, out var _, out var byteWidth4, out var widthStep4); RoiParam(image.Ptr, out var start5, out var _, out var _, out var byteWidth5, out var widthStep5); TDepth[] array = new TDepth[elementCount]; TDepth2[] array2 = new TDepth2[elementCount]; TDepth3[] array3 = new TDepth3[elementCount]; TDepth4[] array4 = new TDepth4[elementCount]; TDepth5[] array5 = new TDepth5[elementCount]; GCHandle gCHandle = GCHandle.Alloc(array, GCHandleType.Pinned); GCHandle gCHandle2 = GCHandle.Alloc(array2, GCHandleType.Pinned); GCHandle gCHandle3 = GCHandle.Alloc(array3, GCHandleType.Pinned); GCHandle gCHandle4 = GCHandle.Alloc(array4, GCHandleType.Pinned); GCHandle gCHandle5 = GCHandle.Alloc(array5, GCHandleType.Pinned); int num = 0; while (num < rows) { CvToolbox.Memcpy(gCHandle.AddrOfPinnedObject(), (IntPtr)start, byteWidth); CvToolbox.Memcpy(gCHandle2.AddrOfPinnedObject(), (IntPtr)start2, byteWidth2); CvToolbox.Memcpy(gCHandle3.AddrOfPinnedObject(), (IntPtr)start3, byteWidth3); CvToolbox.Memcpy(gCHandle4.AddrOfPinnedObject(), (IntPtr)start4, byteWidth4); for (int i = 0; i < elementCount; i++) { array5[i] = converter(array[i], array2[i], array3[i], array4[i]); } CvToolbox.Memcpy((IntPtr)start5, gCHandle5.AddrOfPinnedObject(), byteWidth5); num++; start += widthStep; start2 += widthStep2; start3 += widthStep3; start4 += widthStep4; start5 += widthStep5; } gCHandle.Free(); gCHandle2.Free(); gCHandle3.Free(); gCHandle4.Free(); gCHandle5.Free(); return image; } protected override void DisposeObject() { base.DisposeObject(); if (_ptr != IntPtr.Zero) { if (_imageDataReleaseMode == ImageDataReleaseMode.ReleaseHeaderOnly) { CvInvoke.cvReleaseImageHeader(ref _ptr); GC.RemoveMemoryPressure(StructSize.MIplImage); } else { CvInvoke.cvReleaseImage(ref _ptr); } } _array = null; } public static Imageoperator &(Image img1, Image img2) { return img1.And(img2); } public static Imageoperator &(Image img1, double val) { return img1.And(new TColor { MCvScalar = new MCvScalar(val, val, val, val) }); } public static Imageoperator &(double val, Image img1) { return img1.And(new TColor { MCvScalar = new MCvScalar(val, val, val, val) }); } public static Imageoperator &(Image img1, TColor val) { return img1.And(val); } public static Imageoperator &(TColor val, Image img1) { return img1.And(val); } public static Imageoperator |(Image img1, Image img2) { return img1.Or(img2); } public static Imageoperator |(Image img1, double val) { return img1.Or(new TColor { MCvScalar = new MCvScalar(val, val, val, val) }); } public static Imageoperator |(double val, Image img1) { return img1 | val; } public static Imageoperator |(Image img1, TColor val) { return img1.Or(val); } public static Imageoperator |(TColor val, Image img1) { return img1.Or(val); } public static Imageoperator ~(Image image) { return image.Not(); } public static Imageoperator +(Image img1, Image img2) { return img1.Add(img2); } public static Imageoperator +(double val, Image img1) { return img1 + val; } public static Imageoperator +(Image image, double value) { return image.Add(new TColor { MCvScalar = new MCvScalar(value, value, value, value) }); } public static Imageoperator +(Image image, TColor value) { return image.Add(value); } public static Imageoperator +(TColor value, Image image) { return image.Add(value); } public static Imageoperator -(Image image1, Image image2) { return image1.Sub(image2); } public static Imageoperator -(Image image, TColor value) { return image.Sub(value); } public static Imageoperator -(TColor value, Image image) { return image.SubR(value); } public static Imageoperator -(double value, Image image) { return image.SubR(new TColor { MCvScalar = new MCvScalar(value, value, value, value) }); } public static Imageoperator -(Image image, double value) { return image.Sub(new TColor { MCvScalar = new MCvScalar(value, value, value, value) }); } public static Imageoperator *(Image image, double scale) { return image.Mul(scale); } public static Imageoperator *(double scale, Image image) { return image.Mul(scale); } public static Imageoperator *(Image image, ConvolutionKernelF kernel) { return image.Convolution(kernel); } public static Imageoperator /(Image image, double scale) { return image.Mul(1.0 / scale); } public static Imageoperator /(double scale, Image image) { Image image2 = image.CopyBlank(); using ScalarArray src = new ScalarArray(scale); CvInvoke.Divide(src, image, image2, 1.0, CvInvoke.GetDepthType(typeof(TDepth))); return image2; } public Image SmoothBlur(int width, int height) { return SmoothBlur(width, height, scale: true); } [ExposableMethod(Exposable = true, Category = "Smoothing")] public Image SmoothBlur(int width, int height, bool scale) { Image image = CopyBlank(); CvInvoke.BoxFilter(this, image, CvInvoke.GetDepthType(typeof(TDepth)), new Size(width, height), new Point(-1, -1), scale); return image; } [ExposableMethod(Exposable = true, Category = "Smoothing")] public Image SmoothMedian(int size) { Image image = CopyBlank(); CvInvoke.MedianBlur(this, image, size); return image; } [ExposableMethod(Exposable = true, Category = "Smoothing")] public Image SmoothBilateral(int kernelSize, int colorSigma, int spaceSigma) { Image image = CopyBlank(); CvInvoke.BilateralFilter(this, image, kernelSize, colorSigma, spaceSigma); return image; } public Image SmoothGaussian(int kernelSize) { return SmoothGaussian(kernelSize, kernelSize, 0.0, 0.0); } [ExposableMethod(Exposable = true, Category = "Smoothing")] public Image SmoothGaussian(int kernelWidth, int kernelHeight, double sigma1, double sigma2) { Image image = CopyBlank(); CvInvoke.GaussianBlur(this, image, new Size(kernelWidth, kernelHeight), sigma1, sigma2); return image; } public void _SmoothGaussian(int kernelSize) { _SmoothGaussian(kernelSize, kernelSize, 0.0, 0.0); } public void _SmoothGaussian(int kernelWidth, int kernelHeight, double sigma1, double sigma2) { CvInvoke.GaussianBlur(this, this, new Size(kernelWidth, kernelHeight), sigma1, sigma2); } public Image Convolution(ConvolutionKernelF kernel, double delta = 0.0, BorderType borderType = BorderType.Reflect101) { Image image = ((typeof(TDepth) == typeof(float)) ? (this as Image) : Convert()); try { Size size = Size; Image image2 = new Image(size); int numberOfChannels = NumberOfChannels; if (numberOfChannels == 1) { CvInvoke.Filter2D(image, image2, kernel, kernel.Center, delta, borderType); } else { using Mat mat = new Mat(size, DepthType.Cv32F, 1); using Mat mat2 = new Mat(size, DepthType.Cv32F, 1); for (int i = 0; i < numberOfChannels; i++) { CvInvoke.ExtractChannel(image, mat, i); CvInvoke.Filter2D(mat, mat2, kernel, kernel.Center, delta, borderType); CvInvoke.InsertChannel(mat2, image2, i); } } return image2; } finally { if (image != this) { image.Dispose(); } } } public Image Integral() { Image image = new Image(base.Width + 1, base.Height + 1); CvInvoke.Integral(this, image, null, null, DepthType.Cv64F); return image; } public void Integral(out Image sum, out Image squareSum) { sum = new Image(base.Width + 1, base.Height + 1); squareSum = new Image(base.Width + 1, base.Height + 1); CvInvoke.Integral(this, sum, squareSum, null, DepthType.Cv64F); } public void Integral(out Image sum, out Image squareSum, out Image titledSum) { sum = new Image(base.Width + 1, base.Height + 1); squareSum = new Image(base.Width + 1, base.Height + 1); titledSum = new Image(base.Width + 1, base.Height + 1); CvInvoke.Integral(this, sum, squareSum, titledSum, DepthType.Cv64F); } [ExposableMethod(Exposable = true, Category = "Threshold")] public Image ThresholdAdaptive(TColor maxValue, AdaptiveThresholdType adaptiveType, ThresholdType thresholdType, int blockSize, TColor param1) { double[] max = maxValue.MCvScalar.ToArray(); double[] p1 = param1.MCvScalar.ToArray(); Image image = CopyBlank(); ForEachDuplicateChannel(delegate(IInputArray src, IOutputArray dst, int channel) { CvInvoke.AdaptiveThreshold(src, dst, max[channel], adaptiveType, thresholdType, blockSize, p1[channel]); }, image); return image; } private void ThresholdBase(Image dest, TColor threshold, TColor maxValue, ThresholdType threshType) { double[] t = threshold.MCvScalar.ToArray(); double[] i = maxValue.MCvScalar.ToArray(); ForEachDuplicateChannel(delegate(IInputArray src, IOutputArray dst, int channel) { CvInvoke.Threshold(src, dst, t[channel], i[channel], threshType); }, dest); } public Image ThresholdToZero(TColor threshold) { Image image = CopyBlank(); ThresholdBase(image, threshold, new TColor(), ThresholdType.ToZero); return image; } public Image ThresholdToZeroInv(TColor threshold) { Image image = CopyBlank(); ThresholdBase(image, threshold, new TColor(), ThresholdType.ToZeroInv); return image; } public Image ThresholdTrunc(TColor threshold) { Image image = CopyBlank(); ThresholdBase(image, threshold, new TColor(), ThresholdType.Trunc); return image; } public Image ThresholdBinary(TColor threshold, TColor maxValue) { Image image = CopyBlank(); ThresholdBase(image, threshold, maxValue, ThresholdType.Binary); return image; } public Image ThresholdBinaryInv(TColor threshold, TColor maxValue) { Image image = CopyBlank(); ThresholdBase(image, threshold, maxValue, ThresholdType.BinaryInv); return image; } [ExposableMethod(Exposable = true, Category = "Threshold")] public void _ThresholdToZero(TColor threshold) { ThresholdBase(this, threshold, new TColor(), ThresholdType.ToZero); } [ExposableMethod(Exposable = true, Category = "Threshold")] public void _ThresholdToZeroInv(TColor threshold) { ThresholdBase(this, threshold, new TColor(), ThresholdType.ToZeroInv); } [ExposableMethod(Exposable = true, Category = "Threshold")] public void _ThresholdTrunc(TColor threshold) { ThresholdBase(this, threshold, new TColor(), ThresholdType.Trunc); } [ExposableMethod(Exposable = true, Category = "Threshold")] public void _ThresholdBinary(TColor threshold, TColor maxValue) { ThresholdBase(this, threshold, maxValue, ThresholdType.Binary); } [ExposableMethod(Exposable = true, Category = "Threshold")] public void _ThresholdBinaryInv(TColor threshold, TColor maxValue) { ThresholdBase(this, threshold, maxValue, ThresholdType.BinaryInv); } public void AvgSdv(out TColor average, out MCvScalar sdv, Image mask) { average = new TColor(); MCvScalar mean = default(MCvScalar); sdv = default(MCvScalar); CvInvoke.MeanStdDev(this, ref mean, ref sdv, mask); average.MCvScalar = mean; } public void AvgSdv(out TColor avg, out MCvScalar sdv) { AvgSdv(out avg, out sdv, null); } public int[] CountNonzero() { using Mat mat = CvInvoke.CvArrToMat(this); if (NumberOfChannels == 1) { return new int[1] { CvInvoke.CountNonZero(mat) }; } int[] array = new int[NumberOfChannels]; using (Mat mat2 = new Mat()) { for (int i = 0; i < array.Length; i++) { CvInvoke.ExtractChannel(mat, mat2, i); array[i] = CvInvoke.CountNonZero(mat2); } } return array; } public void MinMax(out double[] minValues, out double[] maxValues, out Point[] minLocations, out Point[] maxLocations) { base.Mat.MinMax(out minValues, out maxValues, out minLocations, out maxLocations); } public Image Flip(FlipType flipType) { Image image = CopyBlank(); CvInvoke.Flip(this, image, flipType); return image; } [ExposableMethod(Exposable = true, Category = "Transform")] public void _Flip(FlipType flipType) { CvInvoke.Flip(this, this, flipType); } public Image ConcateVertical(Image otherImage) { Image image = new Image(Math.Max(base.Width, otherImage.Width), base.Height + otherImage.Height); image.ROI = ROI; CvInvoke.cvCopy(base.Ptr, image.Ptr, IntPtr.Zero); Rectangle rOI = otherImage.ROI; rOI.Y += base.Height; image.ROI = rOI; CvInvoke.cvCopy(otherImage.Ptr, image.Ptr, IntPtr.Zero); image.ROI = Rectangle.Empty; return image; } public Image ConcateHorizontal(Image otherImage) { Image image = new Image(base.Width + otherImage.Width, Math.Max(base.Height, otherImage.Height)); image.ROI = ROI; CvInvoke.cvCopy(base.Ptr, image.Ptr, IntPtr.Zero); Rectangle rOI = otherImage.ROI; rOI.X += base.Width; image.ROI = rOI; CvInvoke.cvCopy(otherImage.Ptr, image.Ptr, IntPtr.Zero); image.ROI = Rectangle.Empty; return image; } public Moments GetMoments(bool binary) { return CvInvoke.Moments(this, binary); } [ExposableMethod(Exposable = true)] public void _GammaCorrect(double gamma) { if (!(this is Image)) { throw new NotImplementedException("Gamma correction only implemented for Image of Byte as Depth"); } byte[,] array = new byte[256, 1]; for (int i = 0; i < 256; i++) { array[i, 0] = (byte)(Math.Pow((double)i / 255.0, gamma) * 255.0); } using Matrix matrix = new Matrix(array); Matrix matrix2; if (matrix.NumberOfChannels == 1) { matrix2 = matrix; } else { matrix2 = new Matrix(matrix.Rows, matrix.Cols, NumberOfChannels); using VectorOfMat vectorOfMat = new VectorOfMat(); for (int j = 0; j < NumberOfChannels; j++) { vectorOfMat.Push(matrix.Mat); } CvInvoke.Merge(vectorOfMat, matrix2); } CvInvoke.LUT(this, matrix2, this); if (matrix != matrix2) { matrix2.Dispose(); } } public Image[] Split() { if (NumberOfChannels == 1) { return new Image[1] { Copy() as Image }; } Image[] array = new Image[NumberOfChannels]; using VectorOfMat vectorOfMat = new VectorOfMat(); Size size = Size; for (int i = 0; i < NumberOfChannels; i++) { array[i] = new Image(size); vectorOfMat.Push(array[i].Mat); } CvInvoke.Split(this, vectorOfMat); return array; } public override void Save(string fileName) { if (NumberOfChannels == 3 && typeof(TColor) != typeof(Bgr)) { using (Mat mat = new Mat()) { CvInvoke.CvtColor(this, mat, typeof(TColor), typeof(Bgr)); mat.Save(fileName); return; } } if (NumberOfChannels == 4 && typeof(TColor) != typeof(Bgra)) { using (Mat mat2 = new Mat()) { CvInvoke.CvtColor(this, mat2, typeof(TColor), typeof(Bgra)); mat2.Save(fileName); return; } } base.Mat.Save(fileName); } [ExposableMethod(Exposable = true)] public void _EqualizeHist() { if (NumberOfChannels == 1) { CvInvoke.EqualizeHist(this, this); return; } Image image = (this as Image) ?? Convert(); using (Image image2 = new Image(Size)) { CvInvoke.MixChannels(image, image2, new int[2] { 1, 0 }); image2._EqualizeHist(); CvInvoke.MixChannels(image2, image, new int[2] { 0, 1 }); } if (this != image) { ConvertFrom(image); image.Dispose(); } } private void LoadImageFromMat(Mat mat) { Size size = mat.Size; AllocateData(size.Height, size.Width, NumberOfChannels); switch (mat.NumberOfChannels) { case 1: switch (mat.Depth) { case DepthType.Cv8U: { using Image srcImage8 = new Image(size.Width, size.Height, mat.Step, mat.DataPointer); ConvertFrom(srcImage8); break; } case DepthType.Cv16U: { using Image srcImage7 = new Image(size.Width, size.Height, mat.Step, mat.DataPointer); ConvertFrom(srcImage7); break; } case DepthType.Cv32F: { using Image srcImage6 = new Image(size.Width, size.Height, mat.Step, mat.DataPointer); ConvertFrom(srcImage6); break; } case DepthType.Cv64F: { using Image srcImage5 = new Image(size.Width, size.Height, mat.Step, mat.DataPointer); ConvertFrom(srcImage5); break; } default: throw new NotImplementedException($"Loading of {mat.Depth}, {mat.NumberOfChannels} channel image is not implemented."); } break; case 3: switch (mat.Depth) { case DepthType.Cv8U: { using Image srcImage4 = new Image(size.Width, size.Height, mat.Step, mat.DataPointer); ConvertFrom(srcImage4); break; } case DepthType.Cv16U: { using Image srcImage3 = new Image(size.Width, size.Height, mat.Step, mat.DataPointer); ConvertFrom(srcImage3); break; } case DepthType.Cv32F: { using Image srcImage2 = new Image(size.Width, size.Height, mat.Step, mat.DataPointer); ConvertFrom(srcImage2); break; } case DepthType.Cv64F: { using Image srcImage = new Image(size.Width, size.Height, mat.Step, mat.DataPointer); ConvertFrom(srcImage); break; } default: throw new NotImplementedException($"Loading of {mat.Depth}, {mat.NumberOfChannels} channel image is not implemented."); } break; default: throw new NotImplementedException($"Loading of {mat.Depth}, {mat.NumberOfChannels} channel image is not implemented."); } } private void LoadImageFromIplImagePtr(IntPtr iplImage) { MIplImage mIplImage = (MIplImage)Marshal.PtrToStructure(iplImage, typeof(MIplImage)); Size size = new Size(mIplImage.Width, mIplImage.Height); AllocateData(size.Height, size.Width, NumberOfChannels); if (mIplImage.NChannels == 1) { switch (mIplImage.Depth) { case IplDepth.IplDepth_8U: { using Image srcImage4 = new Image(mIplImage.Width, mIplImage.Height, mIplImage.WidthStep, mIplImage.ImageData); ConvertFrom(srcImage4); break; } case IplDepth.IplDepth16U: { using Image srcImage3 = new Image(mIplImage.Width, mIplImage.Height, mIplImage.WidthStep, mIplImage.ImageData); ConvertFrom(srcImage3); break; } case IplDepth.IplDepth32F: { using Image srcImage2 = new Image(mIplImage.Width, mIplImage.Height, mIplImage.WidthStep, mIplImage.ImageData); ConvertFrom(srcImage2); break; } case IplDepth.IplDepth64F: { using Image srcImage = new Image(mIplImage.Width, mIplImage.Height, mIplImage.WidthStep, mIplImage.ImageData); ConvertFrom(srcImage); break; } default: throw new NotImplementedException($"Loading of {mIplImage.Depth}, {mIplImage.NChannels} channel image is not implemented."); } return; } if (mIplImage.NChannels == 3) { switch (mIplImage.Depth) { case IplDepth.IplDepth_8U: { using Image srcImage8 = new Image(mIplImage.Width, mIplImage.Height, mIplImage.WidthStep, mIplImage.ImageData); ConvertFrom(srcImage8); break; } case IplDepth.IplDepth16U: { using Image srcImage7 = new Image(mIplImage.Width, mIplImage.Height, mIplImage.WidthStep, mIplImage.ImageData); ConvertFrom(srcImage7); break; } case IplDepth.IplDepth32F: { using Image srcImage6 = new Image(mIplImage.Width, mIplImage.Height, mIplImage.WidthStep, mIplImage.ImageData); ConvertFrom(srcImage6); break; } case IplDepth.IplDepth64F: { using Image srcImage5 = new Image(mIplImage.Width, mIplImage.Height, mIplImage.WidthStep, mIplImage.ImageData); ConvertFrom(srcImage5); break; } default: throw new NotImplementedException($"Loading of {mIplImage.Depth}, {mIplImage.NChannels} channel image is not implemented."); } return; } throw new NotImplementedException($"Loading of {mIplImage.Depth}, {mIplImage.NChannels} channel image is not implemented."); } public static Image FromIplImagePtr(IntPtr iplImage) { Image image = new Image(); image.LoadImageFromIplImagePtr(iplImage); return image; } public byte[] ToJpegData(int quality = 95) { using VectorOfByte vectorOfByte = new VectorOfByte(); CvInvoke.Imencode(".jpg", this, vectorOfByte, new KeyValuePair(ImwriteFlags.JpegQuality, quality)); return vectorOfByte.ToArray(); } } internal static class ImageConstants { public static readonly int RoiOffset = (int)Marshal.OffsetOf(typeof(MIplImage), "Roi"); } internal enum ImageDataReleaseMode { ReleaseHeaderOnly, ReleaseIplImage } public class InputArray : UnmanagedObject { [Flags] public enum Type { KindShift = 0x10, FixedType = int.MinValue, FixedSize = 0x40000000, KindMask = 0x1F0000, None = 0, Mat = 0x10000, Matx = 0x20000, StdVector = 0x30000, StdVectorVector = 0x40000, StdVectorMat = 0x50000, Expr = 0x60000, OpenglBuffer = 0x70000, CudaHostMem = 0x80000, CudaGpuMat = 0x90000, UMat = 0xA0000, StdVectorUMat = 0xB0000, StdBoolVector = 0xC0000, StdVectorCudaGpuMat = 0xD0000 } protected object _parent; private static InputArray _empty = new InputArray(); public bool IsEmpty { get { if (_ptr == IntPtr.Zero) { return true; } return CvInvoke.cveInputArrayIsEmpty(_ptr); } } public bool IsMat => CvInvoke.cveInputArrayIsMat(_ptr); public bool IsUMat => CvInvoke.cveInputArrayIsUMat(_ptr); public bool IsMatVector => CvInvoke.cveInputArrayIsMatVector(_ptr); public bool IsUMatVector => CvInvoke.cveInputArrayIsUMatVector(_ptr); public bool IsMatx => CvInvoke.cveInputArrayIsMatx(_ptr); public Type Kind => CvInvoke.cveInputArrayKind(_ptr); internal InputArray() { } public InputArray(IntPtr inputArrayPtr, object parent) { _ptr = inputArrayPtr; _parent = parent; } public static InputArray GetEmpty() { return _empty; } public Mat GetMat(int idx = -1) { Mat mat = new Mat(); CvInvoke.cveInputArrayGetMat(base.Ptr, idx, mat); return mat; } public UMat GetUMat(int idx = -1) { UMat uMat = new UMat(); CvInvoke.cveInputArrayGetUMat(base.Ptr, idx, uMat); return uMat; } public Size GetSize(int idx = -1) { Size size = default(Size); if (_ptr != IntPtr.Zero) { CvInvoke.cveInputArrayGetSize(_ptr, ref size, idx); } return size; } public DepthType GetDepth(int idx = -1) { if (_ptr == IntPtr.Zero) { return DepthType.Default; } return CvInvoke.cveInputArrayGetDepth(_ptr, idx); } public int GetDims(int i = -1) { return CvInvoke.cveInputArrayGetDims(_ptr, i); } public int GetChannels(int idx = -1) { if (_ptr == IntPtr.Zero) { return 0; } return CvInvoke.cveInputArrayGetChannels(_ptr, idx); } public void CopyTo(IOutputArray arr, IInputArray mask = null) { using OutputArray outputArray = arr.GetOutputArray(); using InputArray inputArray = ((mask == null) ? GetEmpty() : mask.GetInputArray()); CvInvoke.cveInputArrayCopyTo(_ptr, outputArray, inputArray); } protected override void DisposeObject() { if (_ptr != IntPtr.Zero) { CvInvoke.cveInputArrayRelease(ref _ptr); } _parent = null; } public GpuMat GetGpuMat() { GpuMat gpuMat = new GpuMat(); CvInvoke.cveInputArrayGetGpuMat(base.Ptr, gpuMat); return gpuMat; } } public class InputOutputArray : OutputArray { private static InputOutputArray _empty = new InputOutputArray(); internal InputOutputArray() { } public InputOutputArray(IntPtr inputOutputArrayPtr, object parent) : base(inputOutputArrayPtr, parent) { } public new static InputOutputArray GetEmpty() { return _empty; } protected override void DisposeObject() { if (_ptr != IntPtr.Zero) { CvInvoke.cveInputOutputArrayRelease(ref _ptr); } _parent = null; } } public interface IOutputArray : IInputArray, IDisposable { OutputArray GetOutputArray(); } public interface IOutputArrayOfArrays : IOutputArray, IInputArray, IDisposable { } [Serializable] public class Map : Image where TColor : struct, IColor where TDepth : new() { private RectangleF _area; private PointF _resolution; public RectangleF Area => _area; public PointF Resolution => _resolution; public new RectangleF ROI { get { return ImageRectangleToMapRectangle(base.ROI); } set { if (value.Equals((object?)RectangleF.Empty)) { CvInvoke.cvResetImageROI(base.Ptr); } else { base.ROI = MapRectangleToImageRectangle(value); } } } public Map(RectangleF area, PointF resolution, TColor color) : this(area, resolution) { SetValue(color); } public Map(RectangleF area, PointF resolution) : base((int)Math.Round(area.Width / resolution.X), (int)Math.Round(area.Height / resolution.Y)) { _area = area; _resolution = resolution; } public Point MapPointToImagePoint(MCvPoint2D64f pt) { return new Point((int)Math.Round((pt.X - (double)Area.Left) / (double)Resolution.X), (int)Math.Round((pt.Y - (double)Area.Top) / (double)Resolution.Y)); } public Point MapPointToImagePoint(PointF pt) { return new Point((int)Math.Round((pt.X - Area.Left) / Resolution.X), (int)Math.Round((pt.Y - Area.Top) / Resolution.Y)); } private Rectangle MapRectangleToImageRectangle(RectangleF rect) { return new Rectangle(MapPointToImagePoint(rect.Location), new Size((int)(rect.Width / Resolution.X), (int)(rect.Height / Resolution.Y))); } public PointF ImagePointToMapPoint(Point pt) { return new PointF((float)pt.X * Resolution.X + Area.Left, (float)pt.Y * Resolution.Y + Area.Top); } private RectangleF ImageRectangleToMapRectangle(Rectangle rect) { return new RectangleF(ImagePointToMapPoint(rect.Location), new SizeF((float)rect.Width * Resolution.X, (float)rect.Height * Resolution.Y)); } public Map Copy(RectangleF area) { Map map = new Map(area, _resolution); if (Area.Contains(area)) { ROI = area; CvInvoke.cvCopy(base.Ptr, map, IntPtr.Zero); ROI = RectangleF.Empty; } else if (Area.IntersectsWith(area)) { RectangleF area2 = Area; area2.Intersect(area); ROI = area2; map.ROI = area2; CvInvoke.cvCopy(base.Ptr, map, IntPtr.Zero); ROI = RectangleF.Empty; map.ROI = RectangleF.Empty; } return map; } public void Draw(RectangleF rect, TColor color, int thickness) { base.Draw(new Rectangle(MapPointToImagePoint(new PointF(rect.Left + rect.Width / 2f, rect.Top + rect.Height / 2f)), new Size((int)(rect.Width / Resolution.X), (int)(rect.Height / Resolution.Y))), color, thickness); } public override void Draw(LineSegment2DF line, TColor color, int thickness, LineType lineType = LineType.EightConnected, int shift = 0) { base.Draw(new LineSegment2DF(MapPointToImagePoint(line.P1), MapPointToImagePoint(line.P2)), color, thickness, lineType, shift); } public override void Draw(CircleF circle, TColor color, int thickness = 1, LineType lineType = LineType.EightConnected, int shift = 0) { base.Draw(new CircleF(MapPointToImagePoint(circle.Center), circle.Radius / Resolution.X), color, thickness, lineType, shift); } public override void Draw(IConvexPolygonF polygon, TColor color, int thickness) { PointF[] vertices = polygon.GetVertices(); Point[] array = new Point[vertices.Length]; for (int i = 0; i < vertices.Length; i++) { array[i] = MapPointToImagePoint(vertices[i]); } if (thickness > 0) { DrawPolyline(array, isClosed: true, color, thickness); } else { FillConvexPoly(array, color); } } public override void Draw(string message, Point bottomLeft, FontFace fontFace, double fontScale, TColor color, int thickness = 1, LineType lineType = LineType.EightConnected, bool bottomLeftOrigin = false) { base.Draw(message, MapPointToImagePoint(bottomLeft), fontFace, fontScale, color, thickness, lineType, bottomLeftOrigin); } public void DrawPolyline(PointF[] pts, bool isClosed, TColor color, int thickness) { Point[] array = new Point[pts.Length]; for (int i = 0; i < array.Length; i++) { pts[i] = MapPointToImagePoint(pts[i]); } DrawPolyline(array, isClosed, color, thickness); } public Map(SerializationInfo info, StreamingContext context) : base(info, context) { _area = (RectangleF)info.GetValue("Area", typeof(RectangleF)); _resolution = (PointF)info.GetValue("Resolution", typeof(PointF)); } public override void GetObjectData(SerializationInfo info, StreamingContext context) { base.GetObjectData(info, context); info.AddValue("Area", _area); info.AddValue("Resolution", _resolution); } } [Serializable] [DebuggerTypeProxy(typeof(DebuggerProxy))] public class Mat : UnmanagedObject, IEquatable, IInputOutputArray, IInputArray, IDisposable, IOutputArray, IInputArrayOfArrays, IOutputArrayOfArrays, ISerializable { internal class MatWithHandle : Mat { private GCHandle _handle; public MatWithHandle(GCHandle handle, Size s, DepthType dt, int channels, int step) : base(s, dt, channels, handle.AddrOfPinnedObject(), step) { _handle = handle; } protected override void ReleaseManagedResources() { base.ReleaseManagedResources(); _handle.Free(); } } internal class DebuggerProxy { private Mat _v; public Array Data => _v.GetData(); public DebuggerProxy(Mat v) { _v = v; } } internal bool _needDispose; internal object _parent; private byte[] Bytes { get { if (IsEmpty) { return null; } byte[] array = new byte[Total.ToInt32() * ElementSize]; CopyTo(array); return array; } set { SetTo(value); } } public Size Size { get { Size s = default(Size); MatInvoke.cveMatGetSize(_ptr, ref s); return s; } } public int Rows => Size.Height; public int Cols => Size.Width; public IntPtr DataPointer => MatInvoke.cveMatGetDataPointer(_ptr); public int Step => (int)MatInvoke.cveMatGetStep(_ptr); public int ElementSize => MatInvoke.cveMatGetElementSize(_ptr); public int Width => Size.Width; public int Height => Size.Height; public int[] SizeOfDimension { get { int[] array = new int[Dims]; GCHandle gCHandle = GCHandle.Alloc(array, GCHandleType.Pinned); try { MatInvoke.cveMatGetSizeOfDimension(_ptr, gCHandle.AddrOfPinnedObject()); return array; } finally { gCHandle.Free(); } } } public bool IsContinuous => CvInvoke.cveMatIsContinuous(_ptr); public bool IsSubmatrix => CvInvoke.cveMatIsSubmatrix(_ptr); public DepthType Depth => CvInvoke.cveMatDepth(_ptr); public bool IsEmpty => CvInvoke.cveMatIsEmpty(_ptr); public int NumberOfChannels => CvInvoke.cveMatNumberOfChannels(_ptr); public IntPtr Total => CvInvoke.cveMatTotal(_ptr); public int Dims => CvInvoke.cveMatGetDims(_ptr); public Mat(SerializationInfo info, StreamingContext context) : this() { DeserializeObjectData(info, context); } protected virtual void DeserializeObjectData(SerializationInfo info, StreamingContext context) { int rows = (int)info.GetValue("Rows", typeof(int)); int cols = (int)info.GetValue("Cols", typeof(int)); int type = (int)info.GetValue("DepthType", typeof(int)); int channels = (int)info.GetValue("NumberOfChannels", typeof(int)); Create(rows, cols, (DepthType)type, channels); Bytes = (byte[])info.GetValue("Bytes", typeof(byte[])); } public void GetObjectData(SerializationInfo info, StreamingContext context) { info.AddValue("Rows", Rows); info.AddValue("Cols", Cols); info.AddValue("DepthType", (int)Depth); info.AddValue("NumberOfChannels", NumberOfChannels); info.AddValue("Bytes", Bytes); } public void CopyTo(T[] data) { GCHandle gCHandle = GCHandle.Alloc(data, GCHandleType.Pinned); MatInvoke.cveMatCopyDataTo(this, gCHandle.AddrOfPinnedObject()); gCHandle.Free(); } public void SetTo(T[] data) { GCHandle gCHandle = GCHandle.Alloc(data, GCHandleType.Pinned); MatInvoke.cveMatCopyDataFrom(this, gCHandle.AddrOfPinnedObject()); gCHandle.Free(); } internal Mat(IntPtr ptr, bool needDispose, bool useCustomMemAllocator = false) { _ptr = ptr; _needDispose = needDispose; } public Mat() : this(MatInvoke.cveMatCreate(), needDispose: true, useCustomMemAllocator: true) { } public Mat(int rows, int cols, DepthType type, int channels) : this() { Create(rows, cols, type, channels); } public Mat(Size size, DepthType type, int channels) : this(size.Height, size.Width, type, channels) { } public Mat(int rows, int cols, DepthType type, int channels, IntPtr data, int step) : this(MatInvoke.cveMatCreateWithData(rows, cols, CvInvoke.MakeType(type, channels), data, new IntPtr(step)), needDispose: true, useCustomMemAllocator: true) { } public Mat(int[] sizes, DepthType type, IntPtr data, IntPtr[] steps = null) : this(MatInvoke.cveMatCreateMultiDimWithData(sizes, type, data, steps), needDispose: true, useCustomMemAllocator: true) { } public Mat(Size size, DepthType type, int channels, IntPtr data, int step) : this(size.Height, size.Width, type, channels, data, step) { } public Mat(string fileName, ImreadModes loadType = ImreadModes.Color) : this(MatInvoke.cveMatCreate(), needDispose: true) { FileInfo fileInfo = new FileInfo(fileName); if (!fileInfo.Exists) { throw new ArgumentException($"File {fileName} do not exist"); } if (fileInfo.Extension.ToLower().Equals(".png") && (Platform.OperationSystem == Platform.OS.IOS || Platform.OperationSystem == Platform.OS.MacOS) && NativeMatFileIO.ReadFileToMat(fileName, this, loadType)) { return; } using CvString cvString = new CvString(fileName); CvInvoke.cveImread(cvString, loadType, this); if (IsEmpty) { CvInvoke.Imdecode(File.ReadAllBytes(fileName), loadType, this); if (IsEmpty && !NativeMatFileIO.ReadFileToMat(fileName, this, loadType)) { throw new ArgumentException($"Unable to decode file: {fileName}"); } } } public Mat(Mat mat, Rectangle roi) : this(MatInvoke.cveMatCreateFromRect(mat.Ptr, ref roi), needDispose: true, useCustomMemAllocator: true) { } public Mat(Mat mat, Emgu.CV.Structure.Range rowRange, Emgu.CV.Structure.Range colRange) : this(MatInvoke.cveMatCreateFromRange(mat.Ptr, ref rowRange, ref colRange), needDispose: true, useCustomMemAllocator: true) { } public UMat GetUMat(AccessType access, UMat.Usage usageFlags = UMat.Usage.Default) { return new UMat(MatInvoke.cveMatGetUMat(base.Ptr, access, usageFlags), needDispose: true); } public void Create(int rows, int cols, DepthType type, int channels) { MatInvoke.cveMatCreateData(_ptr, rows, cols, CvInvoke.MakeType(type, channels)); } public IntPtr GetDataPointer(params int[] index) { if (index.Length == 0) { return DataPointer; } int[] array = new int[Dims]; Array.Copy(index, array, index.Length); GCHandle gCHandle = GCHandle.Alloc(array, GCHandleType.Pinned); IntPtr result = MatInvoke.cveMatGetDataPointer2(base.Ptr, gCHandle.AddrOfPinnedObject()); gCHandle.Free(); return result; } public Array GetData(bool jagged = true) { if (IsEmpty) { return null; } Type depthType = CvInvoke.GetDepthType(Depth); if (depthType == null) { return null; } int num = Total.ToInt32() * ElementSize; Array array; if (jagged) { int[] sizeOfDimension = SizeOfDimension; int numberOfChannels = NumberOfChannels; if (numberOfChannels == 1) { array = Array.CreateInstance(depthType, sizeOfDimension); } else { int[] array2 = new int[sizeOfDimension.Length + 1]; Array.Copy(sizeOfDimension, array2, sizeOfDimension.Length); array2[^1] = numberOfChannels; array = Array.CreateInstance(depthType, array2); } } else { int length = num / Marshal.SizeOf(depthType); array = Array.CreateInstance(depthType, length); } GCHandle gCHandle = GCHandle.Alloc(array, GCHandleType.Pinned); CvInvoke.cveMemcpy(gCHandle.AddrOfPinnedObject(), DataPointer, num); gCHandle.Free(); return array; } public byte[] GetRawData(params int[] indices) { switch (indices.Length) { case 0: return Bytes; case 1: { if (IsEmpty) { return null; } int y = indices[0]; byte[] array2 = new byte[Cols * ElementSize]; GCHandle gCHandle = GCHandle.Alloc(array2, GCHandleType.Pinned); using (Mat mat = Row(y)) { using Mat m = new Mat(1, Cols, Depth, NumberOfChannels, gCHandle.AddrOfPinnedObject(), Cols * ElementSize); mat.CopyTo(m); } gCHandle.Free(); return array2; } case 2: { if (IsEmpty) { return null; } int num = indices[0]; int num2 = indices[1]; byte[] array = new byte[ElementSize]; Marshal.Copy(new IntPtr(DataPointer.ToInt64() + num * Step + num2 * array.Length), array, 0, array.Length); return array; } default: throw new NotImplementedException($"GetRawData with indices size {indices.Length} is not implemented"); } } public void CopyTo(IOutputArray m, IInputArray mask = null) { using OutputArray outputArray = m.GetOutputArray(); using InputArray inputArray = ((mask == null) ? InputArray.GetEmpty() : mask.GetInputArray()); MatInvoke.cveMatCopyTo(base.Ptr, outputArray, inputArray); } public void ConvertTo(IOutputArray m, DepthType rtype, double alpha = 1.0, double beta = 0.0) { using OutputArray outputArray = m.GetOutputArray(); MatInvoke.cveMatConvertTo(base.Ptr, outputArray, rtype, alpha, beta); } public Mat Reshape(int cn, int rows = 0) { return new Mat(MatInvoke.cveMatReshape(base.Ptr, cn, rows), needDispose: true); } protected override void DisposeObject() { if (_needDispose && _ptr != IntPtr.Zero) { MatInvoke.cveMatRelease(ref _ptr); } } public InputArray GetInputArray() { return new InputArray(MatInvoke.cveInputArrayFromMat(_ptr), this); } public OutputArray GetOutputArray() { return new OutputArray(MatInvoke.cveOutputArrayFromMat(_ptr), this); } public InputOutputArray GetInputOutputArray() { return new InputOutputArray(MatInvoke.cveInputOutputArrayFromMat(_ptr), this); } public RangeF GetValueRange() { double minVal = 0.0; double maxVal = 0.0; Point minLoc = default(Point); Point maxLoc = default(Point); if (NumberOfChannels == 1) { CvInvoke.MinMaxLoc(this, ref minVal, ref maxVal, ref minLoc, ref maxLoc); } else { using Mat arr = Reshape(1); CvInvoke.MinMaxLoc(arr, ref minVal, ref maxVal, ref minLoc, ref maxLoc); } return new RangeF((float)minVal, (float)maxVal); } public Image ToImage(bool tryShareData = false) where TColor : struct, IColor where TDepth : new() { TColor val = new TColor(); int numberOfChannels = NumberOfChannels; if (typeof(TDepth) == CvInvoke.GetDepthType(Depth) && val.Dimension == numberOfChannels) { if (tryShareData) { return new Image(MatInvoke.cveMatToIplImage(base.Ptr)); } Image image = new Image(Size); CopyTo(image); return image; } if (typeof(TDepth) != CvInvoke.GetDepthType(Depth) && val.Dimension == numberOfChannels) { Image image2 = new Image(Size); ConvertTo(image2, CvInvoke.GetDepthType(typeof(TDepth))); return image2; } if (typeof(TDepth) == CvInvoke.GetDepthType(Depth) && val.Dimension != numberOfChannels) { Image image3 = new Image(Size); CvInvoke.CvtColor(this, image3, numberOfChannels switch { 3 => typeof(Bgr), 1 => typeof(Gray), _ => typeof(Bgra), }, typeof(TColor)); return image3; } using Mat mat = new Mat(); ConvertTo(mat, CvInvoke.GetDepthType(typeof(TDepth))); return mat.ToImage(); } internal static DepthType GetDepthTypeFromArray(Array data) { switch (data.Rank) { case 1: if (!(data is byte[])) { if (!(data is ushort[])) { if (!(data is short[])) { if (!(data is float[])) { if (!(data is int[])) { if (!(data is double[])) { return DepthType.Default; } return DepthType.Cv64F; } return DepthType.Cv32S; } return DepthType.Cv32F; } return DepthType.Cv16S; } return DepthType.Cv16U; } return DepthType.Cv8U; case 2: if (!(data is byte[,])) { if (!(data is ushort[,])) { if (!(data is short[,])) { if (!(data is float[,])) { if (!(data is int[,])) { if (!(data is double[,])) { return DepthType.Default; } return DepthType.Cv64F; } return DepthType.Cv32S; } return DepthType.Cv32F; } return DepthType.Cv16S; } return DepthType.Cv16U; } return DepthType.Cv8U; case 3: if (!(data is byte[,,])) { if (!(data is ushort[,,])) { if (!(data is short[,,])) { if (!(data is float[,,])) { if (!(data is int[,,])) { if (!(data is double[,,])) { return DepthType.Default; } return DepthType.Cv64F; } return DepthType.Cv32S; } return DepthType.Cv32F; } return DepthType.Cv16S; } return DepthType.Cv16U; } return DepthType.Cv8U; default: return DepthType.Default; } } public void SetTo(MCvScalar value, IInputArray mask = null) { using ScalarArray value2 = new ScalarArray(value); SetTo(value2, mask); } public void SetTo(IInputArray value, IInputArray mask = null) { using InputArray inputArray = value.GetInputArray(); using InputArray inputArray2 = ((mask == null) ? InputArray.GetEmpty() : mask.GetInputArray()); MatInvoke.cveMatSetTo(base.Ptr, inputArray, inputArray2); } public static Mat Eye(int rows, int cols, DepthType type, int channels) { Mat mat = new Mat(); MatInvoke.cveMatEye(rows, cols, CvInvoke.MakeType(type, channels), mat.Ptr); return mat; } public Mat Diag(int d = 0) { Mat mat = new Mat(); MatInvoke.cveMatDiag(base.Ptr, d, mat); return mat; } public Mat T() { Mat mat = new Mat(); MatInvoke.cveMatT(base.Ptr, mat); return mat; } public static Mat Zeros(int rows, int cols, DepthType type, int channels) { Mat mat = new Mat(); MatInvoke.cveMatZeros(rows, cols, CvInvoke.MakeType(type, channels), mat.Ptr); return mat; } public static Mat Ones(int rows, int cols, DepthType type, int channels) { Mat mat = new Mat(); MatInvoke.cveMatOnes(rows, cols, CvInvoke.MakeType(type, channels), mat.Ptr); return mat; } public void MinMax(out double[] minValues, out double[] maxValues, out Point[] minLocations, out Point[] maxLocations) { CvInvoke.MinMax(this, out minValues, out maxValues, out minLocations, out maxLocations); } public Mat Row(int y) { return new Mat(this, new Emgu.CV.Structure.Range(y, y + 1), Emgu.CV.Structure.Range.All); } public Mat Col(int x) { return new Mat(this, Emgu.CV.Structure.Range.All, new Emgu.CV.Structure.Range(x, x + 1)); } public void Save(string fileName) { Exception ex = null; try { if (!CvInvoke.Imwrite(fileName, this)) { ex = new Exception("Unable to save image"); } } catch (Exception ex2) { ex = ex2; } if (ex != null && !NativeMatFileIO.WriteMatToFile(this, fileName)) { throw ex; } } public Mat Clone() { Mat mat = new Mat(); CopyTo(mat); return mat; } public Mat[] Split() { Mat[] array = new Mat[NumberOfChannels]; Size size = Size; DepthType depth = Depth; for (int i = 0; i < array.Length; i++) { array[i] = new Mat(size, depth, 1); } using VectorOfMat mv = new VectorOfMat(array); CvInvoke.Split(this, mv); return array; } public bool Equals(Mat other) { if (!Size.Equals((object?)other.Size) || NumberOfChannels != other.NumberOfChannels || Depth != other.Depth) { return false; } using Mat mat = new Mat(); CvInvoke.Compare(this, other, mat, CmpType.NotEqual); using Mat arr = mat.Reshape(1); return CvInvoke.CountNonZero(arr) == 0; } public double Dot(IInputArray m) { using InputArray inputArray = m.GetInputArray(); return MatInvoke.cveMatDot(base.Ptr, inputArray); } public Mat Cross(IInputArray m) { Mat mat = new Mat(); using InputArray inputArray = m.GetInputArray(); MatInvoke.cveMatCross(base.Ptr, inputArray, mat); return mat; } public static Mat operator &(Mat mat1, Mat mat2) { Mat mat3 = new Mat(); CvInvoke.BitwiseAnd(mat1, mat2, mat3); return mat3; } public static Mat operator &(Mat mat1, double val) { using ScalarArray src = new ScalarArray(val); Mat mat2 = new Mat(); CvInvoke.BitwiseAnd(mat1, src, mat2); return mat2; } public static Mat operator &(double val, Mat mat1) { return mat1 & val; } public static Mat operator &(Mat mat1, MCvScalar val) { using ScalarArray src = new ScalarArray(val); Mat mat2 = new Mat(); CvInvoke.BitwiseAnd(mat1, src, mat2); return mat2; } public static Mat operator &(MCvScalar val, Mat mat1) { return mat1 & val; } public static Mat operator |(Mat mat1, Mat mat2) { Mat mat3 = new Mat(); CvInvoke.BitwiseOr(mat1, mat2, mat3); return mat3; } public static Mat operator |(Mat mat1, double val) { using ScalarArray src = new ScalarArray(val); Mat mat2 = new Mat(); CvInvoke.BitwiseOr(mat1, src, mat2); return mat2; } public static Mat operator |(double val, Mat mat1) { return mat1 | val; } public static Mat operator |(Mat mat1, MCvScalar val) { using ScalarArray src = new ScalarArray(val); Mat mat2 = new Mat(); CvInvoke.BitwiseOr(mat1, src, mat2); return mat2; } public static Mat operator |(MCvScalar val, Mat mat1) { return mat1 | val; } public static Mat operator ~(Mat mat) { Mat mat2 = new Mat(); CvInvoke.BitwiseNot(mat, mat2); return mat2; } public static Mat operator +(Mat mat1, Mat mat2) { Mat mat3 = new Mat(); CvInvoke.Add(mat1, mat2, mat3); return mat3; } public static Mat operator +(double value, Mat mat1) { return mat1 + value; } public static Mat operator +(Mat mat, double value) { using ScalarArray src = new ScalarArray(value); Mat mat2 = new Mat(); CvInvoke.Add(mat, src, mat2); return mat2; } public static Mat operator +(Mat mat, MCvScalar value) { using ScalarArray src = new ScalarArray(value); Mat mat2 = new Mat(); CvInvoke.Add(mat, src, mat2); return mat2; } public static Mat operator +(MCvScalar value, Mat mat) { return mat + value; } public static Mat operator -(Mat mat1, Mat mat2) { Mat mat3 = new Mat(); CvInvoke.Subtract(mat1, mat2, mat3); return mat3; } public static Mat operator -(Mat mat, MCvScalar value) { using ScalarArray src = new ScalarArray(value); Mat mat2 = new Mat(); CvInvoke.Subtract(mat, src, mat2); return mat2; } public static Mat operator -(MCvScalar value, Mat mat) { using ScalarArray src = new ScalarArray(value); Mat mat2 = new Mat(); CvInvoke.Subtract(src, mat, mat2); return mat2; } public static Mat operator -(double value, Mat mat) { using ScalarArray src = new ScalarArray(value); Mat mat2 = new Mat(); CvInvoke.Subtract(src, mat, mat2); return mat2; } public static Mat operator -(Mat mat, double value) { using ScalarArray src = new ScalarArray(value); Mat mat2 = new Mat(); CvInvoke.Subtract(mat, src, mat2); return mat2; } public static Mat operator *(Mat mat, double scale) { using ScalarArray src = new ScalarArray(scale); Mat mat2 = new Mat(); CvInvoke.Multiply(mat, src, mat2); return mat2; } public static Mat operator *(double scale, Mat mat) { return mat * scale; } public static Mat operator /(Mat mat, double scale) { return mat * (1.0 / scale); } public static Mat operator /(double scale, Mat mat) { using ScalarArray src = new ScalarArray(scale); Mat mat2 = new Mat(); CvInvoke.Divide(src, mat, mat2); return mat2; } public void PopBack(int value) { CvInvoke.cveMatPopBack(_ptr, value); } public void PushBack(Mat value) { CvInvoke.cveMatPushBack(_ptr, value); } } internal static class MatInvoke { static MatInvoke() { CvInvoke.Init(); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveInputArrayFromMat(IntPtr mat); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveOutputArrayFromMat(IntPtr mat); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveInputOutputArrayFromMat(IntPtr mat); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveMatCreate(); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveMatRelease(ref IntPtr mat); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveMatGetSize(IntPtr mat, ref Size s); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveMatCopyTo(IntPtr mat, IntPtr m, IntPtr mask); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int cveMatGetElementSize(IntPtr mat); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveMatGetDataPointer(IntPtr mat); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveMatGetDataPointer2(IntPtr mat, IntPtr indices); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveMatGetStep(IntPtr mat); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveMatCreateData(IntPtr mat, int row, int cols, int type); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveMatCreateWithData(int rows, int cols, int type, IntPtr data, IntPtr step); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveMatCreateFromRect(IntPtr mat, ref Rectangle roi); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveMatCreateFromRange(IntPtr mat, ref Emgu.CV.Structure.Range rowRange, ref Emgu.CV.Structure.Range colRange); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveMatGetUMat(IntPtr mat, AccessType access, UMat.Usage usageFlags); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveMatSetTo(IntPtr mat, IntPtr value, IntPtr mask); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveMatConvertTo(IntPtr mat, IntPtr outArray, DepthType rtype, double alpha, double beta); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveMatReshape(IntPtr mat, int cn, int rows); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveMatToIplImage(IntPtr mat); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern double cveMatDot(IntPtr mat, IntPtr m); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveMatCross(IntPtr mat, IntPtr m, IntPtr result); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveMatCopyDataTo(IntPtr mat, IntPtr dest); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveMatCopyDataFrom(IntPtr mat, IntPtr source); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveMatGetSizeOfDimension(IntPtr mat, IntPtr sizes); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern IntPtr cveMatCreateMultiDimWithData(int ndims, IntPtr sizes, DepthType type, IntPtr data, IntPtr steps); internal static IntPtr cveMatCreateMultiDimWithData(int[] sizes, DepthType type, IntPtr data, IntPtr[] steps) { GCHandle gCHandle = GCHandle.Alloc(sizes, GCHandleType.Pinned); try { if (steps == null) { return cveMatCreateMultiDimWithData(sizes.Length, gCHandle.AddrOfPinnedObject(), type, data, IntPtr.Zero); } GCHandle gCHandle2 = GCHandle.Alloc(steps, GCHandleType.Pinned); try { return cveMatCreateMultiDimWithData(sizes.Length, gCHandle.AddrOfPinnedObject(), type, data, gCHandle2.AddrOfPinnedObject()); } finally { gCHandle2.Free(); } } finally { gCHandle.Free(); } } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveMatEye(int rows, int cols, int type, IntPtr m); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveMatDiag(IntPtr src, int d, IntPtr dst); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveMatT(IntPtr src, IntPtr dst); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveMatZeros(int rows, int cols, int type, IntPtr dst); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveMatOnes(int rows, int cols, int type, IntPtr dst); } [Serializable] public class MatND : CvArray, IEquatable> where TDepth : new() { private Array _array; public override int NumberOfChannels { get { throw new Exception("The method or operation is not implemented."); } } public override Array ManagedArray { get { return _array; } set { AllocateHeader(); if (_dataHandle.IsAllocated) { _dataHandle.Free(); } _array = value; _dataHandle = GCHandle.Alloc(_array, GCHandleType.Pinned); int[] array = new int[_array.Rank]; for (int i = 0; i < array.Length; i++) { array[i] = _array.GetLength(i); } CvInvoke.cvInitMatNDHeader(_ptr, array.Length, array, CvDepth, _dataHandle.AddrOfPinnedObject()); } } protected static DepthType CvDepth => CvInvoke.GetDepthType(typeof(TDepth)); public MCvMatND MCvMatND => (MCvMatND)Marshal.PtrToStructure(_ptr, typeof(MCvMatND)); public MatND(params int[] sizes) { ManagedArray = Array.CreateInstance(typeof(TDepth), sizes); } public MatND(SerializationInfo info, StreamingContext context) { DeserializeObjectData(info, context); } protected override void AllocateData(int rows, int cols, int numberOfChannels) { throw new Exception("The method or operation is not implemented."); } private void AllocateHeader() { if (_ptr == IntPtr.Zero) { _ptr = Marshal.AllocHGlobal(StructSize.MCvMatND); GC.AddMemoryPressure(StructSize.MCvMatND); } } private int[] GetDimension() { MCvMatND mCvMatND = MCvMatND; int[] array = new int[mCvMatND.dims]; for (int i = 0; i < array.Length; i++) { array[i] = mCvMatND.dim[i].Size; } return array; } protected override void DisposeObject() { base.DisposeObject(); if (_ptr != IntPtr.Zero) { Marshal.FreeHGlobal(_ptr); GC.RemoveMemoryPressure(StructSize.MCvMatND); _ptr = IntPtr.Zero; } _array = null; } public override void GetObjectData(SerializationInfo info, StreamingContext context) { info.AddValue("Dimension", GetDimension()); info.AddValue("CompressionRatio", base.SerializationCompressionRatio); info.AddValue("Bytes", base.Bytes); } protected override void DeserializeObjectData(SerializationInfo info, StreamingContext context) { int[] lengths = (int[])info.GetValue("Dimension", typeof(int[])); ManagedArray = Array.CreateInstance(typeof(TDepth), lengths); base.SerializationCompressionRatio = (int)info.GetValue("CompressionRatio", typeof(int)); base.Bytes = (byte[])info.GetValue("Bytes", typeof(byte[])); } public override void ReadXml(XmlReader reader) { throw new NotImplementedException("This function is not implemented"); } public override void WriteXml(XmlWriter writer) { throw new NotImplementedException("This function is not implemented"); } public MatND Convert() where TOtherDepth : new() { MatND matND = new MatND(GetDimension()); CvInvoke.cvConvertScale(base.Ptr, matND.Ptr, 1.0, 0.0); return matND; } public bool Equals(MatND other) { int[] dimension = GetDimension(); int[] dimension2 = other.GetDimension(); if (dimension.Length != dimension2.Length) { return false; } for (int i = 0; i < dimension.Length; i++) { if (dimension[i] != dimension2[i]) { return false; } } using MatND matND = new MatND(dimension); CvInvoke.BitwiseXor(this, other, matND); return Array.TrueForAll(matND.Bytes, (byte b) => b == 0); } } [Serializable] public class Matrix : CvArray, IEquatable>, ICloneable where TDepth : new() { private TDepth[,] _array; public override Array ManagedArray { get { return Data; } set { if (!(value is TDepth[,] data)) { throw new InvalidCastException($"Cannot convert ManagedArray to type of {typeof(TDepth).ToString()}[,]."); } Data = data; } } public TDepth[,] Data { get { if (_array != null) { return _array; } Size size = Size; TDepth[,] array = new TDepth[size.Height, size.Width]; GCHandle gCHandle = GCHandle.Alloc(array, GCHandleType.Pinned); using (Matrix matrix = new Matrix(size.Height, size.Width, gCHandle.AddrOfPinnedObject())) { CvInvoke.cvCopy(_ptr, matrix._ptr, IntPtr.Zero); } gCHandle.Free(); return array; } set { AllocateHeader(); if (_dataHandle.IsAllocated) { _dataHandle.Free(); } _array = value; _dataHandle = GCHandle.Alloc(_array, GCHandleType.Pinned); CvInvoke.cvInitMatHeader(_ptr, _array.GetLength(0), _array.GetLength(1), CvInvoke.MakeType(CvInvoke.GetDepthType(typeof(TDepth)), 1), _dataHandle.AddrOfPinnedObject(), int.MaxValue); } } public override int NumberOfChannels => MCvMat.NumberOfChannels; public MCvMat MCvMat => (MCvMat)Marshal.PtrToStructure(base.Ptr, typeof(MCvMat)); [DebuggerBrowsable(DebuggerBrowsableState.Never)] public double Det => CvInvoke.Determinant(this); [DebuggerBrowsable(DebuggerBrowsableState.Never)] public double Sum => CvInvoke.Sum(this).V0; public TDepth this[int row, int col] { get { return (TDepth)System.Convert.ChangeType(CvInvoke.cvGetReal2D(base.Ptr, row, col), typeof(TDepth)); } set { CvInvoke.cvSet2D(base.Ptr, row, col, new MCvScalar(System.Convert.ToDouble(value))); } } public override Size Size { get { MCvMat mCvMat = MCvMat; return new Size(mCvMat.Width, mCvMat.Height); } } private void AllocateHeader() { if (_ptr == IntPtr.Zero) { _ptr = Marshal.AllocHGlobal(StructSize.MCvMat); GC.AddMemoryPressure(StructSize.MCvMat); } } protected Matrix() { } public Matrix(int rows, int cols, IntPtr data, int step) : this(rows, cols, 1, data, step) { } public Matrix(int rows, int cols, int channels, IntPtr data, int step) { AllocateHeader(); CvInvoke.cvInitMatHeader(_ptr, rows, cols, CvInvoke.MakeType(CvInvoke.GetDepthType(typeof(TDepth)), channels), data, step); } public Matrix(int rows, int cols, IntPtr data) : this(rows, cols, data, 0) { } public Matrix(int rows, int cols) : this(rows, cols, 1) { } public Matrix(Size size) : this(size.Height, size.Width) { } public Matrix(int rows, int cols, int channels) { AllocateData(rows, cols, channels); } public Matrix(TDepth[,] data) { Data = data; } public Matrix(TDepth[] data) { TDepth[,] array = new TDepth[data.Length, 1]; Buffer.BlockCopy(data, 0, array, 0, data.Length * CvArray.SizeOfElement); Data = array; } public Matrix CopyBlank() { return new Matrix(base.Rows, base.Cols, NumberOfChannels); } public virtual Matrix Clone() { Matrix matrix = new Matrix(base.Rows, base.Cols, NumberOfChannels); CvInvoke.cvCopy(base.Ptr, matrix.Ptr, IntPtr.Zero); return matrix; } public Matrix Reshape(int newChannels, int newRows) { Matrix matrix = new Matrix(); matrix._array = _array; matrix.AllocateHeader(); CvInvoke.cvReshape(base.Ptr, matrix.Ptr, newChannels, newRows); return matrix; } public Matrix Convert(double scale = 1.0, double shift = 0.0) where TOtherDepth : new() { Matrix matrix = new Matrix(base.Rows, base.Cols, NumberOfChannels); CvInvoke.cvConvertScale(base.Ptr, matrix.Ptr, scale, shift); return matrix; } public Matrix Transpose() { Matrix matrix = new Matrix(base.Cols, base.Rows); CvInvoke.Transpose(this, matrix); return matrix; } protected override void AllocateData(int rows, int cols, int numberOfChannels) { Data = new TDepth[rows, cols * numberOfChannels]; if (numberOfChannels > 1) { CvInvoke.cvReshape(_ptr, _ptr, numberOfChannels, 0); } } public Matrix GetSubRect(Rectangle rect) { Matrix matrix = new Matrix(); matrix._array = _array; matrix.AllocateHeader(); CvInvoke.cvGetSubRect(_ptr, matrix.Ptr, rect); return matrix; } public Matrix GetRow(int row) { return GetRows(row, row + 1, 1); } public Matrix GetRows(int startRow, int endRow, int deltaRow) { Matrix matrix = new Matrix(); matrix._array = _array; matrix.AllocateHeader(); matrix._ptr = CvInvoke.cvGetRows(_ptr, matrix.Ptr, startRow, endRow, deltaRow); return matrix; } public Matrix GetCol(int col) { return GetCols(col, col + 1); } public Matrix GetCols(int startCol, int endCol) { Matrix matrix = new Matrix(); matrix._array = _array; matrix.AllocateHeader(); matrix._ptr = CvInvoke.cvGetCols(_ptr, matrix.Ptr, startCol, endCol); return matrix; } public Matrix GetDiag(int diag) { Matrix matrix = new Matrix(); matrix._array = _array; matrix.AllocateHeader(); matrix._ptr = CvInvoke.cvGetDiag(_ptr, matrix.Ptr, diag); return matrix; } public Matrix GetDiag() { return GetDiag(0); } public Matrix RemoveRows(int startRow, int endRow) { if (startRow == 0) { return GetRows(endRow, base.Rows, 1); } if (endRow == base.Rows) { return GetRows(0, startRow, 1); } using Matrix matrix = GetRows(0, startRow, 1); using Matrix otherMatrix = GetRows(endRow, base.Rows, 1); return matrix.ConcateVertical(otherMatrix); } public Matrix RemoveCols(int startCol, int endCol) { if (startCol == 0) { return GetCols(endCol, base.Cols); } if (endCol == base.Cols) { return GetCols(0, startCol); } using Matrix matrix = GetCols(0, startCol); using Matrix otherMatrix = GetCols(endCol, base.Cols); return matrix.ConcateHorizontal(otherMatrix); } public Matrix ConcateVertical(Matrix otherMatrix) { Matrix matrix = new Matrix(base.Rows + otherMatrix.Rows, base.Cols); using (Matrix destination = matrix.GetRows(0, base.Rows, 1)) { CopyTo(destination); } using Matrix destination2 = matrix.GetRows(base.Rows, matrix.Rows, 1); otherMatrix.CopyTo(destination2); return matrix; } public Matrix ConcateHorizontal(Matrix otherMatrix) { Matrix matrix = new Matrix(base.Rows, base.Cols + otherMatrix.Cols); using (Matrix destination = matrix.GetCols(0, base.Cols)) { CopyTo(destination); } using Matrix destination2 = matrix.GetCols(base.Cols, matrix.Cols); otherMatrix.CopyTo(destination2); return matrix; } public void MinMax(out double minValue, out double maxValue, out Point minLocation, out Point maxLocation, IInputArray mask = null) { minLocation = default(Point); maxLocation = default(Point); int[] array = new int[2]; int[] array2 = new int[2]; CvInvoke.MinMaxIdx(this, out minValue, out maxValue, array, array2, mask); minLocation.X = array[1]; minLocation.Y = array[0]; maxLocation.X = array2[1]; maxLocation.Y = array2[0]; } public Matrix Add(Matrix mat2) { Matrix matrix = CopyBlank(); CvInvoke.Add(this, mat2, matrix, null, CvInvoke.GetDepthType(typeof(TDepth))); return matrix; } public Matrix Add(TDepth val) { Matrix matrix = CopyBlank(); using ScalarArray src = new ScalarArray(System.Convert.ToDouble(val)); CvInvoke.Add(this, src, matrix, null, CvInvoke.GetDepthType(typeof(TDepth))); return matrix; } public Matrix Sub(Matrix mat2) { Matrix matrix = CopyBlank(); CvInvoke.Subtract(this, mat2, matrix, null, CvInvoke.GetDepthType(typeof(TDepth))); return matrix; } public Matrix Sub(TDepth val) { Matrix matrix = CopyBlank(); using ScalarArray src = new ScalarArray(System.Convert.ToDouble(val)); CvInvoke.Subtract(this, src, matrix, null, CvInvoke.GetDepthType(typeof(TDepth))); return matrix; } public Matrix SubR(TDepth val) { Matrix matrix = CopyBlank(); using ScalarArray src = new ScalarArray(System.Convert.ToDouble(val)); CvInvoke.Subtract(src, this, matrix, null, CvInvoke.GetDepthType(typeof(TDepth))); return matrix; } public Matrix Mul(double scale) { Matrix matrix = CopyBlank(); CvInvoke.cvConvertScale(base.Ptr, matrix.Ptr, scale, 0.0); return matrix; } public Matrix Mul(Matrix mat2) { Matrix matrix = new Matrix(base.Rows, mat2.Cols); CvInvoke.Gemm(this, mat2, 1.0, null, 0.0, matrix); return matrix; } public static Matrixoperator +(Matrix mat1, Matrix mat2) { return mat1.Add(mat2); } public static Matrixoperator +(Matrix mat1, double val) { return mat1.Add((TDepth)System.Convert.ChangeType(val, typeof(TDepth))); } public static Matrixoperator +(double val, Matrix mat1) { return mat1.Add((TDepth)System.Convert.ChangeType(val, typeof(TDepth))); } public static Matrixoperator -(double val, Matrix mat1) { return mat1.SubR((TDepth)System.Convert.ChangeType(val, typeof(TDepth))); } public static Matrixoperator -(Matrix mat1, Matrix mat2) { return mat1.Sub(mat2); } public static Matrixoperator -(Matrix mat1, double val) { return mat1.Sub((TDepth)System.Convert.ChangeType(val, typeof(TDepth))); } public static Matrixoperator *(Matrix mat1, double val) { return mat1.Mul(val); } public static Matrixoperator *(double val, Matrix mat1) { return mat1.Mul(val); } public static Matrixoperator /(Matrix mat1, double val) { return mat1.Mul(1.0 / val); } public static Matrixoperator *(Matrix mat1, Matrix mat2) { return mat1.Mul(mat2); } public Matrix(SerializationInfo info, StreamingContext context) { DeserializeObjectData(info, context); } protected override void DisposeObject() { base.DisposeObject(); if (_ptr != IntPtr.Zero) { Marshal.FreeHGlobal(_ptr); GC.RemoveMemoryPressure(StructSize.MCvMat); _ptr = IntPtr.Zero; } _array = null; } public Matrix Cmp(Matrix mat2, CmpType type) { Matrix matrix = new Matrix(base.Rows, base.Cols); CvInvoke.Compare(this, mat2, matrix, type); return matrix; } public Matrix[] Split() { int numberOfChannels = NumberOfChannels; Matrix[] array = new Matrix[numberOfChannels]; using VectorOfMat vectorOfMat = new VectorOfMat(); for (int i = 0; i < numberOfChannels; i++) { array[i] = new Matrix(base.Rows, base.Cols); vectorOfMat.Push(array[i].Mat); } CvInvoke.Split(this, vectorOfMat); return array; } public bool Equals(Matrix mat2) { if (!Size.Equals((object?)mat2.Size)) { return false; } int numberOfChannels = NumberOfChannels; if (numberOfChannels != mat2.NumberOfChannels) { return false; } using Matrix matrix = new Matrix(base.Rows, base.Cols, numberOfChannels); CvInvoke.BitwiseXor(this, mat2, matrix); if (numberOfChannels == 1) { return CvInvoke.CountNonZero(matrix) == 0; } Matrix[] array = matrix.Split(); try { for (int i = 0; i < numberOfChannels; i++) { if (CvInvoke.CountNonZero(array[i]) != 0) { return false; } } return true; } finally { Matrix[] array2 = array; for (int j = 0; j < array2.Length; j++) { array2[j].Dispose(); } } } object ICloneable.Clone() { return Clone(); } } public class Moments : UnmanagedObject { public MCvPoint2D64f GravityCenter => new MCvPoint2D64f(M10 / M00, M01 / M00); public double M00 { get { return CvInvoke.cveMomentsGetM00(_ptr); } set { CvInvoke.cveMomentsSetM00(_ptr, value); } } public double M10 { get { return CvInvoke.cveMomentsGetM10(_ptr); } set { CvInvoke.cveMomentsSetM10(_ptr, value); } } public double M01 { get { return CvInvoke.cveMomentsGetM01(_ptr); } set { CvInvoke.cveMomentsSetM01(_ptr, value); } } public double M20 { get { return CvInvoke.cveMomentsGetM20(_ptr); } set { CvInvoke.cveMomentsSetM20(_ptr, value); } } public double M11 { get { return CvInvoke.cveMomentsGetM11(_ptr); } set { CvInvoke.cveMomentsSetM11(_ptr, value); } } public double M02 { get { return CvInvoke.cveMomentsGetM02(_ptr); } set { CvInvoke.cveMomentsSetM02(_ptr, value); } } public double M30 { get { return CvInvoke.cveMomentsGetM30(_ptr); } set { CvInvoke.cveMomentsSetM30(_ptr, value); } } public double M21 { get { return CvInvoke.cveMomentsGetM21(_ptr); } set { CvInvoke.cveMomentsSetM21(_ptr, value); } } public double M12 { get { return CvInvoke.cveMomentsGetM12(_ptr); } set { CvInvoke.cveMomentsSetM12(_ptr, value); } } public double M03 { get { return CvInvoke.cveMomentsGetM03(_ptr); } set { CvInvoke.cveMomentsSetM03(_ptr, value); } } public double Mu20 { get { return CvInvoke.cveMomentsGetMu20(_ptr); } set { CvInvoke.cveMomentsSetMu20(_ptr, value); } } public double Mu11 { get { return CvInvoke.cveMomentsGetMu11(_ptr); } set { CvInvoke.cveMomentsSetMu11(_ptr, value); } } public double Mu02 { get { return CvInvoke.cveMomentsGetMu02(_ptr); } set { CvInvoke.cveMomentsSetMu02(_ptr, value); } } public double Mu30 { get { return CvInvoke.cveMomentsGetMu30(_ptr); } set { CvInvoke.cveMomentsSetMu30(_ptr, value); } } public double Mu21 { get { return CvInvoke.cveMomentsGetMu21(_ptr); } set { CvInvoke.cveMomentsSetMu21(_ptr, value); } } public double Mu12 { get { return CvInvoke.cveMomentsGetMu12(_ptr); } set { CvInvoke.cveMomentsSetMu12(_ptr, value); } } public double Mu03 { get { return CvInvoke.cveMomentsGetMu03(_ptr); } set { CvInvoke.cveMomentsSetMu03(_ptr, value); } } public double Nu20 { get { return CvInvoke.cveMomentsGetNu20(_ptr); } set { CvInvoke.cveMomentsSetNu20(_ptr, value); } } public double Nu11 { get { return CvInvoke.cveMomentsGetNu11(_ptr); } set { CvInvoke.cveMomentsSetNu11(_ptr, value); } } public double Nu02 { get { return CvInvoke.cveMomentsGetNu02(_ptr); } set { CvInvoke.cveMomentsSetNu02(_ptr, value); } } public double Nu30 { get { return CvInvoke.cveMomentsGetNu30(_ptr); } set { CvInvoke.cveMomentsSetNu30(_ptr, value); } } public double Nu21 { get { return CvInvoke.cveMomentsGetNu21(_ptr); } set { CvInvoke.cveMomentsSetNu21(_ptr, value); } } public double Nu12 { get { return CvInvoke.cveMomentsGetNu12(_ptr); } set { CvInvoke.cveMomentsSetNu12(_ptr, value); } } public double Nu03 { get { return CvInvoke.cveMomentsGetNu03(_ptr); } set { CvInvoke.cveMomentsSetNu03(_ptr, value); } } public Moments() { _ptr = CvInvoke.cveMomentsCreate(); } protected override void DisposeObject() { if (_ptr != IntPtr.Zero) { CvInvoke.cveMomentsRelease(ref _ptr); } } } public static class NativeMatFileIO { private static IFileReaderMat[] _fileReaderMatArr; private static IFileWriterMat[] _fileWriterMatArr; public static bool ReadFileToMat(string fileName, Mat mat, ImreadModes loadType) { if (_fileReaderMatArr == null) { Type[] interfaceImplementationFromAssembly = Toolbox.GetInterfaceImplementationFromAssembly(); IFileReaderMat[] array = new IFileReaderMat[interfaceImplementationFromAssembly.Length]; for (int i = 0; i < interfaceImplementationFromAssembly.Length; i++) { array[i] = Activator.CreateInstance(interfaceImplementationFromAssembly[i]) as IFileReaderMat; } _fileReaderMatArr = array; } IFileReaderMat[] fileReaderMatArr = _fileReaderMatArr; for (int j = 0; j < fileReaderMatArr.Length; j++) { if (fileReaderMatArr[j].ReadFile(fileName, mat, loadType)) { return true; } } return false; } public static bool WriteMatToFile(Mat mat, string fileName) { if (_fileWriterMatArr == null) { Type[] interfaceImplementationFromAssembly = Toolbox.GetInterfaceImplementationFromAssembly(); IFileWriterMat[] array = new IFileWriterMat[interfaceImplementationFromAssembly.Length]; for (int i = 0; i < interfaceImplementationFromAssembly.Length; i++) { array[i] = Activator.CreateInstance(interfaceImplementationFromAssembly[i]) as IFileWriterMat; } _fileWriterMatArr = array; } IFileWriterMat[] fileWriterMatArr = _fileWriterMatArr; for (int j = 0; j < fileWriterMatArr.Length; j++) { if (fileWriterMatArr[j].WriteFile(mat, fileName)) { return true; } } return false; } } public class OutputArray : InputArray { private static OutputArray _empty = new OutputArray(); public bool FixedSize => CvInvoke.cveOutputArrayFixedSize(_ptr); public bool FixedType => CvInvoke.cveOutputArrayFixedType(_ptr); public bool Needed => CvInvoke.cveOutputArrayNeeded(_ptr); internal OutputArray() { } public OutputArray(IntPtr outputArrayPtr, object parent) : base(outputArrayPtr, parent) { } public new static OutputArray GetEmpty() { return _empty; } protected override void DisposeObject() { if (_ptr != IntPtr.Zero) { CvInvoke.cveOutputArrayRelease(ref _ptr); } _parent = null; } } public class RNG : UnmanagedObject { public enum DistType { Uniform, Normal } public RNG() { _ptr = CvInvoke.cveRngCreate(); } public RNG(ulong state) { _ptr = CvInvoke.cveRngCreateWithSeed(state); } protected override void DisposeObject() { if (_ptr != IntPtr.Zero) { CvInvoke.cveRngRelease(ref _ptr); } } public void Fill(IInputOutputArray mat, DistType distType, IInputArray a, IInputArray b, bool saturateRange = false) { using InputArray inputArray = a.GetInputArray(); using InputArray inputArray2 = b.GetInputArray(); using InputOutputArray inputOutputArray = mat.GetInputOutputArray(); CvInvoke.cveRngFill(_ptr, inputOutputArray, distType, inputArray, inputArray2, saturateRange); } public void Fill(IInputOutputArray mat, DistType distType, MCvScalar a, MCvScalar b, bool saturateRange = false) { using ScalarArray a2 = new ScalarArray(a); using ScalarArray b2 = new ScalarArray(b); Fill(mat, distType, a2, b2, saturateRange); } public double Gaussian(double sigma) { return CvInvoke.cveRngGaussian(_ptr, sigma); } public uint Next() { return CvInvoke.cveRngNext(_ptr); } public int Uniform(int a, int b) { return CvInvoke.cveRngUniformInt(_ptr, a, b); } public float Uniform(float a, float b) { return CvInvoke.cveRngUniformFloat(_ptr, a, b); } public double Uniform(double a, double b) { return CvInvoke.cveRngUniformDouble(_ptr, a, b); } } public class ScalarArray : UnmanagedObject, IInputArray, IDisposable { private enum DataType { Scalar, Double } private DataType _dataType; static ScalarArray() { CvInvoke.Init(); } public ScalarArray(MCvScalar scalar) { _ptr = cveScalarCreate(ref scalar); _dataType = DataType.Scalar; } public ScalarArray(double scalar) { _ptr = Marshal.AllocHGlobal(8); _dataType = DataType.Double; Marshal.Copy(new double[1] { scalar }, 0, _ptr, 1); } public static explicit operator ScalarArray(double scalar) { return new ScalarArray(scalar); } public static explicit operator ScalarArray(MCvScalar scalar) { return new ScalarArray(scalar); } protected override void DisposeObject() { if (_ptr != IntPtr.Zero) { if (_dataType == DataType.Scalar) { cveScalarRelease(ref _ptr); } else if (_dataType == DataType.Double) { Marshal.FreeHGlobal(_ptr); _ptr = IntPtr.Zero; } } } public InputArray GetInputArray() { if (_dataType == DataType.Scalar) { return new InputArray(cveInputArrayFromScalar(_ptr), this); } if (_dataType == DataType.Double) { return new InputArray(cveInputArrayFromDouble(_ptr), this); } throw new NotImplementedException("Not implemented"); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveScalarCreate(ref MCvScalar scalar); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveScalarRelease(ref IntPtr scalar); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveInputArrayFromScalar(IntPtr scalar); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveInputArrayFromDouble(IntPtr scalar); } public class SparseMatrix : UnmanagedObject where TDepth : new() { private int[] _dimension; public double this[int row, int col] { get { return CvInvoke.cvGetReal2D(base.Ptr, row, col); } set { CvInvoke.cvSet2D(base.Ptr, row, col, new MCvScalar(value)); } } public SparseMatrix(int[] dimension) { _dimension = new int[dimension.Length]; Array.Copy(dimension, _dimension, dimension.Length); GCHandle gCHandle = GCHandle.Alloc(_dimension, GCHandleType.Pinned); _ptr = CvInvoke.cvCreateSparseMat(_dimension.Length, gCHandle.AddrOfPinnedObject(), CvInvoke.GetDepthType(typeof(TDepth))); gCHandle.Free(); } protected override void DisposeObject() { CvInvoke.cvReleaseSparseMat(ref _ptr); } } [Serializable] public class TimedImage : Image where TColor : struct, IColor where TDepth : new() { private DateTime _timestamp; public DateTime Timestamp { get { return _timestamp; } set { _timestamp = value; } } protected TimedImage() { _timestamp = DateTime.Now; } public TimedImage(int width, int height, TColor value) : base(width, height, value) { _timestamp = DateTime.Now; } public TimedImage(int width, int height) : base(width, height) { _timestamp = DateTime.Now; } } [Serializable] [DebuggerTypeProxy(typeof(DebuggerProxy))] public class UMat : UnmanagedObject, IEquatable, IInputOutputArray, IInputArray, IDisposable, IOutputArray, IInputArrayOfArrays, IOutputArrayOfArrays, ISerializable { public enum Usage { Default = 0, AllocateHostMemory = 1, AllocateDeviceMemory = 2, AllocateSharedMemory = 4 } internal class DebuggerProxy { private UMat _v; public Mat Mat { get { Mat mat = new Mat(); _v.CopyTo(mat); return mat; } } public DebuggerProxy(UMat v) { _v = v; } } private bool _needDispose; public byte[] Bytes { get { if (IsEmpty) { return null; } byte[] array = new byte[Total.ToInt32() * ElementSize]; CopyTo(array); return array; } set { SetTo(value); } } public Size Size { get { Size s = default(Size); UMatInvoke.cveUMatGetSize(_ptr, ref s); return s; } } public int Rows => Size.Height; public int Cols => Size.Width; public int ElementSize => UMatInvoke.cveUMatGetElementSize(_ptr); public bool IsContinuous => CvInvoke.cveUMatIsContinuous(_ptr); public bool IsSubmatrix => CvInvoke.cveUMatIsSubmatrix(_ptr); public DepthType Depth => CvInvoke.cveUMatDepth(_ptr); public bool IsEmpty => CvInvoke.cveUMatIsEmpty(_ptr); public int NumberOfChannels => CvInvoke.cveUMatNumberOfChannels(_ptr); public IntPtr Total => CvInvoke.cveUMatTotal(_ptr); public int Dims => CvInvoke.cveUMatGetDims(_ptr); public UMat(SerializationInfo info, StreamingContext context) : this() { DeserializeObjectData(info, context); } protected virtual void DeserializeObjectData(SerializationInfo info, StreamingContext context) { int rows = (int)info.GetValue("Rows", typeof(int)); int cols = (int)info.GetValue("Cols", typeof(int)); int type = (int)info.GetValue("DepthType", typeof(int)); int channels = (int)info.GetValue("NumberOfChannels", typeof(int)); Create(rows, cols, (DepthType)type, channels); Bytes = (byte[])info.GetValue("Bytes", typeof(byte[])); } public void GetObjectData(SerializationInfo info, StreamingContext context) { info.AddValue("Rows", Rows); info.AddValue("Cols", Cols); info.AddValue("DepthType", (int)Depth); info.AddValue("NumberOfChannels", NumberOfChannels); info.AddValue("Bytes", Bytes); } internal UMat(IntPtr ptr, bool needDispose) { _ptr = ptr; _needDispose = needDispose; } public UMat(Usage usage = Usage.Default) : this(UMatInvoke.cveUMatCreate(usage), needDispose: true) { } public UMat(int rows, int cols, DepthType type, int channels, Usage usage = Usage.Default) : this() { Create(rows, cols, type, channels, usage); } public UMat(Size size, DepthType type, int channels, Usage usage = Usage.Default) : this(size.Height, size.Width, type, channels, usage) { } public UMat(UMat parent, Rectangle roi) : this(UMatInvoke.cveUMatCreateFromRect(parent.Ptr, ref roi), needDispose: true) { } public UMat(UMat umat, Emgu.CV.Structure.Range rowRange, Emgu.CV.Structure.Range colRange) : this(UMatInvoke.cveUMatCreateFromRange(umat.Ptr, ref rowRange, ref colRange), needDispose: true) { } public void Create(int rows, int cols, DepthType type, int channels, Usage usage = Usage.Default) { UMatInvoke.cveUMatCreateData(_ptr, rows, cols, CvInvoke.MakeType(type, channels), usage); } public UMat(string fileName, ImreadModes loadType) : this() { using Mat mat = new Mat(fileName, loadType); mat.CopyTo(this); } public void CopyTo(IOutputArray m, IInputArray mask = null) { using OutputArray outputArray = m.GetOutputArray(); using InputArray inputArray = ((mask == null) ? InputArray.GetEmpty() : mask.GetInputArray()); UMatInvoke.cveUMatCopyTo(this, outputArray, inputArray); } public void SetTo(IInputArray value, IInputArray mask = null) { using InputArray inputArray = value.GetInputArray(); using InputArray inputArray2 = ((mask == null) ? InputArray.GetEmpty() : mask.GetInputArray()); UMatInvoke.cveUMatSetTo(base.Ptr, inputArray, inputArray2); } public void SetTo(MCvScalar value, IInputArray mask = null) { using ScalarArray value2 = new ScalarArray(value); SetTo(value2, mask); } public Mat GetMat(AccessType access) { return new Mat(UMatInvoke.cveUMatGetMat(_ptr, access), needDispose: true); } protected override void DisposeObject() { if (_needDispose && _ptr != IntPtr.Zero) { UMatInvoke.cveUMatRelease(ref _ptr); } } public InputArray GetInputArray() { return new InputArray(UMatInvoke.cveInputArrayFromUMat(_ptr), this); } public OutputArray GetOutputArray() { return new OutputArray(UMatInvoke.cveOutputArrayFromUMat(_ptr), this); } public InputOutputArray GetInputOutputArray() { return new InputOutputArray(UMatInvoke.cveInputOutputArrayFromUMat(_ptr), this); } public UMat Reshape(int cn, int rows = 0) { return new UMat(UMatInvoke.cveUMatReshape(base.Ptr, cn, rows), needDispose: true); } public Image ToImage() where TColor : struct, IColor where TDepth : new() { TColor val = new TColor(); int numberOfChannels = NumberOfChannels; if (typeof(TDepth) == CvInvoke.GetDepthType(Depth) && val.Dimension == numberOfChannels) { Image image = new Image(Size); CopyTo(image); return image; } if (typeof(TDepth) != CvInvoke.GetDepthType(Depth) && val.Dimension == numberOfChannels) { Image image2 = new Image(Size); _ = Depth; Mat mat = image2.Mat; ConvertTo(mat, mat.Depth); return image2; } if (typeof(TDepth) == CvInvoke.GetDepthType(Depth) && val.Dimension != numberOfChannels) { Image image3 = new Image(Size); Type type = numberOfChannels switch { 4 => typeof(Bgra), 3 => typeof(Bgr), 1 => typeof(Gray), _ => null, }; if (type == null) { throw new Exception("Unsupported conversion"); } CvInvoke.CvtColor(this, image3, type, typeof(TColor)); return image3; } using UMat uMat = new UMat(); ConvertTo(uMat, CvInvoke.GetDepthType(typeof(TDepth))); return uMat.ToImage(); } public void MinMax(out double[] minValues, out double[] maxValues, out Point[] minLocations, out Point[] maxLocations) { CvInvoke.MinMax(this, out minValues, out maxValues, out minLocations, out maxLocations); } public void ConvertTo(IOutputArray m, DepthType rtype, double alpha = 1.0, double beta = 0.0) { using OutputArray outputArray = m.GetOutputArray(); UMatInvoke.cveUMatConvertTo(base.Ptr, outputArray, rtype, alpha, beta); } public UMat[] Split() { UMat[] array = new UMat[NumberOfChannels]; Size size = Size; DepthType depth = Depth; for (int i = 0; i < array.Length; i++) { array[i] = new UMat(size, depth, 1); } using VectorOfUMat mv = new VectorOfUMat(array); CvInvoke.Split(this, mv); return array; } public void Save(string fileName) { using Mat mat = GetMat(AccessType.Read); mat.Save(fileName); } public UMat Clone() { UMat uMat = new UMat(); CopyTo(uMat); return uMat; } public bool Equals(UMat other) { if (!Size.Equals((object?)other.Size) || NumberOfChannels != other.NumberOfChannels || Depth != other.Depth) { return false; } using UMat uMat = new UMat(); CvInvoke.Compare(this, other, uMat, CmpType.NotEqual); using UMat arr = uMat.Reshape(1); return CvInvoke.CountNonZero(arr) == 0; } public void CopyTo(T[] data) { GCHandle gCHandle = GCHandle.Alloc(data, GCHandleType.Pinned); UMatInvoke.cveUMatCopyDataTo(this, gCHandle.AddrOfPinnedObject()); gCHandle.Free(); } public void SetTo(T[] data) { GCHandle gCHandle = GCHandle.Alloc(data, GCHandleType.Pinned); UMatInvoke.cveUMatCopyDataFrom(this, gCHandle.AddrOfPinnedObject()); gCHandle.Free(); } public double Dot(IInputArray mat) { using InputArray inputArray = mat.GetInputArray(); return UMatInvoke.cveUMatDot(base.Ptr, inputArray); } public UMat Row(int y) { return new UMat(this, new Emgu.CV.Structure.Range(y, y + 1), Emgu.CV.Structure.Range.All); } public UMat Col(int x) { return new UMat(this, Emgu.CV.Structure.Range.All, new Emgu.CV.Structure.Range(x, x + 1)); } public Array GetData(bool jagged = true) { if (IsEmpty) { return null; } using InputArray inputArray = GetInputArray(); using Mat mat = inputArray.GetMat(); return mat.GetData(jagged); } public static UMat operator &(UMat mat1, UMat mat2) { UMat uMat = new UMat(); CvInvoke.BitwiseAnd(mat1, mat2, uMat); return uMat; } public static UMat operator &(UMat mat1, double val) { using ScalarArray src = new ScalarArray(val); UMat uMat = new UMat(); CvInvoke.BitwiseAnd(mat1, src, uMat); return uMat; } public static UMat operator &(double val, UMat mat1) { return mat1 & val; } public static UMat operator &(UMat mat1, MCvScalar val) { using ScalarArray src = new ScalarArray(val); UMat uMat = new UMat(); CvInvoke.BitwiseAnd(mat1, src, uMat); return uMat; } public static UMat operator &(MCvScalar val, UMat mat1) { return mat1 & val; } public static UMat operator |(UMat mat1, UMat mat2) { UMat uMat = new UMat(); CvInvoke.BitwiseOr(mat1, mat2, uMat); return uMat; } public static UMat operator |(UMat mat1, double val) { using ScalarArray src = new ScalarArray(val); UMat uMat = new UMat(); CvInvoke.BitwiseOr(mat1, src, uMat); return uMat; } public static UMat operator |(double val, UMat mat1) { return mat1 | val; } public static UMat operator |(UMat mat1, MCvScalar val) { using ScalarArray src = new ScalarArray(val); UMat uMat = new UMat(); CvInvoke.BitwiseOr(mat1, src, uMat); return uMat; } public static UMat operator |(MCvScalar val, UMat mat1) { return mat1 | val; } public static UMat operator ~(UMat mat) { UMat uMat = new UMat(); CvInvoke.BitwiseNot(mat, uMat); return uMat; } public static UMat operator +(UMat mat1, UMat mat2) { UMat uMat = new UMat(); CvInvoke.Add(mat1, mat2, uMat); return uMat; } public static UMat operator +(double value, UMat mat1) { return mat1 + value; } public static UMat operator +(UMat mat, double value) { using ScalarArray src = new ScalarArray(value); UMat uMat = new UMat(); CvInvoke.Add(mat, src, uMat); return uMat; } public static UMat operator +(UMat mat, MCvScalar value) { using ScalarArray src = new ScalarArray(value); UMat uMat = new UMat(); CvInvoke.Add(mat, src, uMat); return uMat; } public static UMat operator +(MCvScalar value, UMat mat) { return mat + value; } public static UMat operator -(UMat mat1, UMat mat2) { UMat uMat = new UMat(); CvInvoke.Subtract(mat1, mat2, uMat); return uMat; } public static UMat operator -(UMat mat, MCvScalar value) { using ScalarArray src = new ScalarArray(value); UMat uMat = new UMat(); CvInvoke.Subtract(mat, src, uMat); return uMat; } public static UMat operator -(MCvScalar value, UMat mat) { using ScalarArray src = new ScalarArray(value); UMat uMat = new UMat(); CvInvoke.Subtract(src, mat, uMat); return uMat; } public static UMat operator -(double value, UMat mat) { using ScalarArray src = new ScalarArray(value); UMat uMat = new UMat(); CvInvoke.Subtract(src, mat, uMat); return uMat; } public static UMat operator -(UMat mat, double value) { using ScalarArray src = new ScalarArray(value); UMat uMat = new UMat(); CvInvoke.Subtract(mat, src, uMat); return uMat; } public static UMat operator *(UMat mat, double scale) { using ScalarArray src = new ScalarArray(scale); UMat uMat = new UMat(); CvInvoke.Multiply(mat, src, uMat); return uMat; } public static UMat operator *(double scale, UMat mat) { return mat * scale; } public static UMat operator /(UMat mat, double scale) { return mat * (1.0 / scale); } public static UMat operator /(double scale, UMat mat) { using ScalarArray src = new ScalarArray(scale); UMat uMat = new UMat(); CvInvoke.Divide(src, mat, uMat); return uMat; } } internal static class UMatInvoke { static UMatInvoke() { CvInvoke.Init(); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveInputArrayFromUMat(IntPtr mat); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveOutputArrayFromUMat(IntPtr mat); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveInputOutputArrayFromUMat(IntPtr mat); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveUMatCreate(UMat.Usage usageFlag); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveUMatRelease(ref IntPtr mat); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveUMatGetSize(IntPtr mat, ref Size s); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveUMatCopyTo(IntPtr mat, IntPtr m, IntPtr mask); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int cveUMatGetElementSize(IntPtr mat); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveUMatCreateData(IntPtr mat, int row, int cols, int type, UMat.Usage flags); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveUMatCreateFromRect(IntPtr mat, ref Rectangle roi); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveUMatCreateFromRange(IntPtr mat, ref Emgu.CV.Structure.Range rowRange, ref Emgu.CV.Structure.Range colRange); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveUMatSetTo(IntPtr mat, IntPtr value, IntPtr mask); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveUMatGetMat(IntPtr umat, AccessType access); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveUMatConvertTo(IntPtr umat, IntPtr outArray, DepthType rtype, double alpha, double beta); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveUMatReshape(IntPtr mat, int cn, int rows); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveUMatCopyDataTo(IntPtr mat, IntPtr dest); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveUMatCopyDataFrom(IntPtr mat, IntPtr source); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern double cveUMatDot(IntPtr mat, IntPtr m); } public class VideoCapture : UnmanagedObject { public enum API { Any = 0, Vfw = 200, V4L = 200, V4L2 = 200, Firewire = 300, IEEE1394 = 300, DC1394 = 300, CMU1394 = 300, QT = 500, Unicap = 600, DShow = 700, Pvapi = 800, OpenNI = 900, OpenNIAsus = 910, Android = 1000, XiApi = 1100, AVFoundation = 1200, Giganetix = 1300, Msmf = 1400, Winrt = 1410, IntelPerc = 1500, Openni2 = 1600, Openni2Asus = 1610, Gphoto2 = 1700, Gstreamer = 1800, Ffmpeg = 1900, Images = 2000, Aravis = 2100, OpencvMjpeg = 2200, IntelMfx = 2300, Xine = 2400 } public enum CaptureModuleType { Camera, Highgui } private enum GrabState { Stopped, Running, Pause, Stopping } private AutoResetEvent _pauseEvent = new AutoResetEvent(initialState: false); private FlipType? _flipType; private CaptureModuleType _captureModuleType; private readonly bool _needDispose; private volatile GrabState _grabState; private Task _captureTask; public CaptureModuleType CaptureSource => _captureModuleType; public FlipType? FlipType { get { return _flipType; } set { _flipType = value; } } public bool FlipHorizontal { get { if (!_flipType.HasValue) { return false; } if (_flipType.Value != Emgu.CV.CvEnum.FlipType.Horizontal) { return _flipType.Value == Emgu.CV.CvEnum.FlipType.Both; } return true; } set { if (!_flipType.HasValue) { if (value) { _flipType = Emgu.CV.CvEnum.FlipType.Horizontal; } return; } switch (_flipType.Value) { case Emgu.CV.CvEnum.FlipType.Both: if (!value) { _flipType = Emgu.CV.CvEnum.FlipType.Vertical; } break; case Emgu.CV.CvEnum.FlipType.Horizontal: if (!value) { _flipType = null; } break; case Emgu.CV.CvEnum.FlipType.Vertical: if (value) { _flipType = Emgu.CV.CvEnum.FlipType.Both; } break; } } } public bool FlipVertical { get { if (!_flipType.HasValue) { return false; } if (_flipType.Value != 0) { return _flipType.Value == Emgu.CV.CvEnum.FlipType.Both; } return true; } set { if (!_flipType.HasValue) { if (value) { _flipType = Emgu.CV.CvEnum.FlipType.Vertical; } return; } switch (FlipType.Value) { case Emgu.CV.CvEnum.FlipType.Vertical: if (!value) { _flipType = null; } break; case Emgu.CV.CvEnum.FlipType.Horizontal: if (value) { _flipType = Emgu.CV.CvEnum.FlipType.Both; } break; case Emgu.CV.CvEnum.FlipType.Both: if (!value) { _flipType = Emgu.CV.CvEnum.FlipType.Horizontal; } break; } } } public int Width { get { if (_ptr == IntPtr.Zero) { return 0; } return Convert.ToInt32(Get(CapProp.FrameWidth)); } } public int Height { get { if (_ptr == IntPtr.Zero) { return 0; } return Convert.ToInt32(Get(CapProp.FrameHeight)); } } public string BackendName { get { if (_ptr == IntPtr.Zero) { return string.Empty; } using CvString cvString = new CvString(); CvInvoke.cveVideoCaptureGetBackendName(base.Ptr, cvString); return cvString.ToString(); } } public bool IsOpened => CvInvoke.cveVideoCaptureIsOpened(_ptr); public bool ExceptionMode { get { return CvInvoke.cveVideoCaptureGetExceptionMode(_ptr); } set { CvInvoke.cveVideoCaptureSetExceptionMode(_ptr, value); } } public event EventHandler ImageGrabbed; internal VideoCapture(IntPtr ptr, bool needDispose) { _ptr = ptr; _needDispose = needDispose; } private static VectorOfInt ConvertCaptureProperties(Tuple[] captureProperties) { VectorOfInt vectorOfInt = new VectorOfInt(); if (captureProperties != null) { foreach (Tuple tuple in captureProperties) { vectorOfInt.Push(new int[2] { (int)tuple.Item1, tuple.Item2 }); } } return vectorOfInt; } public VideoCapture(int camIndex = 0, API captureApi = API.Any, params Tuple[] captureProperties) { _captureModuleType = CaptureModuleType.Camera; using (VectorOfInt vectorOfInt = ConvertCaptureProperties(captureProperties)) { _ptr = CvInvoke.cveVideoCaptureCreateFromDevice(camIndex, captureApi, vectorOfInt); } if (_ptr == IntPtr.Zero) { throw new NullReferenceException($"Error: Unable to create capture from camera {camIndex}"); } _needDispose = true; } public VideoCapture(string fileName, API captureApi = API.Any, params Tuple[] captureProperties) { using (CvString cvString = new CvString(fileName)) { using VectorOfInt vectorOfInt = ConvertCaptureProperties(captureProperties); _captureModuleType = CaptureModuleType.Highgui; _ptr = CvInvoke.cveVideoCaptureCreateFromFile(cvString, captureApi, vectorOfInt); if (_ptr == IntPtr.Zero) { throw new NullReferenceException($"Unable to create capture from {fileName}"); } } _needDispose = true; } protected override void DisposeObject() { if (_needDispose && _ptr != IntPtr.Zero) { Stop(); CvInvoke.cveVideoCaptureRelease(ref _ptr); } } public double Get(CapProp index) { return CvInvoke.cveVideoCaptureGet(_ptr, index); } public bool Set(CapProp property, double value) { return CvInvoke.cveVideoCaptureSet(base.Ptr, property, value); } public virtual bool Grab() { if (_ptr == IntPtr.Zero) { return false; } bool num = CvInvoke.cveVideoCaptureGrab(base.Ptr); if (num && this.ImageGrabbed != null) { this.ImageGrabbed(this, new EventArgs()); } return num; } private void Run(ExceptionHandler eh = null) { try { while (_grabState == GrabState.Running || _grabState == GrabState.Pause) { if (_grabState == GrabState.Pause) { _pauseEvent.WaitOne(); continue; } IntPtr zero = IntPtr.Zero; if (zero.Equals((object?)(nint)_ptr) || !Grab()) { _grabState = GrabState.Stopping; } } } catch (Exception ex) { if (eh != null && eh.HandleException(ex)) { return; } Trace.WriteLine(ex.StackTrace); throw new Exception("Capture error", ex); } finally { _grabState = GrabState.Stopped; } } public void Start(ExceptionHandler eh = null) { if (_grabState == GrabState.Pause) { _grabState = GrabState.Running; _pauseEvent.Set(); } else if (_grabState == GrabState.Stopped || _grabState == GrabState.Stopping) { _grabState = GrabState.Running; _captureTask = new Task(delegate { Run(eh); }); _captureTask.Start(); } } public void Pause() { if (_grabState == GrabState.Running) { _grabState = GrabState.Pause; } } public void Stop() { if (_grabState == GrabState.Pause) { _grabState = GrabState.Stopping; _pauseEvent.Set(); } else if (_grabState == GrabState.Running) { _grabState = GrabState.Stopping; } if (_captureTask != null) { _captureTask.Wait(100); _captureTask = null; } } public virtual bool Retrieve(IOutputArray image, int flag = 0) { bool flag2; using (OutputArray outputArray = image.GetOutputArray()) { flag2 = CvInvoke.cveVideoCaptureRetrieve(base.Ptr, outputArray, flag); } if (flag2 && FlipType.HasValue) { CvInvoke.Flip(image, image, FlipType.Value); } return flag2; } public bool Read(IOutputArray m) { using OutputArray outputArray = m.GetOutputArray(); return CvInvoke.cveVideoCaptureRead(base.Ptr, outputArray); } public bool Read(Mat mat) { CvInvoke.cveVideoCaptureReadToMat(_ptr, mat); return !mat.IsEmpty; } public bool Read(UMat umat) { CvInvoke.cveVideoCaptureReadToUMat(_ptr, umat); return !umat.IsEmpty; } public static bool WaitAny(VectorOfVideoCapture streams, VectorOfInt readyIndex, int timeoutNs = 0) { return CvInvoke.cveVideoCaptureWaitAny(streams, readyIndex, timeoutNs); } public virtual Mat QueryFrame() { Mat mat = new Mat(); if (!Read(mat)) { mat.Dispose(); return null; } return mat; } public virtual Mat QuerySmallFrame() { Mat mat = QueryFrame(); if (mat != null) { if (!mat.IsEmpty) { CvInvoke.PyrDown(mat, mat); return mat; } mat.Dispose(); } return null; } } public class Backend { private int _id; public int ID => _id; public string Name { get { using CvString cvString = new CvString(); CvInvoke.cveGetBackendName(_id, cvString); return cvString.ToString(); } } public Backend(int id) { _id = id; } } public class VideoWriter : UnmanagedObject { public enum WriterProperty { Quality = 1, Framebytes, NStripes, IsColor, Depth, HwAcceleration, HwDevice, HwAccelerationUseOpencl } public bool IsOpened { get { if (_ptr != IntPtr.Zero) { return CvInvoke.cveVideoWriterIsOpened(_ptr); } return false; } } public string BackendName { get { if (_ptr == IntPtr.Zero) { return string.Empty; } using CvString cvString = new CvString(); CvInvoke.cveVideoWriterGetBackendName(base.Ptr, cvString); return cvString.ToString(); } } public VideoWriter(string fileName, int fps, Size size, bool isColor) : this(fileName, Fourcc('I', 'Y', 'U', 'V'), fps, size, isColor) { } public VideoWriter(string fileName, int compressionCode, double fps, Size size, bool isColor) { using (CvString cvString = new CvString(fileName)) { _ptr = CvInvoke.cveVideoWriterCreate(cvString, compressionCode, fps, ref size, isColor); } if (_ptr == IntPtr.Zero || !IsOpened) { throw new NullReferenceException("Unable to create VideoWriter. Make sure you have the specific codec installed"); } } public VideoWriter(string fileName, int apiPreference, int compressionCode, double fps, Size size, bool isColor) { using (CvString cvString = new CvString(fileName)) { _ptr = CvInvoke.cveVideoWriterCreate2(cvString, apiPreference, compressionCode, fps, ref size, isColor); } if (_ptr == IntPtr.Zero || !IsOpened) { throw new NullReferenceException("Unable to create VideoWriter. Make sure you have the specific codec installed"); } } private static VectorOfInt ConvertWriterProperties(Tuple[] captureProperties) { VectorOfInt vectorOfInt = new VectorOfInt(); if (captureProperties != null) { foreach (Tuple tuple in captureProperties) { vectorOfInt.Push(new int[2] { (int)tuple.Item1, tuple.Item2 }); } } return vectorOfInt; } public VideoWriter(string fileName, int apiPreference, int compressionCode, double fps, Size size, params Tuple[] writerProperties) { using (CvString cvString = new CvString(fileName)) { using VectorOfInt vectorOfInt = ConvertWriterProperties(writerProperties); _ptr = CvInvoke.cveVideoWriterCreate3(cvString, apiPreference, compressionCode, fps, ref size, vectorOfInt); } if (_ptr == IntPtr.Zero || !IsOpened) { throw new NullReferenceException("Unable to create VideoWriter. Make sure you have the specific codec installed"); } } public void Write(IInputArray frame) { using InputArray inputArray = frame.GetInputArray(); CvInvoke.cveVideoWriterWrite(_ptr, inputArray); } public static int Fourcc(char c1, char c2, char c3, char c4) { return CvInvoke.cveVideoWriterFourcc(c1, c2, c3, c4); } protected override void DisposeObject() { CvInvoke.cveVideoWriterRelease(ref _ptr); } public bool Set(WriterProperty prop, double value) { return CvInvoke.cveVideoWriterSet(_ptr, prop, value); } public double Get(WriterProperty prop) { return CvInvoke.cveVideoWriterGet(_ptr, prop); } } [AttributeUsage(AttributeTargets.Struct)] public sealed class ColorInfoAttribute : Attribute { private string _conversionCodename; public string ConversionCodename { get { return _conversionCodename; } set { _conversionCodename = value; } } public ColorInfoAttribute() { _conversionCodename = string.Empty; } } [AttributeUsage(AttributeTargets.Property)] internal sealed class DisplayColorAttribute : Attribute { private Color _displayColor; public Color DisplayColor { get { return _displayColor; } set { _displayColor = value; } } public DisplayColorAttribute(int blue, int green, int red) { _displayColor = Color.FromArgb(red, green, blue); } } public interface IColor { MCvScalar MCvScalar { get; set; } int Dimension { get; } } public abstract class AlignExposures : UnmanagedObject { protected IntPtr _alignExposuresPtr; public void Process(IInputArrayOfArrays src, VectorOfMat dst, IInputArray times, IInputArray response) { using InputArray inputArray = src.GetInputArray(); using InputArray inputArray2 = times.GetInputArray(); using InputArray inputArray3 = times.GetInputArray(); CvInvoke.cveAlignExposuresProcess(_alignExposuresPtr, inputArray, dst, inputArray2, inputArray3); } protected override void DisposeObject() { _alignExposuresPtr = IntPtr.Zero; } } public class AlignMTB : AlignExposures { private IntPtr _sharedPtr; public AlignMTB(int maxBits = 6, int excludeRange = 4, bool cut = true) { _ptr = CvInvoke.cveAlignMTBCreate(maxBits, excludeRange, cut, ref _alignExposuresPtr, ref _sharedPtr); } protected override void DisposeObject() { if (IntPtr.Zero != _ptr) { CvInvoke.cveAlignMTBRelease(ref _ptr, ref _sharedPtr); } base.DisposeObject(); } } public abstract class CalibrateCRF : UnmanagedObject { protected IntPtr _calibrateCRFPtr; public void Process(IInputArray src, IOutputArray dst, IInputArray times) { using InputArray inputArray = src.GetInputArray(); using OutputArray outputArray = dst.GetOutputArray(); using InputArray inputArray2 = times.GetInputArray(); CvInvoke.cveCalibrateCRFProcess(_calibrateCRFPtr, inputArray, outputArray, inputArray2); } protected override void DisposeObject() { _calibrateCRFPtr = IntPtr.Zero; } } public class CalibrateDebevec : CalibrateCRF { private IntPtr _sharedPtr; public CalibrateDebevec(int samples = 70, float lambda = 10f, bool random = false) { _ptr = CvInvoke.cveCalibrateDebevecCreate(samples, lambda, random, ref _calibrateCRFPtr, ref _sharedPtr); } protected override void DisposeObject() { if (IntPtr.Zero != _ptr) { CvInvoke.cveCalibrateDebevecRelease(ref _ptr, ref _sharedPtr); } base.DisposeObject(); } } public class CalibrateRobertson : CalibrateCRF { private IntPtr _sharedPtr; public CalibrateRobertson(int maxIter = 30, float threshold = 0.01f) { _ptr = CvInvoke.cveCalibrateRobertsonCreate(maxIter, threshold, ref _calibrateCRFPtr, ref _sharedPtr); } protected override void DisposeObject() { if (IntPtr.Zero != _ptr) { CvInvoke.cveCalibrateRobertsonRelease(ref _ptr, ref _sharedPtr); } base.DisposeObject(); } } public abstract class MergeExposures : UnmanagedObject { protected IntPtr _mergeExposuresPtr; public void Process(IInputArray src, IOutputArray dst, IInputArray times, IInputArray response) { using InputArray inputArray = src.GetInputArray(); using OutputArray outputArray = dst.GetOutputArray(); using InputArray inputArray2 = times.GetInputArray(); using InputArray inputArray3 = response.GetInputArray(); CvInvoke.cveMergeExposuresProcess(_mergeExposuresPtr, inputArray, outputArray, inputArray2, inputArray3); } protected override void DisposeObject() { _mergeExposuresPtr = IntPtr.Zero; } } public class MergeDebevec : MergeExposures { private IntPtr _sharedPtr; public MergeDebevec() { _ptr = CvInvoke.cveMergeDebevecCreate(ref _mergeExposuresPtr, ref _sharedPtr); } protected override void DisposeObject() { if (IntPtr.Zero != _ptr) { CvInvoke.cveMergeDebevecRelease(ref _ptr, ref _sharedPtr); } base.DisposeObject(); } } public class MergeMertens : MergeExposures { private IntPtr _sharedPtr; public MergeMertens(float contrastWeight = 1f, float saturationWeight = 1f, float exposureWeight = 0f) { _ptr = CvInvoke.cveMergeMertensCreate(contrastWeight, saturationWeight, exposureWeight, ref _mergeExposuresPtr, ref _sharedPtr); } public void Process(IInputArray src, IOutputArray dst) { using InputArray inputArray = src.GetInputArray(); using OutputArray outputArray = dst.GetOutputArray(); using InputArray inputArray2 = InputArray.GetEmpty(); using InputArray inputArray3 = InputArray.GetEmpty(); CvInvoke.cveMergeExposuresProcess(_mergeExposuresPtr, inputArray, outputArray, inputArray2, inputArray3); } protected override void DisposeObject() { if (IntPtr.Zero != _ptr) { CvInvoke.cveMergeMertensRelease(ref _ptr, ref _sharedPtr); } base.DisposeObject(); } } public class MergeRobertson : MergeExposures { private IntPtr _sharedPtr; public MergeRobertson() { _ptr = CvInvoke.cveMergeRobertsonCreate(ref _mergeExposuresPtr, ref _sharedPtr); } protected override void DisposeObject() { if (IntPtr.Zero != _ptr) { CvInvoke.cveMergeRobertsonRelease(ref _ptr, ref _sharedPtr); } base.DisposeObject(); } } public class Tonemap : UnmanagedObject, IAlgorithm { private IntPtr _sharedPtr; protected IntPtr _tonemapPtr; protected IntPtr _algorithmPtr; public IntPtr AlgorithmPtr => _algorithmPtr; public float Gamma { get { return CvInvoke.cveTonemapGetGamma(_ptr); } set { CvInvoke.cveTonemapSetGamma(_ptr, value); } } protected Tonemap(IntPtr ptr, IntPtr tonemapPtr) { _ptr = ptr; _tonemapPtr = tonemapPtr; } public Tonemap(float gamma = 1f) { _ptr = CvInvoke.cveTonemapCreate(gamma, ref _algorithmPtr, ref _sharedPtr); _tonemapPtr = _ptr; } public void Process(IInputArray src, IOutputArray dst) { using InputArray inputArray = src.GetInputArray(); using OutputArray outputArray = dst.GetOutputArray(); CvInvoke.cveTonemapProcess(_tonemapPtr, inputArray, outputArray); } protected override void DisposeObject() { if (IntPtr.Zero != _ptr) { CvInvoke.cveTonemapRelease(ref _ptr, ref _sharedPtr); } _tonemapPtr = IntPtr.Zero; _algorithmPtr = IntPtr.Zero; } } public class TonemapDrago : Tonemap { private IntPtr _sharedPtr; public float Saturation { get { return CvInvoke.cveTonemapDragoGetSaturation(_ptr); } set { CvInvoke.cveTonemapDragoSetSaturation(_ptr, value); } } public float Bias { get { return CvInvoke.cveTonemapDragoGetBias(_ptr); } set { CvInvoke.cveTonemapDragoSetBias(_ptr, value); } } public TonemapDrago(float gamma = 1f, float saturation = 1f, float bias = 0.85f) : base(IntPtr.Zero, IntPtr.Zero) { _ptr = CvInvoke.cveTonemapDragoCreate(gamma, saturation, bias, ref _tonemapPtr, ref _algorithmPtr, ref _sharedPtr); } protected override void DisposeObject() { if (IntPtr.Zero != _ptr) { CvInvoke.cveTonemapDragoRelease(ref _ptr, ref _sharedPtr); } _tonemapPtr = IntPtr.Zero; _algorithmPtr = IntPtr.Zero; } } public class TonemapMantiuk : Tonemap { private IntPtr _sharedPtr; public float Saturation { get { return CvInvoke.cveTonemapMantiukGetSaturation(_ptr); } set { CvInvoke.cveTonemapMantiukSetSaturation(_ptr, value); } } public float Scale { get { return CvInvoke.cveTonemapMantiukGetScale(_ptr); } set { CvInvoke.cveTonemapMantiukSetScale(_ptr, value); } } public TonemapMantiuk(float gamma = 1f, float scale = 0.7f, float saturation = 1f) : base(IntPtr.Zero, IntPtr.Zero) { _ptr = CvInvoke.cveTonemapMantiukCreate(gamma, scale, saturation, ref _tonemapPtr, ref _algorithmPtr, ref _sharedPtr); } protected override void DisposeObject() { if (IntPtr.Zero != _ptr) { CvInvoke.cveTonemapMantiukRelease(ref _ptr, ref _sharedPtr); _tonemapPtr = IntPtr.Zero; _algorithmPtr = IntPtr.Zero; } } } public class TonemapReinhard : Tonemap { private IntPtr _sharedPtr; public float Intensity { get { return CvInvoke.cveTonemapReinhardGetIntensity(_ptr); } set { CvInvoke.cveTonemapReinhardSetIntensity(_ptr, value); } } public float LightAdaptation { get { return CvInvoke.cveTonemapReinhardGetLightAdaptation(_ptr); } set { CvInvoke.cveTonemapReinhardSetLightAdaptation(_ptr, value); } } public float ColorAdaptation { get { return CvInvoke.cveTonemapReinhardGetColorAdaptation(_ptr); } set { CvInvoke.cveTonemapReinhardSetColorAdaptation(_ptr, value); } } public TonemapReinhard(float gamma = 1f, float intensity = 0f, float lightAdapt = 1f, float colorAdapt = 0f) : base(IntPtr.Zero, IntPtr.Zero) { _ptr = CvInvoke.cveTonemapReinhardCreate(gamma, intensity, lightAdapt, colorAdapt, ref _tonemapPtr, ref _algorithmPtr, ref _sharedPtr); } protected override void DisposeObject() { if (IntPtr.Zero != _ptr) { CvInvoke.cveTonemapReinhardRelease(ref _ptr, ref _sharedPtr); _tonemapPtr = IntPtr.Zero; _algorithmPtr = IntPtr.Zero; } } } public interface IWidget { IntPtr GetWidget { get; } } public interface IWidget3D : IWidget { IntPtr GetWidget3D { get; } } public interface IWidget2D : IWidget { IntPtr GetWidget2D { get; } } public class Viz3d : UnmanagedObject { public bool WasStopped => CvInvoke.cveViz3dWasStopped(_ptr); public Viz3d(string windowName) { using CvString cvString = new CvString(windowName); _ptr = CvInvoke.cveViz3dCreate(cvString); } public void ShowWidget(string id, IWidget widget, Affine3d pose = null) { using CvString cvString = new CvString(id); CvInvoke.cveViz3dShowWidget(_ptr, cvString, widget.GetWidget, pose); } public void RemoveWidget(string id) { using CvString cvString = new CvString(id); CvInvoke.cveViz3dRemoveWidget(_ptr, cvString); } public void SetWidgetPose(string id, Affine3d pose) { using CvString cvString = new CvString(id); CvInvoke.cveViz3dSetWidgetPose(_ptr, cvString, pose); } public void Spin() { CvInvoke.cveViz3dSpin(_ptr); } public void SpinOnce(int time = 1, bool forceRedraw = false) { CvInvoke.cveViz3dSpinOnce(_ptr, time, forceRedraw); } public void SetBackgroundMeshLab() { CvInvoke.cveViz3dSetBackgroundMeshLab(_ptr); } protected override void DisposeObject() { IntPtr zero = IntPtr.Zero; if (!zero.Equals((object?)(nint)_ptr)) { CvInvoke.cveViz3dRelease(ref _ptr); } } } public class WArrow : UnmanagedObject, IWidget3D, IWidget { private IntPtr _widgetPtr; private IntPtr _widget3dPtr; public IntPtr GetWidget3D => _widget3dPtr; public IntPtr GetWidget => _widgetPtr; public WArrow(MCvPoint3D64f pt1, MCvPoint3D64f pt2, double thickness, MCvScalar color) { _ptr = CvInvoke.cveWArrowCreate(ref pt1, ref pt2, thickness, ref color, ref _widget3dPtr, ref _widgetPtr); } protected override void DisposeObject() { IntPtr zero = IntPtr.Zero; if (!zero.Equals((object?)(nint)_ptr)) { CvInvoke.cveWArrowRelease(ref _ptr); } _widgetPtr = IntPtr.Zero; _widget3dPtr = IntPtr.Zero; } } public class WCircle : UnmanagedObject, IWidget3D, IWidget { private IntPtr _widgetPtr; private IntPtr _widget3dPtr; public IntPtr GetWidget3D => _widget3dPtr; public IntPtr GetWidget => _widgetPtr; public WCircle(double radius, double thickness, MCvScalar color) { _ptr = CvInvoke.cveWCircleCreateAtOrigin(radius, thickness, ref color, ref _widget3dPtr, ref _widgetPtr); } public WCircle(double radius, MCvPoint3D64f center, MCvPoint3D64f normal, double thickness, MCvScalar color) { _ptr = CvInvoke.cveWCircleCreate(radius, ref center, ref normal, thickness, ref color, ref _widget3dPtr, ref _widgetPtr); } protected override void DisposeObject() { IntPtr zero = IntPtr.Zero; if (!zero.Equals((object?)(nint)_ptr)) { CvInvoke.cveWCircleRelease(ref _ptr); } _widgetPtr = IntPtr.Zero; _widget3dPtr = IntPtr.Zero; } } public class WCloud : UnmanagedObject, IWidget3D, IWidget { private IntPtr _widgetPtr; private IntPtr _widget3dPtr; public IntPtr GetWidget3D => _widget3dPtr; public IntPtr GetWidget => _widgetPtr; public WCloud(IInputArray cloud, IInputArray color) { using InputArray inputArray = cloud.GetInputArray(); using InputArray inputArray2 = color.GetInputArray(); CvInvoke.cveWCloudCreateWithColorArray(inputArray, inputArray2, ref _widget3dPtr, ref _widgetPtr); } public WCloud(IInputArray cloud, MCvScalar color) { using InputArray inputArray = cloud.GetInputArray(); CvInvoke.cveWCloudCreateWithColor(inputArray, ref color, ref _widget3dPtr, ref _widgetPtr); } protected override void DisposeObject() { if (IntPtr.Zero != _ptr) { CvInvoke.cveWCloudRelease(ref _ptr); _widgetPtr = IntPtr.Zero; _widget3dPtr = IntPtr.Zero; } } } public class WCone : UnmanagedObject, IWidget3D, IWidget { private IntPtr _widgetPtr; private IntPtr _widget3dPtr; public IntPtr GetWidget3D => _widget3dPtr; public IntPtr GetWidget => _widgetPtr; public WCone(double length, double radius, int resolution, MCvScalar color) { _ptr = CvInvoke.cveWConeCreateAtOrigin(length, radius, resolution, ref color, ref _widget3dPtr, ref _widgetPtr); } public WCone(double radius, MCvPoint3D64f center, MCvPoint3D64f tip, int resolution, MCvScalar color) { _ptr = CvInvoke.cveWConeCreate(radius, ref center, ref tip, resolution, ref color, ref _widget3dPtr, ref _widgetPtr); } protected override void DisposeObject() { IntPtr zero = IntPtr.Zero; if (!zero.Equals((object?)(nint)_ptr)) { CvInvoke.cveWConeRelease(ref _ptr); } _widgetPtr = IntPtr.Zero; _widget3dPtr = IntPtr.Zero; } } public class WCoordinateSystem : UnmanagedObject, IWidget3D, IWidget { private IntPtr _widgetPtr; private IntPtr _widget3dPtr; public IntPtr GetWidget3D => _widget3dPtr; public IntPtr GetWidget => _widgetPtr; public WCoordinateSystem(double scale = 1.0) { _ptr = CvInvoke.cveWCoordinateSystemCreate(scale, ref _widget3dPtr, ref _widgetPtr); } protected override void DisposeObject() { IntPtr zero = IntPtr.Zero; if (!zero.Equals((object?)(nint)_ptr)) { CvInvoke.cveWCoordinateSystemRelease(ref _ptr); } _widgetPtr = IntPtr.Zero; _widget3dPtr = IntPtr.Zero; } } public class WCube : UnmanagedObject, IWidget3D, IWidget { private IntPtr _widgetPtr; private IntPtr _widget3dPtr; public IntPtr GetWidget3D => _widget3dPtr; public IntPtr GetWidget => _widgetPtr; public WCube(MCvPoint3D64f minPoint, MCvPoint3D64f maxPoint, bool wireFrame, MCvScalar color) { _ptr = CvInvoke.cveWCubeCreate(ref minPoint, ref maxPoint, wireFrame, ref color, ref _widget3dPtr, ref _widgetPtr); } protected override void DisposeObject() { IntPtr zero = IntPtr.Zero; if (!zero.Equals((object?)(nint)_ptr)) { CvInvoke.cveWCubeRelease(ref _ptr); } _widgetPtr = IntPtr.Zero; _widget3dPtr = IntPtr.Zero; } } public class WCylinder : UnmanagedObject, IWidget3D, IWidget { private IntPtr _widgetPtr; private IntPtr _widget3dPtr; public IntPtr GetWidget3D => _widget3dPtr; public IntPtr GetWidget => _widgetPtr; public WCylinder(ref MCvPoint3D64f axisPoint1, MCvPoint3D64f axisPoint2, double radius, int numsides, MCvScalar color) { _ptr = CvInvoke.cveWCylinderCreate(ref axisPoint1, ref axisPoint2, radius, numsides, ref color, ref _widget3dPtr, ref _widgetPtr); } protected override void DisposeObject() { IntPtr zero = IntPtr.Zero; if (!zero.Equals((object?)(nint)_ptr)) { CvInvoke.cveWCylinderRelease(ref _ptr); } _widgetPtr = IntPtr.Zero; _widget3dPtr = IntPtr.Zero; } } public class WText : UnmanagedObject, IWidget2D, IWidget { private IntPtr _widgetPtr; private IntPtr _widget2dPtr; public IntPtr GetWidget2D => _widget2dPtr; public IntPtr GetWidget => _widgetPtr; public WText(string text, Point pos, int fontSize, MCvScalar color) { using CvString cvString = new CvString(text); _ptr = CvInvoke.cveWTextCreate(cvString, ref pos, fontSize, ref color, ref _widget2dPtr, ref _widgetPtr); } protected override void DisposeObject() { IntPtr zero = IntPtr.Zero; if (!zero.Equals((object?)(nint)_ptr)) { CvInvoke.cveWTextRelease(ref _ptr); _widgetPtr = IntPtr.Zero; _widget2dPtr = IntPtr.Zero; } } } public static class PointCollection { public static Ellipse EllipseLeastSquareFitting(PointF[] points) { using VectorOfPointF points2 = new VectorOfPointF(points); Ellipse result = new Ellipse(CvInvoke.FitEllipse(points2)); RotatedRect rotatedRect = result.RotatedRect; rotatedRect.Angle = 0f - rotatedRect.Angle; if (rotatedRect.Angle < 0f) { rotatedRect.Angle += 360f; } result.RotatedRect = rotatedRect; return result; } public static LineSegment2DF[] PolyLine(PointF[] points, bool closed) { int num = points.Length; LineSegment2DF[] array; if (closed) { array = new LineSegment2DF[num]; PointF p = points[num - 1]; for (int i = 0; i < array.Length; i++) { array[i] = new LineSegment2DF(p, points[i]); p = points[i]; } } else { array = new LineSegment2DF[num - 1]; PointF p2 = points[0]; for (int j = 1; j < array.Length; j++) { array[j] = new LineSegment2DF(p2, points[j]); p2 = points[j]; } } return array; } public static LineSegment2D[] PolyLine(Point[] points, bool closed) { int num = points.Length; LineSegment2D[] array; if (closed) { array = new LineSegment2D[num]; for (int i = 0; i < array.Length; i++) { array[i] = new LineSegment2D(points[i], points[(i + 1) % num]); } } else { array = new LineSegment2D[num - 1]; for (int j = 0; j < array.Length; j++) { array[j] = new LineSegment2D(points[j], points[j + 1]); } } return array; } public static Rectangle BoundingRectangle(PointF[] points) { using VectorOfPointF points2 = new VectorOfPointF(points); return CvInvoke.BoundingRectangle(points2); } public static MCvPoint3D32f[] ReprojectImageTo3D(IInputArray disparity, IInputArray Q) { Size size; using (InputArray inputArray = disparity.GetInputArray()) { size = inputArray.GetSize(); } MCvPoint3D32f[] array = new MCvPoint3D32f[size.Width * size.Height]; GCHandle gCHandle = GCHandle.Alloc(array, GCHandleType.Pinned); using (Matrix image3D = new Matrix(size.Height, size.Width, 3, gCHandle.AddrOfPinnedObject(), 0)) { CvInvoke.ReprojectImageTo3D(disparity, image3D, Q, handleMissingValues: false, DepthType.Cv32F); } gCHandle.Free(); return array; } public static PointF[] GeneratePointCloud(Ellipse e, int numberOfPoints) { PointF[] array = new PointF[numberOfPoints]; GCHandle gCHandle = GCHandle.Alloc(array, GCHandleType.Pinned); using (Matrix matrix = new Matrix(numberOfPoints, 2, gCHandle.AddrOfPinnedObject())) { using Matrix matrix2 = matrix.GetCol(0); using Matrix matrix3 = matrix.GetCol(1); using RotationMatrix2D rotationMatrix2D = new RotationMatrix2D(e.RotatedRect.Center, e.RotatedRect.Angle, 1.0); using Mat m = new Mat(); rotationMatrix2D.ConvertTo(m, DepthType.Cv32F); matrix2.SetRandNormal(new MCvScalar(e.RotatedRect.Center.X), new MCvScalar(e.RotatedRect.Size.Width / 2f)); matrix3.SetRandNormal(new MCvScalar(e.RotatedRect.Center.Y), new MCvScalar(e.RotatedRect.Size.Height / 2f)); rotationMatrix2D.RotatePoints(matrix); } gCHandle.Free(); return array; } } public interface IBackgroundSubtractor : IAlgorithm { IntPtr BackgroundSubtractorPtr { get; } } public static class BackgroundSubtractorExtension { public static void Apply(this IBackgroundSubtractor subtractor, IInputArray image, IOutputArray fgMask, double learningRate = -1.0) { using InputArray inputArray = image.GetInputArray(); using OutputArray outputArray = fgMask.GetOutputArray(); CvInvoke.cveBackgroundSubtractorUpdate(subtractor.BackgroundSubtractorPtr, inputArray, outputArray, learningRate); } public static void GetBackgroundImage(this IBackgroundSubtractor subtractor, IOutputArray backgroundImage) { using OutputArray outputArray = backgroundImage.GetOutputArray(); CvInvoke.cveBackgroundSubtractorGetBackgroundImage(subtractor.BackgroundSubtractorPtr, outputArray); } } public class BackgroundSubtractorKNN : UnmanagedObject, IBackgroundSubtractor, IAlgorithm { private IntPtr _sharedPtr; private IntPtr _algorithmPtr; private IntPtr _backgroundSubtractorPtr; public IntPtr AlgorithmPtr => _algorithmPtr; public IntPtr BackgroundSubtractorPtr => _backgroundSubtractorPtr; public int History { get { return CvInvoke.cveBackgroundSubtractorKNNGetHistory(_ptr); } set { CvInvoke.cveBackgroundSubtractorKNNSetHistory(_ptr, value); } } public int NSamples { get { return CvInvoke.cveBackgroundSubtractorKNNGetNSamples(_ptr); } set { CvInvoke.cveBackgroundSubtractorKNNSetNSamples(_ptr, value); } } public double Dist2Threshold { get { return CvInvoke.cveBackgroundSubtractorKNNGetDist2Threshold(_ptr); } set { CvInvoke.cveBackgroundSubtractorKNNSetDist2Threshold(_ptr, value); } } public int KNNSamples { get { return CvInvoke.cveBackgroundSubtractorKNNGetKNNSamples(_ptr); } set { CvInvoke.cveBackgroundSubtractorKNNSetKNNSamples(_ptr, value); } } public bool DetectShadows { get { return CvInvoke.cveBackgroundSubtractorKNNGetDetectShadows(_ptr); } set { CvInvoke.cveBackgroundSubtractorKNNSetDetectShadows(_ptr, value); } } public int ShadowValue { get { return CvInvoke.cveBackgroundSubtractorKNNGetShadowValue(_ptr); } set { CvInvoke.cveBackgroundSubtractorKNNSetShadowValue(_ptr, value); } } public double ShadowThreshold { get { return CvInvoke.cveBackgroundSubtractorKNNGetShadowThreshold(_ptr); } set { CvInvoke.cveBackgroundSubtractorKNNSetShadowThreshold(_ptr, value); } } public BackgroundSubtractorKNN(int history, double dist2Threshold, bool detectShadows) { _ptr = CvInvoke.cveBackgroundSubtractorKNNCreate(history, dist2Threshold, detectShadows, ref _backgroundSubtractorPtr, ref _algorithmPtr, ref _sharedPtr); } protected override void DisposeObject() { if (_ptr != IntPtr.Zero) { CvInvoke.cveBackgroundSubtractorKNNRelease(ref _ptr, ref _sharedPtr); _backgroundSubtractorPtr = IntPtr.Zero; _algorithmPtr = IntPtr.Zero; } } } public class BackgroundSubtractorMOG2 : UnmanagedObject, IBackgroundSubtractor, IAlgorithm { private IntPtr _sharedPtr; private IntPtr _algorithmPtr; private IntPtr _backgroundSubtractorPtr; public IntPtr AlgorithmPtr => _algorithmPtr; public IntPtr BackgroundSubtractorPtr => _backgroundSubtractorPtr; public int History { get { return CvInvoke.cveBackgroundSubtractorMOG2GetHistory(_ptr); } set { CvInvoke.cveBackgroundSubtractorMOG2SetHistory(_ptr, value); } } public bool DetectShadows { get { return CvInvoke.cveBackgroundSubtractorMOG2GetDetectShadows(_ptr); } set { CvInvoke.cveBackgroundSubtractorMOG2SetDetectShadows(_ptr, value); } } public int ShadowValue { get { return CvInvoke.cveBackgroundSubtractorMOG2GetShadowValue(_ptr); } set { CvInvoke.cveBackgroundSubtractorMOG2SetShadowValue(_ptr, value); } } public double ShadowThreshold { get { return CvInvoke.cveBackgroundSubtractorMOG2GetShadowThreshold(_ptr); } set { CvInvoke.cveBackgroundSubtractorMOG2SetShadowThreshold(_ptr, value); } } public int NMixtures { get { return CvInvoke.cveBackgroundSubtractorMOG2GetNMixtures(_ptr); } set { CvInvoke.cveBackgroundSubtractorMOG2SetNMixtures(_ptr, value); } } public double BackgroundRatio { get { return CvInvoke.cveBackgroundSubtractorMOG2GetBackgroundRatio(_ptr); } set { CvInvoke.cveBackgroundSubtractorMOG2SetBackgroundRatio(_ptr, value); } } public double VarThreshold { get { return CvInvoke.cveBackgroundSubtractorMOG2GetVarThreshold(_ptr); } set { CvInvoke.cveBackgroundSubtractorMOG2SetVarThreshold(_ptr, value); } } public double VarThresholdGen { get { return CvInvoke.cveBackgroundSubtractorMOG2GetVarThresholdGen(_ptr); } set { CvInvoke.cveBackgroundSubtractorMOG2SetVarThresholdGen(_ptr, value); } } public double VarInit { get { return CvInvoke.cveBackgroundSubtractorMOG2GetVarInit(_ptr); } set { CvInvoke.cveBackgroundSubtractorMOG2SetVarInit(_ptr, value); } } public double VarMin { get { return CvInvoke.cveBackgroundSubtractorMOG2GetVarMin(_ptr); } set { CvInvoke.cveBackgroundSubtractorMOG2SetVarMin(_ptr, value); } } public double VarMax { get { return CvInvoke.cveBackgroundSubtractorMOG2GetVarMax(_ptr); } set { CvInvoke.cveBackgroundSubtractorMOG2SetVarMax(_ptr, value); } } public double ComplexityReductionThreshold { get { return CvInvoke.cveBackgroundSubtractorMOG2GetComplexityReductionThreshold(_ptr); } set { CvInvoke.cveBackgroundSubtractorMOG2SetComplexityReductionThreshold(_ptr, value); } } public BackgroundSubtractorMOG2(int history = 500, float varThreshold = 16f, bool shadowDetection = true) { _ptr = CvInvoke.cveBackgroundSubtractorMOG2Create(history, varThreshold, shadowDetection, ref _backgroundSubtractorPtr, ref _algorithmPtr, ref _sharedPtr); } protected override void DisposeObject() { if (_ptr != IntPtr.Zero) { CvInvoke.cveBackgroundSubtractorMOG2Release(ref _ptr, ref _sharedPtr); _backgroundSubtractorPtr = IntPtr.Zero; _algorithmPtr = IntPtr.Zero; } } } public interface IDenseOpticalFlow : IAlgorithm { IntPtr DenseOpticalFlowPtr { get; } } public static class DenseOpticalFlowExtensions { public static void Calc(this IDenseOpticalFlow opticalFlow, IInputArray i0, IInputArray i1, IInputOutputArray flow) { using InputArray inputArray = i0.GetInputArray(); using InputArray inputArray2 = i1.GetInputArray(); using InputOutputArray inputOutputArray = flow.GetInputOutputArray(); CvInvoke.cveDenseOpticalFlowCalc(opticalFlow.DenseOpticalFlowPtr, inputArray, inputArray2, inputOutputArray); } } public class DISOpticalFlow : UnmanagedObject, IDenseOpticalFlow, IAlgorithm { public enum Preset { UltraFast, Fast, Medium } private IntPtr _sharedPtr; private IntPtr _denseFlowPtr; private IntPtr _algorithmPtr; public IntPtr AlgorithmPtr => _algorithmPtr; public IntPtr DenseOpticalFlowPtr => _denseFlowPtr; public int FinestScale { get { return CvInvoke.cveDISOpticalFlowGetFinestScale(_ptr); } set { CvInvoke.cveDISOpticalFlowSetFinestScale(_ptr, value); } } public int PatchSize { get { return CvInvoke.cveDISOpticalFlowGetPatchSize(_ptr); } set { CvInvoke.cveDISOpticalFlowSetPatchSize(_ptr, value); } } public int PatchStride { get { return CvInvoke.cveDISOpticalFlowGetPatchStride(_ptr); } set { CvInvoke.cveDISOpticalFlowSetPatchStride(_ptr, value); } } public int GradientDescentIterations { get { return CvInvoke.cveDISOpticalFlowGetGradientDescentIterations(_ptr); } set { CvInvoke.cveDISOpticalFlowSetGradientDescentIterations(_ptr, value); } } public int VariationalRefinementIterations { get { return CvInvoke.cveDISOpticalFlowGetVariationalRefinementIterations(_ptr); } set { CvInvoke.cveDISOpticalFlowSetVariationalRefinementIterations(_ptr, value); } } public float VariationalRefinementAlpha { get { return CvInvoke.cveDISOpticalFlowGetVariationalRefinementAlpha(_ptr); } set { CvInvoke.cveDISOpticalFlowSetVariationalRefinementAlpha(_ptr, value); } } public float VariationalRefinementDelta { get { return CvInvoke.cveDISOpticalFlowGetVariationalRefinementDelta(_ptr); } set { CvInvoke.cveDISOpticalFlowSetVariationalRefinementDelta(_ptr, value); } } public float VariationalRefinementGamma { get { return CvInvoke.cveDISOpticalFlowGetVariationalRefinementGamma(_ptr); } set { CvInvoke.cveDISOpticalFlowSetVariationalRefinementGamma(_ptr, value); } } public bool UseMeanNormalization { get { return CvInvoke.cveDISOpticalFlowGetUseMeanNormalization(_ptr); } set { CvInvoke.cveDISOpticalFlowSetUseMeanNormalization(_ptr, value); } } public bool UseSpatialPropagation { get { return CvInvoke.cveDISOpticalFlowGetUseSpatialPropagation(_ptr); } set { CvInvoke.cveDISOpticalFlowSetUseSpatialPropagation(_ptr, value); } } public DISOpticalFlow(Preset preset = Preset.Fast) { _ptr = CvInvoke.cveDISOpticalFlowCreate(preset, ref _denseFlowPtr, ref _algorithmPtr, ref _sharedPtr); } protected override void DisposeObject() { if (IntPtr.Zero != _ptr) { CvInvoke.cveDISOpticalFlowRelease(ref _ptr, ref _sharedPtr); } _algorithmPtr = IntPtr.Zero; _denseFlowPtr = IntPtr.Zero; } } public class FarnebackOpticalFlow : UnmanagedObject, IDenseOpticalFlow, IAlgorithm { private IntPtr _sharedPtr; private IntPtr _algorithm; private IntPtr _denseOpticalFlow; public IntPtr DenseOpticalFlowPtr => _denseOpticalFlow; public IntPtr AlgorithmPtr => _algorithm; public FarnebackOpticalFlow(int numLevels = 5, double pyrScale = 0.5, bool fastPyramids = false, int winSize = 13, int numIters = 10, int polyN = 5, double polySigma = 1.1, OpticalflowFarnebackFlag flags = OpticalflowFarnebackFlag.Default) { _ptr = CvInvoke.cveFarnebackOpticalFlowCreate(numLevels, pyrScale, fastPyramids, winSize, numIters, polyN, polySigma, flags, ref _denseOpticalFlow, ref _algorithm, ref _sharedPtr); } protected override void DisposeObject() { if (_ptr != IntPtr.Zero) { CvInvoke.cveFarnebackOpticalFlowRelease(ref _ptr, ref _sharedPtr); _algorithm = IntPtr.Zero; _denseOpticalFlow = IntPtr.Zero; } } } public class KalmanFilter : UnmanagedObject { public Mat StatePre => new Mat(CvInvoke.cveKalmanFilterGetStatePre(_ptr), needDispose: false); public Mat StatePost => new Mat(CvInvoke.cveKalmanFilterGetStatePost(_ptr), needDispose: false); public Mat TransitionMatrix => new Mat(CvInvoke.cveKalmanFilterGetTransitionMatrix(_ptr), needDispose: false); public Mat ControlMatrix => new Mat(CvInvoke.cveKalmanFilterGetControlMatrix(_ptr), needDispose: false); public Mat MeasurementMatrix => new Mat(CvInvoke.cveKalmanFilterGetMeasurementMatrix(_ptr), needDispose: false); public Mat ProcessNoiseCov => new Mat(CvInvoke.cveKalmanFilterGetProcessNoiseCov(_ptr), needDispose: false); public Mat MeasurementNoiseCov => new Mat(CvInvoke.cveKalmanFilterGetMeasurementNoiseCov(_ptr), needDispose: false); public Mat ErrorCovPre => new Mat(CvInvoke.cveKalmanFilterGetErrorCovPre(_ptr), needDispose: false); public Mat Gain => new Mat(CvInvoke.cveKalmanFilterGetGain(_ptr), needDispose: false); public Mat ErrorCovPost => new Mat(CvInvoke.cveKalmanFilterGetErrorCovPost(_ptr), needDispose: false); public KalmanFilter(int dynamParams, int measureParams, int controlParams, DepthType type = DepthType.Cv32F) { _ptr = CvInvoke.cveKalmanFilterCreate(dynamParams, measureParams, controlParams, type); } public Mat Predict(Mat control = null) { return new Mat(CvInvoke.cveKalmanFilterPredict(_ptr, control), needDispose: false); } public Mat Correct(Mat measurement) { return new Mat(CvInvoke.cveKalmanFilterCorrect(_ptr, measurement), needDispose: false); } protected override void DisposeObject() { if (_ptr != IntPtr.Zero) { CvInvoke.cveKalmanFilterRelease(ref _ptr); } } } public interface ISparseOpticalFlow : IAlgorithm { IntPtr SparseOpticalFlowPtr { get; } } public static class SparseOpticalFlowExtensions { public static void Calc(this ISparseOpticalFlow opticalFlow, IInputArray prevImg, IInputArray nextImg, IInputArray prevPts, IInputOutputArray nextPts, IOutputArray status, IOutputArray error = null) { using InputArray inputArray = prevImg.GetInputArray(); using InputArray inputArray2 = nextImg.GetInputArray(); using InputArray inputArray3 = prevPts.GetInputArray(); using InputOutputArray inputOutputArray = nextPts.GetInputOutputArray(); using OutputArray outputArray = status.GetOutputArray(); using OutputArray outputArray2 = ((error == null) ? OutputArray.GetEmpty() : error.GetOutputArray()); CvInvoke.cveSparseOpticalFlowCalc(opticalFlow.SparseOpticalFlowPtr, inputArray, inputArray2, inputArray3, inputOutputArray, outputArray, outputArray2); } } public class SparsePyrLKOpticalFlow : UnmanagedObject, ISparseOpticalFlow, IAlgorithm { private IntPtr _sharedPtr; private IntPtr _algorithm; private IntPtr _sparseOpticalFlow; public IntPtr SparseOpticalFlowPtr => _sparseOpticalFlow; public IntPtr AlgorithmPtr => _algorithm; public SparsePyrLKOpticalFlow(Size winSize, int maxLevel, MCvTermCriteria crit, LKFlowFlag flags, double minEigThreshold) { _ptr = CvInvoke.cveSparsePyrLKOpticalFlowCreate(ref winSize, maxLevel, ref crit, flags, minEigThreshold, ref _sparseOpticalFlow, ref _algorithm, ref _sharedPtr); } protected override void DisposeObject() { if (_ptr != IntPtr.Zero) { CvInvoke.cveSparsePyrLKOpticalFlowRelease(ref _ptr, ref _sharedPtr); _algorithm = IntPtr.Zero; _sparseOpticalFlow = IntPtr.Zero; } } } public abstract class Tracker : UnmanagedObject { protected IntPtr _trackerPtr; public void Init(IInputArray image, Rectangle boundingBox) { using InputArray inputArray = image.GetInputArray(); CvInvoke.cveTrackerInit(_trackerPtr, inputArray, ref boundingBox); } public bool Update(IInputArray image, out Rectangle boundingBox) { boundingBox = default(Rectangle); using InputArray inputArray = image.GetInputArray(); return CvInvoke.cveTrackerUpdate(_trackerPtr, inputArray, ref boundingBox); } protected override void DisposeObject() { _trackerPtr = IntPtr.Zero; } } public class TrackerDaSiamRPN : Tracker { private IntPtr _sharedPtr; public float TrackingScore => CvInvoke.cveTrackerDaSiamRPNGetTrackingScore(_ptr); public TrackerDaSiamRPN(string model = "dasiamrpn_model.onnx", string kernelCls1 = "dasiamrpn_kernel_cls1.onnx", string kernelR1 = "dasiamrpn_kernel_r1.onnx", Emgu.CV.Dnn.Backend backend = Emgu.CV.Dnn.Backend.Default, Target target = Target.Cpu) { using CvString cvString = new CvString(model); using CvString cvString2 = new CvString(kernelCls1); using CvString cvString3 = new CvString(kernelR1); _ptr = CvInvoke.cveTrackerDaSiamRPNCreate(cvString, cvString2, cvString3, backend, target, ref _trackerPtr, ref _sharedPtr); } protected override void DisposeObject() { if (IntPtr.Zero != _ptr) { CvInvoke.cveTrackerDaSiamRPNRelease(ref _ptr, ref _sharedPtr); } base.DisposeObject(); } } public class TrackerGOTURN : Tracker { private IntPtr _sharedPtr; public TrackerGOTURN() { _ptr = CvInvoke.cveTrackerGOTURNCreate(ref _trackerPtr, ref _sharedPtr); } protected override void DisposeObject() { if (IntPtr.Zero != _ptr) { CvInvoke.cveTrackerGOTURNRelease(ref _ptr, ref _sharedPtr); } base.DisposeObject(); } } public class TrackerMIL : Tracker { private IntPtr _sharedPtr; public TrackerMIL(float samplerInitInRadius = 3f, int samplerInitMaxNegNum = 65, float samplerSearchWinSize = 25f, float samplerTrackInRadius = 4f, int samplerTrackMaxPosNum = 100000, int samplerTrackMaxNegNum = 65, int featureSetNumFeatures = 250) { CvInvoke.cveTrackerMILCreate(samplerInitInRadius, samplerInitMaxNegNum, samplerSearchWinSize, samplerTrackInRadius, samplerTrackMaxPosNum, samplerTrackMaxNegNum, featureSetNumFeatures, ref _trackerPtr, ref _sharedPtr); } protected override void DisposeObject() { if (IntPtr.Zero != _ptr) { CvInvoke.cveTrackerMILRelease(ref _ptr, ref _sharedPtr); } base.DisposeObject(); } } public class VariationalRefinement : UnmanagedObject, IDenseOpticalFlow, IAlgorithm { private IntPtr _sharedPtr; private IntPtr _denseFlowPtr; private IntPtr _algorithmPtr; public IntPtr AlgorithmPtr => _algorithmPtr; public IntPtr DenseOpticalFlowPtr => _denseFlowPtr; public int FixedPointIterations { get { return CvInvoke.cveVariationalRefinementGetFixedPointIterations(_ptr); } set { CvInvoke.cveVariationalRefinementSetFixedPointIterations(_ptr, value); } } public int SorIterations { get { return CvInvoke.cveVariationalRefinementGetSorIterations(_ptr); } set { CvInvoke.cveVariationalRefinementSetSorIterations(_ptr, value); } } public float Omega { get { return CvInvoke.cveVariationalRefinementGetOmega(_ptr); } set { CvInvoke.cveVariationalRefinementSetOmega(_ptr, value); } } public float Alpha { get { return CvInvoke.cveVariationalRefinementGetAlpha(_ptr); } set { CvInvoke.cveVariationalRefinementSetAlpha(_ptr, value); } } public float Delta { get { return CvInvoke.cveVariationalRefinementGetDelta(_ptr); } set { CvInvoke.cveVariationalRefinementSetDelta(_ptr, value); } } public float Gamma { get { return CvInvoke.cveVariationalRefinementGetGamma(_ptr); } set { CvInvoke.cveVariationalRefinementSetGamma(_ptr, value); } } public VariationalRefinement() { _ptr = CvInvoke.cveVariationalRefinementCreate(ref _denseFlowPtr, ref _algorithmPtr, ref _sharedPtr); } protected override void DisposeObject() { if (IntPtr.Zero != _ptr) { CvInvoke.cveVariationalRefinementRelease(ref _ptr, ref _sharedPtr); } _algorithmPtr = IntPtr.Zero; _denseFlowPtr = IntPtr.Zero; } } public class DenseRLOFOpticalFlow : SharedPtrObject, IDenseOpticalFlow, IAlgorithm { public enum InterpolationType { Geo, Epic } private IntPtr _algorithm; private IntPtr _denseOpticalFlow; public IntPtr DenseOpticalFlowPtr => _denseOpticalFlow; public IntPtr AlgorithmPtr => _algorithm; public DenseRLOFOpticalFlow(RLOFOpticalFlowParameter parameter, float forwardBackwardThreshold, Size gridStep, InterpolationType interpType = InterpolationType.Epic, int epicK = 128, float epicSigma = 0.05f, float epicLambda = 999f, bool usePostProc = true, float fgsLambda = 500f, float fgsSigma = 1.5f) { _ptr = CvInvoke.cveDenseRLOFOpticalFlowCreate(parameter, forwardBackwardThreshold, ref gridStep, interpType, epicK, epicSigma, epicLambda, usePostProc, fgsLambda, fgsSigma, ref _denseOpticalFlow, ref _algorithm, ref _sharedPtr); } protected override void DisposeObject() { if (_sharedPtr != IntPtr.Zero) { CvInvoke.cveDenseRLOFOpticalFlowRelease(ref _sharedPtr); _ptr = IntPtr.Zero; _algorithm = IntPtr.Zero; _denseOpticalFlow = IntPtr.Zero; } } } public class DualTVL1OpticalFlow : SharedPtrObject, IDenseOpticalFlow, IAlgorithm { private IntPtr _algorithm; private IntPtr _denseOpticalFlow; public IntPtr DenseOpticalFlowPtr => _denseOpticalFlow; public IntPtr AlgorithmPtr => _algorithm; public double Tau { get { return CvInvoke.cveDualTVL1OpticalFlowGetTau(_ptr); } set { CvInvoke.cveDualTVL1OpticalFlowSetTau(_ptr, value); } } public double Lambda { get { return CvInvoke.cveDualTVL1OpticalFlowGetLambda(_ptr); } set { CvInvoke.cveDualTVL1OpticalFlowSetLambda(_ptr, value); } } public double Theta { get { return CvInvoke.cveDualTVL1OpticalFlowGetTheta(_ptr); } set { CvInvoke.cveDualTVL1OpticalFlowSetTheta(_ptr, value); } } public double Gamma { get { return CvInvoke.cveDualTVL1OpticalFlowGetGamma(_ptr); } set { CvInvoke.cveDualTVL1OpticalFlowSetGamma(_ptr, value); } } public int ScalesNumber { get { return CvInvoke.cveDualTVL1OpticalFlowGetScalesNumber(_ptr); } set { CvInvoke.cveDualTVL1OpticalFlowSetScalesNumber(_ptr, value); } } public int WarpingsNumber { get { return CvInvoke.cveDualTVL1OpticalFlowGetWarpingsNumber(_ptr); } set { CvInvoke.cveDualTVL1OpticalFlowSetWarpingsNumber(_ptr, value); } } public double Epsilon { get { return CvInvoke.cveDualTVL1OpticalFlowGetEpsilon(_ptr); } set { CvInvoke.cveDualTVL1OpticalFlowSetEpsilon(_ptr, value); } } public int InnerIterations { get { return CvInvoke.cveDualTVL1OpticalFlowGetInnerIterations(_ptr); } set { CvInvoke.cveDualTVL1OpticalFlowSetInnerIterations(_ptr, value); } } public int OuterIterations { get { return CvInvoke.cveDualTVL1OpticalFlowGetOuterIterations(_ptr); } set { CvInvoke.cveDualTVL1OpticalFlowSetOuterIterations(_ptr, value); } } public bool UseInitialFlow { get { return CvInvoke.cveDualTVL1OpticalFlowGetUseInitialFlow(_ptr); } set { CvInvoke.cveDualTVL1OpticalFlowSetUseInitialFlow(_ptr, value); } } public double ScaleStep { get { return CvInvoke.cveDualTVL1OpticalFlowGetScaleStep(_ptr); } set { CvInvoke.cveDualTVL1OpticalFlowSetScaleStep(_ptr, value); } } public int MedianFiltering { get { return CvInvoke.cveDualTVL1OpticalFlowGetMedianFiltering(_ptr); } set { CvInvoke.cveDualTVL1OpticalFlowSetMedianFiltering(_ptr, value); } } public DualTVL1OpticalFlow() { _ptr = CvInvoke.cveDenseOpticalFlowCreateDualTVL1(ref _denseOpticalFlow, ref _algorithm, ref _sharedPtr); } protected override void DisposeObject() { if (_sharedPtr != IntPtr.Zero) { CvInvoke.cveDualTVL1OpticalFlowRelease(ref _sharedPtr); _ptr = IntPtr.Zero; _algorithm = IntPtr.Zero; _denseOpticalFlow = IntPtr.Zero; } } } public class MotionHistory : DisposableObject { private double _mhiDuration; private Mat _mhi; private Mat _mask = new Mat(); private Mat _orientation = new Mat(); private DateTime _initTime; private DateTime _lastTime; private double _maxTimeDelta; private double _minTimeDelta; public Mat Mask => _mask; public MotionHistory(double mhiDuration, double maxTimeDelta, double minTimeDelta) : this(mhiDuration, maxTimeDelta, minTimeDelta, DateTime.Now) { } public MotionHistory(double mhiDuration, double maxTimeDelta, double minTimeDelta, DateTime startTime) { _mhiDuration = mhiDuration; _initTime = startTime; _maxTimeDelta = maxTimeDelta; _minTimeDelta = minTimeDelta; } public void Update(Mat image) { Update(image, DateTime.Now); } public void Update(Mat foregroundMask, DateTime timestamp) { _lastTime = timestamp; TimeSpan timeSpan = _lastTime.Subtract(_initTime); if (_mhi == null) { _mhi = new Mat(foregroundMask.Rows, foregroundMask.Cols, DepthType.Cv32F, 1); } CvInvoke.UpdateMotionHistory(foregroundMask, _mhi, timeSpan.TotalSeconds, _mhiDuration); double num = 255.0 / _mhiDuration; _mhi.ConvertTo(_mask, DepthType.Cv8U, num, (_mhiDuration - timeSpan.TotalSeconds) * num); CvInvoke.CalcMotionGradient(_mhi, _mask, _orientation, _maxTimeDelta, _minTimeDelta); } public void GetMotionComponents(IOutputArray segMask, VectorOfRect boundingRects) { TimeSpan timeSpan = _lastTime.Subtract(_initTime); CvInvoke.SegmentMotion(_mhi, segMask, boundingRects, timeSpan.TotalSeconds, _maxTimeDelta); } public Rectangle[] GetMotionComponents(IOutputArray segMask) { using VectorOfRect vectorOfRect = new VectorOfRect(); GetMotionComponents(segMask, vectorOfRect); return vectorOfRect.ToArray(); } public void MotionInfo(Mat forgroundMask, Rectangle motionRectangle, out double angle, out double motionPixelCount) { TimeSpan timeSpan = _lastTime.Subtract(_initTime); using Mat arr = new Mat(forgroundMask, motionRectangle); using Mat mhi = new Mat(_mhi, motionRectangle); using Mat orientation = new Mat(_orientation, motionRectangle); using Mat mask = new Mat(_mask, motionRectangle); angle = CvInvoke.CalcGlobalOrientation(orientation, mask, mhi, timeSpan.TotalSeconds, _mhiDuration); angle = 360.0 - angle; motionPixelCount = CvInvoke.Norm(arr, null, NormType.L1); } protected override void DisposeObject() { } protected override void ReleaseManagedResources() { if (_mhi != null) { _mhi.Dispose(); } if (_mask != null) { _mask.Dispose(); } if (_orientation != null) { _orientation.Dispose(); } } } public class OptFlowDeepFlow : SharedPtrObject, IDenseOpticalFlow, IAlgorithm { private IntPtr _algorithmPtr; public IntPtr AlgorithmPtr => _algorithmPtr; public IntPtr DenseOpticalFlowPtr => _ptr; public OptFlowDeepFlow() { _ptr = CvInvoke.cveOptFlowDeepFlowCreate(ref _algorithmPtr, ref _sharedPtr); } protected override void DisposeObject() { if (IntPtr.Zero != _sharedPtr) { CvInvoke.cveDenseOpticalFlowRelease(ref _sharedPtr); _algorithmPtr = IntPtr.Zero; _ptr = IntPtr.Zero; } } } public class OpticalFlowPCAFlow : SharedPtrObject, IDenseOpticalFlow, IAlgorithm { private IntPtr _algorithmPtr; public IntPtr AlgorithmPtr => _algorithmPtr; public IntPtr DenseOpticalFlowPtr => _ptr; public OpticalFlowPCAFlow() { _ptr = CvInvoke.cveOptFlowPCAFlowCreate(ref _algorithmPtr, ref _sharedPtr); } protected override void DisposeObject() { if (IntPtr.Zero != _sharedPtr) { CvInvoke.cveDenseOpticalFlowRelease(ref _sharedPtr); _ptr = IntPtr.Zero; _algorithmPtr = IntPtr.Zero; } } } public class RLOFOpticalFlowParameter : UnmanagedObject { public enum SolverType { Standard, Bilinear } public enum SupportRegionType { Fixed, Cross } public float NormSigma0 { get { return CvInvoke.cveRLOFOpticalFlowParameterGetNormSigma0(_ptr); } set { CvInvoke.cveRLOFOpticalFlowParameterSetNormSigma0(_ptr, value); } } public float NormSigma1 { get { return CvInvoke.cveRLOFOpticalFlowParameterGetNormSigma1(_ptr); } set { CvInvoke.cveRLOFOpticalFlowParameterSetNormSigma1(_ptr, value); } } public SolverType Solver { get { return CvInvoke.cveRLOFOpticalFlowParameterGetSolver(_ptr); } set { CvInvoke.cveRLOFOpticalFlowParameterSetSolver(_ptr, value); } } public SupportRegionType SupportRegion { get { return CvInvoke.cveRLOFOpticalFlowParameterGetSupportRegion(_ptr); } set { CvInvoke.cveRLOFOpticalFlowParameterSetSupportRegion(_ptr, value); } } public int SmallWinSize { get { return CvInvoke.cveRLOFOpticalFlowParameterGetSmallWinSize(_ptr); } set { CvInvoke.cveRLOFOpticalFlowParameterSetSmallWinSize(_ptr, value); } } public int LargeWinSize { get { return CvInvoke.cveRLOFOpticalFlowParameterGetLargeWinSize(_ptr); } set { CvInvoke.cveRLOFOpticalFlowParameterSetLargeWinSize(_ptr, value); } } public int CrossSegmentationThreshold { get { return CvInvoke.cveRLOFOpticalFlowParameterGetCrossSegmentationThreshold(_ptr); } set { CvInvoke.cveRLOFOpticalFlowParameterSetCrossSegmentationThreshold(_ptr, value); } } public int MaxLevel { get { return CvInvoke.cveRLOFOpticalFlowParameterGetMaxLevel(_ptr); } set { CvInvoke.cveRLOFOpticalFlowParameterSetMaxLevel(_ptr, value); } } public bool UseInitialFlow { get { return CvInvoke.cveRLOFOpticalFlowParameterGetUseInitialFlow(_ptr); } set { CvInvoke.cveRLOFOpticalFlowParameterSetUseInitialFlow(_ptr, value); } } public bool UseIlluminationModel { get { return CvInvoke.cveRLOFOpticalFlowParameterGetUseIlluminationModel(_ptr); } set { CvInvoke.cveRLOFOpticalFlowParameterSetUseIlluminationModel(_ptr, value); } } public bool UseGlobalMotionPrior { get { return CvInvoke.cveRLOFOpticalFlowParameterGetUseGlobalMotionPrior(_ptr); } set { CvInvoke.cveRLOFOpticalFlowParameterSetUseGlobalMotionPrior(_ptr, value); } } public int MaxIteration { get { return CvInvoke.cveRLOFOpticalFlowParameterGetMaxIteration(_ptr); } set { CvInvoke.cveRLOFOpticalFlowParameterSetMaxIteration(_ptr, value); } } public float MinEigenValue { get { return CvInvoke.cveRLOFOpticalFlowParameterGetMinEigenValue(_ptr); } set { CvInvoke.cveRLOFOpticalFlowParameterSetMinEigenValue(_ptr, value); } } public float GlobalMotionRansacThreshold { get { return CvInvoke.cveRLOFOpticalFlowParameterGetGlobalMotionRansacThreshold(_ptr); } set { CvInvoke.cveRLOFOpticalFlowParameterSetGlobalMotionRansacThreshold(_ptr, value); } } public RLOFOpticalFlowParameter() { _ptr = CvInvoke.cveRLOFOpticalFlowParameterCreate(); } protected override void DisposeObject() { if (IntPtr.Zero != _ptr) { CvInvoke.cveRLOFOpticalFlowParameterRelease(ref _ptr); } } } public class SparseRLOFOpticalFlow : SharedPtrObject, ISparseOpticalFlow, IAlgorithm { private IntPtr _algorithm; private IntPtr _sparseOpticalFlow; public IntPtr SparseOpticalFlowPtr => _sparseOpticalFlow; public IntPtr AlgorithmPtr => _algorithm; public SparseRLOFOpticalFlow(RLOFOpticalFlowParameter parameter, float forwardBackwardThreshold) { _ptr = CvInvoke.cveSparseRLOFOpticalFlowCreate(parameter, forwardBackwardThreshold, ref _sparseOpticalFlow, ref _algorithm, ref _sharedPtr); } protected override void DisposeObject() { if (_sharedPtr != IntPtr.Zero) { CvInvoke.cveSparseRLOFOpticalFlowRelease(ref _sharedPtr); _ptr = IntPtr.Zero; _algorithm = IntPtr.Zero; _sparseOpticalFlow = IntPtr.Zero; } } } public class CascadeClassifier : UnmanagedObject { public bool IsOldFormatCascade => CvInvoke.cveCascadeClassifierIsOldFormatCascade(_ptr); public Size OriginalWindowSize { get { Size size = default(Size); CvInvoke.cveCascadeClassifierGetOriginalWindowSize(_ptr, ref size); return size; } } public CascadeClassifier() { _ptr = CvInvoke.cveCascadeClassifierCreate(); } public CascadeClassifier(string fileName) { if (!new FileInfo(fileName).Exists) { throw new FileNotFoundException($"File '{fileName}' not found"); } using (CvString cvString = new CvString(fileName)) { _ptr = CvInvoke.cveCascadeClassifierCreateFromFile(cvString); } if (_ptr == IntPtr.Zero) { throw new NullReferenceException($"Fail to create HaarCascade object: {fileName}"); } } public bool Read(FileNode node) { return CvInvoke.cveCascadeClassifierRead(_ptr, node); } public Rectangle[] DetectMultiScale(IInputArray image, double scaleFactor = 1.1, int minNeighbors = 3, Size minSize = default(Size), Size maxSize = default(Size)) { using VectorOfRect vectorOfRect = new VectorOfRect(); using InputArray inputArray = image.GetInputArray(); CvInvoke.cveCascadeClassifierDetectMultiScale(_ptr, inputArray, vectorOfRect, scaleFactor, minNeighbors, 0, ref minSize, ref maxSize); return vectorOfRect.ToArray(); } protected override void DisposeObject() { if (_ptr != IntPtr.Zero) { CvInvoke.cveCascadeClassifierRelease(ref _ptr); } } } public class FaceDetectorYN : SharedPtrObject { public Size InputSize { get { Size val = default(Size); CvInvoke.cveFaceDetectorYNGetInputSize(_ptr, ref val); return val; } set { CvInvoke.cveFaceDetectorYNSetInputSize(_ptr, ref value); } } public FaceDetectorYN(string model, string config, Size inputSize, float scoreThreshold, float nmsThreshold, int topK, Emgu.CV.Dnn.Backend backendId, Target targetId) { using CvString cvString = new CvString(model); using CvString cvString2 = new CvString(config); _ptr = CvInvoke.cveFaceDetectorYNCreate(cvString, cvString2, ref inputSize, scoreThreshold, nmsThreshold, topK, backendId, targetId, ref _sharedPtr); } public int Detect(IInputArray image, IOutputArray faces) { using InputArray inputArray = image.GetInputArray(); using OutputArray outputArray = faces.GetOutputArray(); return CvInvoke.cveFaceDetectorYNDetect(_ptr, inputArray, outputArray); } protected override void DisposeObject() { IntPtr zero = IntPtr.Zero; if (!zero.Equals((object?)(nint)_sharedPtr)) { CvInvoke.cveFaceDetectorYNRelease(ref _sharedPtr); _ptr = IntPtr.Zero; } } public void SetScoreThreshold(float value) { CvInvoke.cveFaceDetectorYNSetScoreThreshold(_ptr, value); } public void SetNMSThreshold(float value) { CvInvoke.cveFaceDetectorYNSetNMSThreshold(_ptr, value); } public void SetTopK(int value) { CvInvoke.cveFaceDetectorYNSetTopK(_ptr, value); } } public class FaceRecognizerSF : SharedPtrObject { public enum DisType { Cosine, NormL2 } public FaceRecognizerSF(string model, string config, Emgu.CV.Dnn.Backend backendId, Target targetId) { using CvString cvString = new CvString(model); using CvString cvString2 = new CvString(config); _ptr = CvInvoke.cveFaceRecognizerSFCreate(cvString, cvString2, backendId, targetId, ref _sharedPtr); } public void AlignCrop(IInputArray srcImg, IInputArray faceBox, IOutputArray alignedImg) { using InputArray inputArray = srcImg.GetInputArray(); using InputArray inputArray2 = faceBox.GetInputArray(); using OutputArray outputArray = alignedImg.GetOutputArray(); CvInvoke.cveFaceRecognizerSFAlignCrop(_ptr, inputArray, inputArray2, outputArray); } public void Feature(IInputArray alignedImg, IOutputArray faceFeature) { using InputArray inputArray = alignedImg.GetInputArray(); using OutputArray outputArray = faceFeature.GetOutputArray(); CvInvoke.cveFaceRecognizerSFFeature(_ptr, inputArray, outputArray); } public double Match(IInputArray faceFeature1, IInputArray faceFeature2, DisType disType = DisType.Cosine) { using InputArray inputArray = faceFeature1.GetInputArray(); using InputArray inputArray2 = faceFeature2.GetInputArray(); return CvInvoke.cveFaceRecognizerSFMatch(_ptr, inputArray, inputArray2, disType); } protected override void DisposeObject() { IntPtr zero = IntPtr.Zero; if (!zero.Equals((object?)(nint)_sharedPtr)) { CvInvoke.cveFaceRecognizerSFRelease(ref _sharedPtr); _ptr = IntPtr.Zero; } } } public class HOGDescriptor : UnmanagedObject { public uint DescriptorSize => CvInvoke.cveHOGDescriptorGetDescriptorSize(_ptr); public HOGDescriptor() { _ptr = CvInvoke.cveHOGDescriptorCreateDefault(); } public HOGDescriptor(Size winSize, Size blockSize, Size blockStride, Size cellSize, int nbins = 9, int derivAperture = 1, double winSigma = -1.0, double L2HysThreshold = 0.2, bool gammaCorrection = true) { _ptr = CvInvoke.cveHOGDescriptorCreate(ref winSize, ref blockSize, ref blockStride, ref cellSize, nbins, derivAperture, winSigma, 0, L2HysThreshold, gammaCorrection); } public static float[] GetDefaultPeopleDetector() { using VectorOfFloat vectorOfFloat = new VectorOfFloat(); CvInvoke.cveHOGDescriptorPeopleDetectorCreate(vectorOfFloat); return vectorOfFloat.ToArray(); } public void SetSVMDetector(float[] detector) { using VectorOfFloat vectorOfFloat = new VectorOfFloat(detector); CvInvoke.cveHOGSetSVMDetector(_ptr, vectorOfFloat); } public MCvObjectDetection[] DetectMultiScale(IInputArray image, double hitThreshold = 0.0, Size winStride = default(Size), Size padding = default(Size), double scale = 1.05, double finalThreshold = 2.0, bool useMeanshiftGrouping = false) { using VectorOfRect vectorOfRect = new VectorOfRect(); using VectorOfDouble vectorOfDouble = new VectorOfDouble(); using InputArray inputArray = image.GetInputArray(); CvInvoke.cveHOGDescriptorDetectMultiScale(_ptr, inputArray, vectorOfRect, vectorOfDouble, hitThreshold, ref winStride, ref padding, scale, finalThreshold, useMeanshiftGrouping); Rectangle[] array = vectorOfRect.ToArray(); double[] array2 = vectorOfDouble.ToArray(); MCvObjectDetection[] array3 = new MCvObjectDetection[array.Length]; for (int i = 0; i < array3.Length; i++) { MCvObjectDetection mCvObjectDetection = default(MCvObjectDetection); mCvObjectDetection.Rect = array[i]; mCvObjectDetection.Score = (float)array2[i]; array3[i] = mCvObjectDetection; } return array3; } public float[] Compute(IInputArray image, Size winStride = default(Size), Size padding = default(Size), Point[] locations = null) { using VectorOfFloat vectorOfFloat = new VectorOfFloat(); using InputArray inputArray = image.GetInputArray(); if (locations == null) { CvInvoke.cveHOGDescriptorCompute(_ptr, inputArray, vectorOfFloat, ref winStride, ref padding, IntPtr.Zero); } else { using VectorOfPoint vectorOfPoint = new VectorOfPoint(locations); CvInvoke.cveHOGDescriptorCompute(_ptr, inputArray, vectorOfFloat, ref winStride, ref padding, vectorOfPoint); } return vectorOfFloat.ToArray(); } protected override void DisposeObject() { IntPtr zero = IntPtr.Zero; if (!zero.Equals((object?)(nint)_ptr)) { CvInvoke.cveHOGDescriptorRelease(ref _ptr); } } } public class QRCodeDetector : UnmanagedObject { public QRCodeDetector() { _ptr = CvInvoke.cveQRCodeDetectorCreate(); } protected override void DisposeObject() { IntPtr zero = IntPtr.Zero; if (!zero.Equals((object?)(nint)_ptr)) { CvInvoke.cveQRCodeDetectorRelease(ref _ptr); } } public bool Detect(IInputArray input, IOutputArray points) { using InputArray inputArray = input.GetInputArray(); using OutputArray outputArray = points.GetOutputArray(); return CvInvoke.cveQRCodeDetectorDetect(_ptr, inputArray, outputArray); } public bool DetectMulti(IInputArray img, IOutputArray points) { using InputArray inputArray = img.GetInputArray(); using OutputArray outputArray = points.GetOutputArray(); return CvInvoke.cveQRCodeDetectorDetectMulti(_ptr, inputArray, outputArray); } public string Decode(IInputArray image, IInputArray points, IOutputArray straightQrcode = null) { using InputArray inputArray = image.GetInputArray(); using InputArray inputArray2 = points.GetInputArray(); using OutputArray outputArray = ((straightQrcode == null) ? OutputArray.GetEmpty() : straightQrcode.GetOutputArray()); using CvString cvString = new CvString(); CvInvoke.cveQRCodeDetectorDecode(_ptr, inputArray, inputArray2, cvString, outputArray); return cvString.ToString(); } public string DecodeCurved(IInputArray img, IInputArray points, IOutputArray straightQrcode = null) { using InputArray inputArray = img.GetInputArray(); using InputArray inputArray2 = points.GetInputArray(); using OutputArray outputArray = ((straightQrcode == null) ? OutputArray.GetEmpty() : straightQrcode.GetOutputArray()); using CvString cvString = new CvString(); CvInvoke.cveQRCodeDetectorDecodeCurved(_ptr, inputArray, inputArray2, cvString, outputArray); return cvString.ToString(); } public bool DecodeMulti(IInputArray img, IInputArray points, VectorOfCvString decodedInfo, IOutputArray straightQrcode = null) { using InputArray inputArray = img.GetInputArray(); using InputArray inputArray2 = points.GetInputArray(); using OutputArray outputArray = ((straightQrcode == null) ? OutputArray.GetEmpty() : straightQrcode.GetOutputArray()); return CvInvoke.cveQRCodeDetectorDecodeMulti(_ptr, inputArray, inputArray2, decodedInfo, outputArray); } public void SetEpsX(double value) { CvInvoke.cveQRCodeDetectorSetEpsX(_ptr, value); } public void SetEpsY(double value) { CvInvoke.cveQRCodeDetectorSetEpsY(_ptr, value); } } public class ConvolutionKernelF : Matrix { protected Point _center; public Point Center { get { return _center; } set { _center = value; } } public ConvolutionKernelF(int rows, int cols) : base(rows, cols) { _center = new Point(-1, -1); } public ConvolutionKernelF(Matrix kernel, Point center) : this(kernel.Data, center) { } public ConvolutionKernelF(float[,] kernel) : this(kernel, new Point(-1, -1)) { } public ConvolutionKernelF(float[,] kernel, Point center) : base(Math.Max(2, kernel.GetLength(0)), Math.Max(2, kernel.GetLength(1))) { int length = kernel.GetLength(0); int length2 = kernel.GetLength(1); float[,] data = base.Data; for (int i = 0; i < length; i++) { for (int j = 0; j < length2; j++) { data[i, j] = kernel[i, j]; } } _center = center; } public ConvolutionKernelF Flip(FlipType flipType) { ConvolutionKernelF convolutionKernelF = new ConvolutionKernelF(base.Height, base.Width); CvInvoke.Flip(this, convolutionKernelF, flipType); convolutionKernelF.Center = new Point((Center.X == -1) ? (-1) : ((flipType == FlipType.Both || flipType == FlipType.Horizontal) ? (base.Width - Center.X - 1) : Center.X), (Center.Y == -1) ? (-1) : ((flipType == FlipType.Both || flipType == FlipType.Vertical) ? (base.Height - Center.Y - 1) : Center.Y)); return convolutionKernelF; } public new ConvolutionKernelF Transpose() { return new ConvolutionKernelF(base.Transpose(), new Point(_center.Y, _center.X)); } } [DebuggerTypeProxy(typeof(DebuggerProxy))] public class DenseHistogram : Mat { internal new class DebuggerProxy { private DenseHistogram _v; public float[] BinValues => _v.GetBinValues(); public DebuggerProxy(DenseHistogram v) { _v = v; } } private int[] _binSizes; private RangeF[] _ranges; public int[] BinDimension => _binSizes; public RangeF[] Ranges => _ranges; public DenseHistogram(int binSize, RangeF range) : this(new int[1] { binSize }, new RangeF[1] { range }) { } public DenseHistogram(int[] binSizes, RangeF[] ranges) { _binSizes = binSizes; _ranges = ranges; } public void Clear() { SetTo(default(MCvScalar)); } public void Calculate(Image[] imgs, bool accumulate, Image mask) where TDepth : new() { Mat[] array = new Mat[imgs.Length]; for (int i = 0; i < imgs.Length; i++) { array[i] = imgs[i].Mat; } Calculate(array, accumulate, mask); } public void Calculate(Matrix[] matrices, bool accumulate, Matrix mask) where TDepth : new() { Mat[] array = new Mat[matrices.Length]; for (int i = 0; i < matrices.Length; i++) { array[i] = matrices[i].Mat; } Calculate(array, accumulate, mask); } private float[] GetRangeAsFloatVec() { float[] array = new float[_ranges.Length * 2]; int num = 0; for (int i = 0; i < _ranges.Length; i++) { array[num++] = _ranges[i].Min; array[num++] = _ranges[i].Max; } return array; } private void Calculate(Mat[] arrays, bool accumulate, CvArray mask) { int[] array = new int[arrays.Length]; for (int i = 0; i < arrays.Length; i++) { array[i] = i; } using VectorOfMat images = new VectorOfMat(arrays); CvInvoke.CalcHist(images, array, mask?.Mat, this, _binSizes, GetRangeAsFloatVec(), accumulate); } public Image BackProject(Image[] srcs) where TDepth : new() { using VectorOfMat vectorOfMat = new VectorOfMat(); vectorOfMat.Push(srcs); int[] array = new int[srcs.Length]; for (int i = 0; i < array.Length; i++) { array[i] = i; } Image image = srcs[0].CopyBlank(); CvInvoke.CalcBackProject(vectorOfMat, array, this, image.Mat, GetRangeAsFloatVec()); return image; } public Matrix BackProject(Matrix[] srcs) where TDepth : new() { using VectorOfMat vectorOfMat = new VectorOfMat(); vectorOfMat.Push(srcs); int[] array = new int[srcs.Length]; for (int i = 0; i < array.Length; i++) { array[i] = i; } Matrix matrix = new Matrix(srcs[0].Size); CvInvoke.CalcBackProject(vectorOfMat, array, this, matrix.Mat, GetRangeAsFloatVec()); return matrix; } public float[] GetBinValues() { if (base.IsEmpty) { return null; } int num = 1; for (int i = 0; i < _binSizes.Length; i++) { num *= _binSizes[i]; } float[] array = new float[num]; CopyTo(array); return array; } } public class IntelligentScissorsMB : UnmanagedObject { public IntelligentScissorsMB() { _ptr = CvInvoke.cveIntelligentScissorsMBCreate(); } public void SetWeights(float weightNonEdge, float weightGradientDirection, float weightGradientMagnitude) { CvInvoke.cveIntelligentScissorsMBSetWeights(_ptr, weightNonEdge, weightGradientDirection, weightGradientMagnitude); } public void SetEdgeFeatureCannyParameters(double threshold1, double threshold2, int apertureSize = 3, bool L2gradient = false) { CvInvoke.cveIntelligentScissorsMBSetEdgeFeatureCannyParameters(_ptr, threshold1, threshold2, apertureSize, L2gradient); } public void ApplyImage(IInputArray image) { using InputArray inputArray = image.GetInputArray(); CvInvoke.cveIntelligentScissorsMBApplyImage(_ptr, inputArray); } public void BuildMap(Point sourcePt) { CvInvoke.cveIntelligentScissorsMBBuildMap(_ptr, ref sourcePt); } public void ApplyImageFeatures(IInputArray nonEdge, IInputArray gradientDirection, IInputArray gradientMagnitude, IInputArray image = null) { using InputArray inputArray = nonEdge.GetInputArray(); using InputArray inputArray2 = gradientDirection.GetInputArray(); using InputArray inputArray3 = gradientMagnitude.GetInputArray(); using InputArray inputArray4 = ((image == null) ? InputArray.GetEmpty() : image.GetInputArray()); CvInvoke.cveIntelligentScissorsMBApplyImageFeatures(_ptr, inputArray, inputArray2, inputArray3, inputArray4); } public void GetContour(Point targetPt, IOutputArray contour, bool backward = false) { using OutputArray outputArray = contour.GetOutputArray(); CvInvoke.cveIntelligentScissorsMBGetContour(_ptr, ref targetPt, outputArray, backward); } protected override void DisposeObject() { if (IntPtr.Zero != _ptr) { CvInvoke.cveIntelligentScissorsMBRelease(ref _ptr); } } public void SetEdgeFeatureZeroCrossingParameters(float value) { CvInvoke.cveIntelligentScissorsMBSetEdgeFeatureZeroCrossingParameters(_ptr, value); } public void SetGradientMagnitudeMaxLimit(float value) { CvInvoke.cveIntelligentScissorsMBSetGradientMagnitudeMaxLimit(_ptr, value); } } public class LineIterator : UnmanagedObject { private Mat _mat; private Type _type; private int _elementLength; private int _byteSize; public IntPtr DataPtr => CvInvoke.cveLineIteratorGetDataPointer(_ptr); public Array Data { get { if (_mat.IsEmpty) { return null; } if (_type == null) { _type = CvInvoke.GetDepthType(_mat.Depth); if (_type == null) { return null; } } if (_byteSize <= 0) { _byteSize = _mat.ElementSize; } if (_elementLength <= 0) { _elementLength = _byteSize / Marshal.SizeOf(_type); } Array array = Array.CreateInstance(_type, _elementLength); GCHandle gCHandle = GCHandle.Alloc(array, GCHandleType.Pinned); CvInvoke.cveMemcpy(gCHandle.AddrOfPinnedObject(), DataPtr, _byteSize); gCHandle.Free(); return array; } set { if (_type == null) { _type = CvInvoke.GetDepthType(_mat.Depth); if (_type == null) { return; } } if (_byteSize <= 0) { _byteSize = _mat.ElementSize; } if (_elementLength <= 0) { _elementLength = _byteSize / Marshal.SizeOf(_type); } if (value.Length != _elementLength) { throw new ArgumentException("Input data size do not match Mat element size"); } if (_type != value.GetValue(0).GetType()) { throw new ArgumentException("Input data type do not match Mat element type"); } GCHandle gCHandle = GCHandle.Alloc(value, GCHandleType.Pinned); CvInvoke.cveMemcpy(DataPtr, gCHandle.AddrOfPinnedObject(), _byteSize); gCHandle.Free(); } } public Point Pos { get { Point pos = default(Point); CvInvoke.cveLineIteratorPos(_ptr, ref pos); return pos; } } public int Count { get { return CvInvoke.cveLineIteratorGetCount(_ptr); } set { CvInvoke.cveLineIteratorSetCount(_ptr, value); } } public LineIterator(Mat img, Point p1, Point p2, int connectivity = 8, bool leftToRight = false) { _mat = img; _ptr = CvInvoke.cveLineIteratorCreate(img, ref p1, ref p2, connectivity, leftToRight); } public void MoveNext() { CvInvoke.cveLineIteratorMoveNext(_ptr); } protected override void DisposeObject() { if (_ptr != IntPtr.Zero) { CvInvoke.cveLineIteratorRelease(ref _ptr); } _mat = null; _type = null; _byteSize = 0; _elementLength = 0; } public static Mat SampleLine(Mat img, Point p1, Point p2, int connectivity = 8, bool leftToRight = false) { Mat mat = new Mat(); CvInvoke.cveLineIteratorSampleLine(img, ref p1, ref p2, connectivity, leftToRight, mat); return mat; } } public class Subdiv2D : UnmanagedObject { private readonly Rectangle _roi; public Subdiv2D(Rectangle roi) { _ptr = CvInvoke.cveSubdiv2DCreate(ref roi); _roi = roi; } public Subdiv2D(PointF[] points, bool silent = false) { _roi = PointCollection.BoundingRectangle(points); _ptr = CvInvoke.cveSubdiv2DCreate(ref _roi); Insert(points, silent); } public void Insert(PointF[] points, bool silent) { using VectorOfPointF vectorOfPointF = new VectorOfPointF(points); if (silent) { IntPtr errorHandler = CvInvoke.RedirectError(CvInvoke.CvErrorHandlerIgnoreError, IntPtr.Zero, IntPtr.Zero); CvInvoke.cveSubdiv2DInsertMulti(_ptr, vectorOfPointF); CvInvoke.RedirectError(errorHandler, IntPtr.Zero, IntPtr.Zero); } else { CvInvoke.cveSubdiv2DInsertMulti(_ptr, vectorOfPointF); } } public void Insert(PointF point) { CvInvoke.cveSubdiv2DInsertSingle(_ptr, ref point); } public Subdiv2DPointLocationType Locate(PointF pt, out int subdiv2DEdge, out int subdiv2DPoint) { subdiv2DEdge = 0; subdiv2DPoint = 0; return CvInvoke.cveSubdiv2DLocate(_ptr, ref pt, ref subdiv2DEdge, ref subdiv2DPoint); } public Subdiv2DPointLocationType FindNearest(PointF point, out PointF nearestPoint) { nearestPoint = default(PointF); return CvInvoke.cveSubdiv2DFindNearest(_ptr, ref point, ref nearestPoint); } public VoronoiFacet[] GetVoronoiFacets(int[] idx = null) { using VectorOfInt vectorOfInt = new VectorOfInt(); using VectorOfVectorOfPointF vectorOfVectorOfPointF = new VectorOfVectorOfPointF(); using VectorOfPointF vectorOfPointF = new VectorOfPointF(); if (idx != null) { vectorOfInt.Push(idx); } CvInvoke.cveSubdiv2DGetVoronoiFacetList(_ptr, vectorOfInt, vectorOfVectorOfPointF, vectorOfPointF); PointF[][] array = vectorOfVectorOfPointF.ToArrayOfArray(); PointF[] array2 = vectorOfPointF.ToArray(); VoronoiFacet[] array3 = new VoronoiFacet[array2.Length]; for (int i = 0; i < array3.Length; i++) { array3[i] = new VoronoiFacet(array2[i], array[i]); } return array3; } public Triangle2DF[] GetDelaunayTriangles(bool includeVirtualPoints = false) { using VectorOfTriangle2DF vectorOfTriangle2DF = new VectorOfTriangle2DF(); CvInvoke.cveSubdiv2DGetTriangleList(_ptr, vectorOfTriangle2DF); Triangle2DF[] array = vectorOfTriangle2DF.ToArray(); if (includeVirtualPoints) { return array; } Rectangle roi = _roi; Point location = roi.Location; roi = _roi; int width = roi.Width + 1; roi = _roi; Rectangle r = new Rectangle(location, new Size(width, roi.Height + 1)); return Array.FindAll(array, (Triangle2DF t) => r.Contains(Point.Round(t.V0)) && r.Contains(Point.Round(t.V1)) && r.Contains(Point.Round(t.V2))); } protected override void DisposeObject() { if (IntPtr.Zero != _ptr) { CvInvoke.cveSubdiv2DRelease(ref _ptr); } } } public class VoronoiFacet { private PointF _point; private PointF[] _vertices; public PointF Point { get { return _point; } set { _point = value; } } public PointF[] Vertices { get { return _vertices; } set { _vertices = value; } } public VoronoiFacet(PointF point, PointF[] polyline) { _point = point; _vertices = polyline; } } public static class Fisheye { public enum CalibrationFlag { Default = 0, UseIntrinsicGuess = 1, RecomputeExtrinsic = 2, CheckCond = 4, FixSkew = 8, FixK1 = 0x10, FixK2 = 0x20, FixK3 = 0x40, FixK4 = 0x80, FixIntrinsic = 0x100 } public static void ProjectPoints(IInputArray objectPoints, IOutputArray imagePoints, IInputArray rvec, IInputArray tvec, IInputArray K, IInputArray D, double alpha = 0.0, IOutputArray jacobian = null) { using InputArray inputArray = objectPoints.GetInputArray(); using OutputArray outputArray = imagePoints.GetOutputArray(); using InputArray inputArray2 = rvec.GetInputArray(); using InputArray inputArray3 = tvec.GetInputArray(); using InputArray inputArray4 = K.GetInputArray(); using InputArray inputArray5 = D.GetInputArray(); using OutputArray outputArray2 = ((jacobian == null) ? OutputArray.GetEmpty() : jacobian.GetOutputArray()); CvInvoke.cveFisheyeProjectPoints(inputArray, outputArray, inputArray2, inputArray3, inputArray4, inputArray5, alpha, outputArray2); } public static void DistortPoints(IInputArray undistored, IOutputArray distorted, IInputArray K, IInputArray D, double alpha = 0.0) { using InputArray inputArray = undistored.GetInputArray(); using OutputArray outputArray = distorted.GetOutputArray(); using InputArray inputArray2 = K.GetInputArray(); using InputArray inputArray3 = D.GetInputArray(); CvInvoke.cveFisheyeDistortPoints(inputArray, outputArray, inputArray2, inputArray3, alpha); } public static void UndistortPoints(IInputArray distorted, IOutputArray undistorted, IInputArray K, IInputArray D, IInputArray R = null, IInputArray P = null) { using InputArray inputArray = distorted.GetInputArray(); using OutputArray outputArray = undistorted.GetOutputArray(); using InputArray inputArray2 = K.GetInputArray(); using InputArray inputArray3 = D.GetInputArray(); using InputArray inputArray4 = ((R == null) ? InputArray.GetEmpty() : R.GetInputArray()); using InputArray inputArray5 = ((P == null) ? InputArray.GetEmpty() : P.GetInputArray()); CvInvoke.cveFisheyeUndistortPoints(inputArray, outputArray, inputArray2, inputArray3, inputArray4, inputArray5); } public static void InitUndistortRectifyMap(IInputArray K, IInputArray D, IInputArray R, IInputArray P, Size size, DepthType depthType, int channels, IOutputArray map1, IOutputArray map2) { using InputArray inputArray = K.GetInputArray(); using InputArray inputArray2 = D.GetInputArray(); using InputArray inputArray3 = R.GetInputArray(); using InputArray inputArray4 = P.GetInputArray(); using OutputArray outputArray = map1.GetOutputArray(); using OutputArray outputArray2 = map2.GetOutputArray(); CvInvoke.cveFisheyeInitUndistortRectifyMap(inputArray, inputArray2, inputArray3, inputArray4, ref size, CvInvoke.MakeType(depthType, channels), outputArray, outputArray2); } public static void UndistortImage(IInputArray distorted, IOutputArray undistored, IInputArray K, IInputArray D, IInputArray Knew = null, Size newSize = default(Size)) { using InputArray inputArray = distorted.GetInputArray(); using OutputArray outputArray = undistored.GetOutputArray(); using InputArray inputArray2 = K.GetInputArray(); using InputArray inputArray3 = D.GetInputArray(); using InputArray inputArray4 = ((Knew == null) ? InputArray.GetEmpty() : Knew.GetInputArray()); CvInvoke.cveFisheyeUndistortImage(inputArray, outputArray, inputArray2, inputArray3, inputArray4, ref newSize); } public static void EstimateNewCameraMatrixForUndistortRectify(IInputArray K, IInputArray D, Size imageSize, IInputArray R, IOutputArray P, double balance = 0.0, Size newSize = default(Size), double fovScale = 1.0) { using InputArray inputArray = K.GetInputArray(); using InputArray inputArray2 = D.GetInputArray(); using InputArray inputArray3 = R.GetInputArray(); using OutputArray outputArray = P.GetOutputArray(); CvInvoke.cveFisheyeEstimateNewCameraMatrixForUndistortRectify(inputArray, inputArray2, ref imageSize, inputArray3, outputArray, balance, ref newSize, fovScale); } public static void StereoRectify(IInputArray K1, IInputArray D1, IInputArray K2, IInputArray D2, Size imageSize, IInputArray R, IInputArray tvec, IOutputArray R1, IOutputArray R2, IOutputArray P1, IOutputArray P2, IOutputArray Q, int flags, Size newImageSize = default(Size), double balance = 0.0, double fovScale = 1.0) { using InputArray inputArray = K1.GetInputArray(); using InputArray inputArray2 = D1.GetInputArray(); using InputArray inputArray3 = K2.GetInputArray(); using InputArray inputArray4 = D2.GetInputArray(); using InputArray inputArray5 = R.GetInputArray(); using InputArray inputArray6 = tvec.GetInputArray(); using OutputArray outputArray = R1.GetOutputArray(); using OutputArray outputArray2 = R2.GetOutputArray(); using OutputArray outputArray3 = P1.GetOutputArray(); using OutputArray outputArray4 = P2.GetOutputArray(); using OutputArray outputArray5 = Q.GetOutputArray(); CvInvoke.cveFisheyeStereoRectify(inputArray, inputArray2, inputArray3, inputArray4, ref imageSize, inputArray5, inputArray6, outputArray, outputArray2, outputArray3, outputArray4, outputArray5, flags, ref newImageSize, balance, fovScale); } public static double Calibrate(IInputArray objectPoints, IInputArray imagePoints, Size imageSize, IInputOutputArray K, IInputOutputArray D, IOutputArray rvecs, IOutputArray tvecs, CalibrationFlag flags, MCvTermCriteria criteria) { using InputArray inputArray = objectPoints.GetInputArray(); using InputArray inputArray2 = imagePoints.GetInputArray(); using InputOutputArray inputOutputArray = K.GetInputOutputArray(); using InputOutputArray inputOutputArray2 = D.GetInputOutputArray(); using OutputArray outputArray = rvecs.GetOutputArray(); using OutputArray outputArray2 = tvecs.GetOutputArray(); return CvInvoke.cveFisheyeCalibrate(inputArray, inputArray2, ref imageSize, inputOutputArray, inputOutputArray2, outputArray, outputArray2, (int)flags, ref criteria); } public static double StereoCalibrate(IInputArray objectPoints, IInputArray imagePoints1, IInputArray imagePoints2, IInputOutputArray K1, IInputOutputArray D1, IInputOutputArray K2, IInputOutputArray D2, Size imageSize, IOutputArray R, IOutputArray T, CalibrationFlag flags, MCvTermCriteria criteria) { using InputArray inputArray = objectPoints.GetInputArray(); using InputArray inputArray2 = imagePoints1.GetInputArray(); using InputArray inputArray3 = imagePoints2.GetInputArray(); using InputOutputArray inputOutputArray = K1.GetInputOutputArray(); using InputOutputArray inputOutputArray2 = D1.GetInputOutputArray(); using InputOutputArray inputOutputArray3 = K2.GetInputOutputArray(); using InputOutputArray inputOutputArray4 = D2.GetInputOutputArray(); using OutputArray outputArray = R.GetOutputArray(); using OutputArray outputArray2 = T.GetOutputArray(); return CvInvoke.cveFisheyeStereoCalibrate(inputArray, inputArray2, inputArray3, inputOutputArray, inputOutputArray2, inputOutputArray3, inputOutputArray4, ref imageSize, outputArray, outputArray2, (int)flags, ref criteria); } } public interface IStereoMatcher { IntPtr StereoMatcherPtr { get; } } public class StereoBM : SharedPtrObject, IStereoMatcher { public IntPtr StereoMatcherPtr => _ptr; public StereoBM(int numberOfDisparities = 0, int blockSize = 21) { _ptr = CvInvoke.cveStereoBMCreate(numberOfDisparities, blockSize, ref _sharedPtr); } protected override void DisposeObject() { if (_sharedPtr != IntPtr.Zero) { CvInvoke.cveStereoMatcherRelease(ref _sharedPtr); _ptr = IntPtr.Zero; } } } public class StereoSGBM : SharedPtrObject, IStereoMatcher { public enum Mode { SGBM, HH } private IntPtr _stereoMatcherPtr; public IntPtr StereoMatcherPtr => _stereoMatcherPtr; public StereoSGBM(int minDisparity, int numDisparities, int blockSize, int p1 = 0, int p2 = 0, int disp12MaxDiff = 0, int preFilterCap = 0, int uniquenessRatio = 0, int speckleWindowSize = 0, int speckleRange = 0, Mode mode = Mode.SGBM) { _ptr = CvInvoke.cveStereoSGBMCreate(minDisparity, numDisparities, blockSize, p1, p2, disp12MaxDiff, preFilterCap, uniquenessRatio, speckleWindowSize, speckleRange, mode, ref _stereoMatcherPtr, ref _sharedPtr); } protected override void DisposeObject() { if (_sharedPtr != IntPtr.Zero) { CvInvoke.cveStereoSGBMRelease(ref _sharedPtr); _ptr = IntPtr.Zero; _stereoMatcherPtr = IntPtr.Zero; } } } public interface IConvexPolygon { Point[] GetVertices(); } public interface IConvexPolygonF { PointF[] GetVertices(); } [Serializable] public struct Quaternions : IEquatable { private double _w; private double _x; private double _y; private double _z; public static readonly Quaternions Empty = new Quaternions(1.0, 0.0, 0.0, 0.0); public double W { get { return _w; } set { _w = value; } } public double X { get { return _x; } set { _x = value; } } public double Y { get { return _y; } set { _y = value; } } public double Z { get { return _z; } set { _z = value; } } public MCvPoint3D64f AxisAngle { get { MCvPoint3D64f axisAngle = default(MCvPoint3D64f); CvInvoke.quaternionsToAxisAngle(ref this, ref axisAngle); return axisAngle; } set { CvInvoke.axisAngleToQuaternions(ref value, ref this); } } public MCvPoint3D64f RotationAxis { get { if (Equals(Empty)) { return new MCvPoint3D64f(0.0, 0.0, 1.0); } double num = Math.Sqrt(X * X + Y * Y + Z * Z); return new MCvPoint3D64f(X / num, Y / num, Z / num); } } public double RotationAngle => 2.0 * Math.Acos(W); public Quaternions(double w, double x, double y, double z) { _w = w; _x = x; _y = y; _z = z; } public void SetEuler(double x, double y, double z) { CvInvoke.eulerToQuaternions(x, y, z, ref this); } public void GetEuler(ref double x, ref double y, ref double z) { CvInvoke.quaternionsToEuler(ref this, ref x, ref y, ref z); } public void GetRotationMatrix(Matrix rotation) { CvInvoke.quaternionsToRotationMatrix(ref this, rotation); } public void RotatePoints(Matrix pointsSrc, Matrix pointsDst) { CvInvoke.quaternionsRotatePoints(ref this, pointsSrc, pointsDst); } public MCvPoint3D64f RotatePoint(MCvPoint3D64f point) { MCvPoint3D64f pointDst = default(MCvPoint3D64f); CvInvoke.quaternionsRotatePoint(ref this, ref point, ref pointDst); return pointDst; } public Quaternions Multiply(Quaternions quaternionsOther) { Quaternions quaternionsDst = default(Quaternions); CvInvoke.quaternionsMultiply(ref this, ref quaternionsOther, ref quaternionsDst); return quaternionsDst; } public Quaternions Slerp(Quaternions quaternionsOther, double weightForOther) { Quaternions qm = default(Quaternions); CvInvoke.quaternionsSlerp(ref this, ref quaternionsOther, weightForOther, ref qm); return qm; } public static Quaternions operator *(Quaternions q1, Quaternions q2) { return q1.Multiply(q2); } public void Conjugate() { X = 0.0 - X; Y = 0.0 - Y; Z = 0.0 - Z; } public bool Equals(Quaternions other) { if (Math.Abs(W - other.W) < double.Epsilon && Math.Abs(X - other.X) < double.Epsilon && Math.Abs(Y - other.Y) < double.Epsilon) { return Math.Abs(Z - other.Z) < double.Epsilon; } return false; } public override string ToString() { return $"[{W}, {X}, {Y}, {Z}]"; } } [Serializable] public class RotationMatrix2D : Mat { public RotationMatrix2D() { } public RotationMatrix2D(PointF center, double angle, double scale) : this() { SetRotation(center, angle, scale); } public void SetRotation(PointF center, double angle, double scale) { CvInvoke.GetRotationMatrix2D(center, angle, scale, this); } public void RotatePoints(MCvPoint2D64f[] points) { GCHandle gCHandle = GCHandle.Alloc(points, GCHandleType.Pinned); using (Matrix points2 = new Matrix(points.Length, 2, gCHandle.AddrOfPinnedObject())) { RotatePoints(points2); } gCHandle.Free(); } public void RotatePoints(PointF[] points) { GCHandle gCHandle = GCHandle.Alloc(points, GCHandleType.Pinned); using (Matrix points2 = new Matrix(points.Length, 2, gCHandle.AddrOfPinnedObject())) { RotatePoints(points2); } gCHandle.Free(); } public void RotateLines(LineSegment2DF[] lineSegments) { GCHandle gCHandle = GCHandle.Alloc(lineSegments, GCHandleType.Pinned); using (Matrix points = new Matrix(lineSegments.Length * 2, 2, gCHandle.AddrOfPinnedObject())) { RotatePoints(points); } gCHandle.Free(); } public void RotatePoints(Matrix points) where TDepth : new() { CvInvoke.GetDepthType(typeof(TDepth)); using Mat mat = new Mat(points.Rows, 3, CvInvoke.GetDepthType(typeof(TDepth)), 1); using Mat mat2 = new Mat(base.Rows, base.Cols, CvInvoke.GetDepthType(typeof(TDepth)), 1); CvInvoke.CopyMakeBorder(points, mat, 0, 0, 0, 1, BorderType.Constant, new MCvScalar(1.0)); if (typeof(double).Equals(typeof(TDepth))) { CopyTo(mat2); } else { ConvertTo(mat2, CvInvoke.GetDepthType(typeof(TDepth))); } CvInvoke.Gemm(mat, mat2, 1.0, null, 0.0, points, GemmType.Src2Transpose); } public new RotationMatrix2D Clone() { RotationMatrix2D rotationMatrix2D = new RotationMatrix2D(); CopyTo(rotationMatrix2D); return rotationMatrix2D; } public static RotationMatrix2D CreateRotationMatrix(PointF center, double angle, Size srcImageSize, out Size dstImageSize) { RotationMatrix2D rotationMatrix2D = new RotationMatrix2D(center, angle, 1.0); PointF[] array = new PointF[4] { new PointF(0f, 0f), new PointF(srcImageSize.Width - 1, 0f), new PointF(srcImageSize.Width - 1, srcImageSize.Height - 1), new PointF(0f, srcImageSize.Height - 1) }; rotationMatrix2D.RotatePoints(array); int num = (int)Math.Round(Math.Min(Math.Min(array[0].X, array[1].X), Math.Min(array[2].X, array[3].X))); int num2 = (int)Math.Round(Math.Max(Math.Max(array[0].X, array[1].X), Math.Max(array[2].X, array[3].X))); int num3 = (int)Math.Round(Math.Min(Math.Min(array[0].Y, array[1].Y), Math.Min(array[2].Y, array[3].Y))); int num4 = (int)Math.Round(Math.Max(Math.Max(array[0].Y, array[1].Y), Math.Max(array[2].Y, array[3].Y))); using (Matrix matrix = new Matrix(2, 3)) { matrix[0, 2] = num; matrix[1, 2] = num3; CvInvoke.Subtract(rotationMatrix2D, matrix, rotationMatrix2D); } dstImageSize = new Size(num2 - num + 1, num4 - num3 + 1); return rotationMatrix2D; } } [Serializable] public class RotationVector3D : Matrix { [XmlIgnore] public Mat RotationMatrix { get { Mat mat = new Mat(); CvInvoke.Rodrigues(this, mat); return mat; } set { CvInvoke.Rodrigues(value, this); } } public RotationVector3D(SerializationInfo info, StreamingContext context) : base(info, context) { } public RotationVector3D() : base(3, 1) { } public RotationVector3D(double[] value) : this() { Buffer.BlockCopy(value, 0, base.Data, 0, 24); } } public static class GapiInvoke { static GapiInvoke() { CvInvoke.Init(); } public static GMat Resize(GMat src, Size dsize, double fx = 0.0, double fy = 0.0, Inter interpolation = Inter.Linear) { return new GMat(cveGapiResize(src, ref dsize, fx, fy, interpolation), needDispose: true); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern IntPtr cveGapiResize(IntPtr src, ref Size dsize, double fx, double fy, Inter interpolation); public static GMat BitwiseNot(GMat src) { return new GMat(cveGapiBitwiseNot(src), needDispose: true); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern IntPtr cveGapiBitwiseNot(IntPtr src); public static GMat Add(GMat src1, GMat src2, DepthType ddepth = DepthType.Default) { return new GMat(cveGapiAdd(src1, src2, ddepth), needDispose: true); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern IntPtr cveGapiAdd(IntPtr src1, IntPtr src2, DepthType ddepth); public static GMat AddC(GMat src1, GScalar c, DepthType ddepth) { return new GMat(cveGapiAddC(src1, c, ddepth), needDispose: true); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern IntPtr cveGapiAddC(IntPtr src1, IntPtr c, DepthType ddepth); public static GMat Sub(GMat src1, GMat src2, DepthType ddepth = DepthType.Default) { return new GMat(cveGapiSub(src1, src2, ddepth), needDispose: true); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern IntPtr cveGapiSub(IntPtr src1, IntPtr src2, DepthType ddepth); public static GMat SubC(GMat src, GScalar c, DepthType ddepth = DepthType.Default) { return new GMat(cveGapiSubC(src, c, ddepth), needDispose: true); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern IntPtr cveGapiSubC(IntPtr src1, IntPtr c, DepthType ddepth); public static GMat SubRC(GScalar c, GMat src, DepthType ddepth = DepthType.Default) { return new GMat(cveGapiSubRC(c, src, ddepth), needDispose: true); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern IntPtr cveGapiSubRC(IntPtr c, IntPtr src1, DepthType ddepth); public static GMat Mul(GMat src1, GMat src2, double scale, DepthType ddepth) { return new GMat(cveGapiMul(src1, src2, scale, ddepth), needDispose: true); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern IntPtr cveGapiMul(IntPtr src1, IntPtr src2, double scale, DepthType ddepth); public static GMat MulC(GMat src1, GScalar c, DepthType ddepth = DepthType.Default) { return new GMat(cveGapiMulC(src1, c, ddepth), needDispose: true); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern IntPtr cveGapiMulC(IntPtr src, IntPtr scale, DepthType ddepth); public static GMat Div(GMat src1, GMat src2, double scale, DepthType ddepth = DepthType.Default) { return new GMat(cveGapiDiv(src1, src2, scale, ddepth), needDispose: true); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern IntPtr cveGapiDiv(IntPtr src1, IntPtr src2, double scale, DepthType ddepth); public static GMat DivC(GMat src1, GScalar divisor, double scale, DepthType ddepth = DepthType.Default) { return new GMat(cveGapiDivC(src1, divisor, scale, ddepth), needDispose: true); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern IntPtr cveGapiDivC(IntPtr src, IntPtr divisor, double scale, DepthType ddepth); public static GMat DivRC(GScalar divisor, GMat src, double scale, DepthType ddepth = DepthType.Default) { return new GMat(cveGapiDivRC(divisor, src, scale, ddepth), needDispose: true); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern IntPtr cveGapiDivRC(IntPtr divident, IntPtr src, double scale, DepthType ddepth); public static GScalar Mean(GMat src) { return new GScalar(cveGapiMean(src)); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern IntPtr cveGapiMean(IntPtr src); public static Tuple PolarToCart(GMat magnitude, GMat angle, bool angleInDegrees = false) { GMat gMat = new GMat(); GMat gMat2 = new GMat(); cveGapiPolarToCart(magnitude, angle, angleInDegrees, gMat, gMat2); return new Tuple(gMat, gMat2); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveGapiPolarToCart(IntPtr magnitude, IntPtr angle, [MarshalAs(UnmanagedType.U1)] bool angleInDegrees, IntPtr outX, IntPtr outY); public static Tuple CartToPolar(GMat x, GMat y, bool angleInDegrees = false) { GMat gMat = new GMat(); GMat gMat2 = new GMat(); cveGapiCartToPolar(x, y, angleInDegrees, gMat, gMat2); return new Tuple(gMat, gMat2); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveGapiCartToPolar(IntPtr x, IntPtr y, [MarshalAs(UnmanagedType.U1)] bool angleInDegrees, IntPtr outMagnitude, IntPtr outAngle); public static GMat Phase(GMat x, GMat y, bool angleInDegrees) { return new GMat(cveGapiPhase(x, y, angleInDegrees), needDispose: true); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern IntPtr cveGapiPhase(IntPtr x, IntPtr y, [MarshalAs(UnmanagedType.U1)] bool angleInDegrees); public static GMat Sqrt(GMat src) { return new GMat(cveGapiSqrt(src), needDispose: true); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern IntPtr cveGapiSqrt(IntPtr src); public static GMat CmpGT(GMat src1, GMat src2) { return new GMat(cveGapiCmpGT(src1, src2), needDispose: true); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern IntPtr cveGapiCmpGT(IntPtr src1, IntPtr src2); public static GMat CmpGT(GMat src1, GScalar src2) { return new GMat(cveGapiCmpGTS(src1, src2), needDispose: true); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern IntPtr cveGapiCmpGTS(IntPtr src1, IntPtr src2); public static GMat CmpLT(GMat src1, GMat src2) { return new GMat(cveGapiCmpLT(src1, src2), needDispose: true); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern IntPtr cveGapiCmpLT(IntPtr src1, IntPtr src2); public static GMat CmpLT(GMat src1, GScalar src2) { return new GMat(cveGapiCmpLTS(src1, src2), needDispose: true); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern IntPtr cveGapiCmpLTS(IntPtr src1, IntPtr src2); public static GMat CmpGE(GMat src1, GMat src2) { return new GMat(cveGapiCmpGE(src1, src2), needDispose: true); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern IntPtr cveGapiCmpGE(IntPtr src1, IntPtr src2); public static GMat CmpGE(GMat src1, GScalar src2) { return new GMat(cveGapiCmpGES(src1, src2), needDispose: true); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern IntPtr cveGapiCmpGES(IntPtr src1, IntPtr src2); public static GMat CmpLE(GMat src1, GMat src2) { return new GMat(cveGapiCmpLE(src1, src2), needDispose: true); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern IntPtr cveGapiCmpLE(IntPtr src1, IntPtr src2); public static GMat CmpLE(GMat src1, GScalar src2) { return new GMat(cveGapiCmpLES(src1, src2), needDispose: true); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern IntPtr cveGapiCmpLES(IntPtr src1, IntPtr src2); public static GMat CmpEQ(GMat src1, GMat src2) { return new GMat(cveGapiCmpEQ(src1, src2), needDispose: true); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern IntPtr cveGapiCmpEQ(IntPtr src1, IntPtr src2); public static GMat CmpEQ(GMat src1, GScalar src2) { return new GMat(cveGapiCmpEQS(src1, src2), needDispose: true); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern IntPtr cveGapiCmpEQS(IntPtr src1, IntPtr src2); public static GMat CmpNE(GMat src1, GMat src2) { return new GMat(cveGapiCmpNE(src1, src2), needDispose: true); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern IntPtr cveGapiCmpNE(IntPtr src1, IntPtr src2); public static GMat CmpNE(GMat src1, GScalar src2) { return new GMat(cveGapiCmpNES(src1, src2), needDispose: true); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern IntPtr cveGapiCmpNES(IntPtr src1, IntPtr src2); public static GMat BitwiseAnd(GMat src1, GMat src2) { return new GMat(cveGapiBitwiseAnd(src1, src2), needDispose: true); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern IntPtr cveGapiBitwiseAnd(IntPtr src1, IntPtr src2); public static GMat BitwiseAnd(GMat src1, GScalar src2) { return new GMat(cveGapiBitwiseAndS(src1, src2), needDispose: true); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern IntPtr cveGapiBitwiseAndS(IntPtr src1, IntPtr src2); public static GMat BitwiseOr(GMat src1, GMat src2) { return new GMat(cveGapiBitwiseOr(src1, src2), needDispose: true); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern IntPtr cveGapiBitwiseOr(IntPtr src1, IntPtr src2); public static GMat BitwiseOr(GMat src1, GScalar src2) { return new GMat(cveGapiBitwiseOrS(src1, src2), needDispose: true); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern IntPtr cveGapiBitwiseOrS(IntPtr src1, IntPtr src2); public static GMat BitwiseXor(GMat src1, GMat src2) { return new GMat(cveGapiBitwiseXor(src1, src2), needDispose: true); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern IntPtr cveGapiBitwiseXor(IntPtr src1, IntPtr src2); public static GMat BitwiseXor(GMat src1, GScalar src2) { return new GMat(cveGapiBitwiseXorS(src1, src2), needDispose: true); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern IntPtr cveGapiBitwiseXorS(IntPtr src1, IntPtr src2); public static GMat Mask(GMat src, GMat mask) { return new GMat(cveGapiMask(src, mask), needDispose: true); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern IntPtr cveGapiMask(IntPtr src, IntPtr mask); public static GMat SepFilter(GMat src, DepthType ddepth, Mat kernelX, Mat kernelY, Point anchor, MCvScalar delta, BorderType borderType = BorderType.Reflect101, MCvScalar borderValue = default(MCvScalar)) { return new GMat(cveGapiSepFilter(src, ddepth, kernelX, kernelY, ref anchor, ref delta, borderType, ref borderValue), needDispose: true); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern IntPtr cveGapiSepFilter(IntPtr src, DepthType ddepth, IntPtr kernelX, IntPtr kernelY, ref Point anchor, ref MCvScalar delta, BorderType borderType, ref MCvScalar borderValue); public static GMat Filter2D(GMat src, DepthType ddepth, Mat kernel, Point anchor, MCvScalar delta = default(MCvScalar), BorderType borderType = BorderType.Reflect101, MCvScalar borderValue = default(MCvScalar)) { return new GMat(cveGapiFilter2D(src, ddepth, kernel, ref anchor, ref delta, borderType, ref borderValue), needDispose: true); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern IntPtr cveGapiFilter2D(IntPtr src, DepthType ddepth, IntPtr kernel, ref Point anchor, ref MCvScalar delta, BorderType borderType, ref MCvScalar borderValue); public static GMat BoxFilter(GMat src, DepthType dtype, Size ksize, Point anchor, bool normalize = true, BorderType borderType = BorderType.Reflect101, MCvScalar borderValue = default(MCvScalar)) { return new GMat(cveGapiBoxFilter(src, dtype, ref ksize, ref anchor, normalize, borderType, ref borderValue), needDispose: true); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern IntPtr cveGapiBoxFilter(IntPtr src, DepthType dtype, ref Size ksize, ref Point anchor, [MarshalAs(UnmanagedType.U1)] bool normalize, BorderType borderType, ref MCvScalar borderValue); public static GMat Blur(GMat src, Size ksize, Point anchor, BorderType borderType = BorderType.Reflect101, MCvScalar borderValue = default(MCvScalar)) { return new GMat(cveGapiBlur(src, ref ksize, ref anchor, borderType, ref borderValue), needDispose: true); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern IntPtr cveGapiBlur(IntPtr src, ref Size ksize, ref Point anchor, BorderType borderType, ref MCvScalar borderValue); public static GMat GaussianBlur(GMat src, Size kSize, double sigmaX, double sigmaY = 0.0, BorderType borderType = BorderType.Reflect101, MCvScalar borderValue = default(MCvScalar)) { return new GMat(cveGapiGaussianBlur(src, ref kSize, sigmaX, sigmaY, borderType, ref borderValue), needDispose: true); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern IntPtr cveGapiGaussianBlur(IntPtr src, ref Size kSize, double sigmaX, double sigmaY, BorderType borderType, ref MCvScalar borderValue); public static GMat MedianBlur(GMat src, int kSize) { return new GMat(cveGapiMedianBlur(src, kSize), needDispose: true); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern IntPtr cveGapiMedianBlur(IntPtr src, int kSize); public static GMat Erode(GMat src, Mat kernel, Point anchor, int iterations = 1, BorderType borderType = BorderType.Constant, MCvScalar borderValue = default(MCvScalar)) { return new GMat(cveGapiErode(src, kernel, ref anchor, iterations, borderType, ref borderValue), needDispose: true); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern IntPtr cveGapiErode(IntPtr src, IntPtr kernel, ref Point anchor, int iterations, BorderType borderType, ref MCvScalar borderValue); public static GMat Erode3x3(GMat src, int iterations = 1, BorderType borderType = BorderType.Constant, MCvScalar borderValue = default(MCvScalar)) { return new GMat(cveGapiErode3x3(src, iterations, borderType, ref borderValue), needDispose: true); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern IntPtr cveGapiErode3x3(IntPtr src, int iterations, BorderType borderType, ref MCvScalar borderValue); public static GMat Dilate(GMat src, Mat kernel, Point anchor, int iterations = 1, BorderType borderType = BorderType.Constant, MCvScalar borderValue = default(MCvScalar)) { return new GMat(cveGapiDilate(src, kernel, ref anchor, iterations, borderType, ref borderValue), needDispose: true); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern IntPtr cveGapiDilate(IntPtr src, IntPtr kernel, ref Point anchor, int iterations, BorderType borderType, ref MCvScalar borderValue); public static GMat Dilate3x3(GMat src, int iterations = 1, BorderType borderType = BorderType.Constant, MCvScalar borderValue = default(MCvScalar)) { return new GMat(cveGapiDilate3x3(src, iterations, borderType, ref borderValue), needDispose: true); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern IntPtr cveGapiDilate3x3(IntPtr src, int iterations, BorderType borderType, ref MCvScalar borderValue); public static GMat MorphologyEx(GMat src, MorphOp op, Mat kernel, Point anchor, int iterations = 1, BorderType borderType = BorderType.Constant, MCvScalar borderValue = default(MCvScalar)) { return new GMat(cveGapiMorphologyEx(src, op, kernel, ref anchor, iterations, borderType, ref borderValue), needDispose: true); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern IntPtr cveGapiMorphologyEx(IntPtr src, MorphOp op, IntPtr kernel, ref Point anchor, int iterations, BorderType borderType, ref MCvScalar borderValue); public static GMat Sobel(GMat src, DepthType ddepth, int dx, int dy, int ksize = 3, double scale = 1.0, double delta = 0.0, BorderType borderType = BorderType.Reflect101, MCvScalar borderValue = default(MCvScalar)) { return new GMat(cveGapiSobel(src, ddepth, dx, dy, ksize, scale, delta, borderType, ref borderValue), needDispose: true); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern IntPtr cveGapiSobel(IntPtr src, DepthType ddepth, int dx, int dy, int ksize, double scale, double delta, BorderType borderType, ref MCvScalar borderValue); public static Tuple SobelXY(GMat src, DepthType ddepth, int order, int ksize = 3, double scale = 1.0, double delta = 0.0, BorderType borderType = BorderType.Reflect101, MCvScalar borderValue = default(MCvScalar)) { GMat gMat = new GMat(); GMat gMat2 = new GMat(); cveGapiSobelXY(src, ddepth, order, ksize, scale, delta, borderType, ref borderValue, gMat, gMat2); return new Tuple(gMat, gMat2); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveGapiSobelXY(IntPtr src, DepthType ddepth, int order, int ksize, double scale, double delta, BorderType borderType, ref MCvScalar borderValue, IntPtr sobelX, IntPtr sobelY); public static GMat Laplacian(GMat src, DepthType ddepth, int ksize = 1, double scale = 1.0, double delta = 0.0, BorderType borderType = BorderType.Reflect101) { return new GMat(cveGapiLaplacian(src, ddepth, ksize, scale, delta, borderType), needDispose: true); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern IntPtr cveGapiLaplacian(IntPtr src, DepthType ddepth, int ksize, double scale, double delta, BorderType borderType); public static GMat BilateralFilter(GMat src, int d, double sigmaColor, double sigmaSpace, BorderType borderType = BorderType.Reflect101) { return new GMat(cveGapiBilateralFilter(src, d, sigmaColor, sigmaColor, borderType), needDispose: true); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern IntPtr cveGapiBilateralFilter(IntPtr src, int d, double sigmaColor, double sigmaSpace, BorderType borderType); public static GMat Canny(GMat image, double threshold1, double threshold2, int apertureSize, bool L2gradient) { return new GMat(cveGapiCanny(image, threshold1, threshold2, apertureSize, L2gradient), needDispose: true); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern IntPtr cveGapiCanny(IntPtr image, double threshold1, double threshold2, int apertureSize, [MarshalAs(UnmanagedType.U1)] bool L2gradient); public static GMat EqualizeHist(GMat src) { return new GMat(cveGapiEqualizeHist(src), needDispose: true); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern IntPtr cveGapiEqualizeHist(IntPtr src); public static GMat BGR2RGB(GMat src) { return new GMat(cveGapiBGR2RGB(src), needDispose: true); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern IntPtr cveGapiBGR2RGB(IntPtr src); public static GMat RGB2Gray(GMat src) { return new GMat(cveGapiRGB2Gray1(src), needDispose: true); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern IntPtr cveGapiRGB2Gray1(IntPtr src); public static GMat RGB2Gray(GMat src, float rY, float gY, float bY) { return new GMat(cveGapiRGB2Gray2(src, rY, gY, bY), needDispose: true); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern IntPtr cveGapiRGB2Gray2(IntPtr src, float rY, float gY, float bY); public static GMat BGR2Gray(GMat src) { return new GMat(cveGapiBGR2Gray(src), needDispose: true); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern IntPtr cveGapiBGR2Gray(IntPtr src); public static GMat RGB2YUV(GMat src) { return new GMat(cveGapiRGB2YUV(src), needDispose: true); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern IntPtr cveGapiRGB2YUV(IntPtr src); public static GMat BGR2I420(GMat src) { return new GMat(cveGapiBGR2I420(src), needDispose: true); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern IntPtr cveGapiBGR2I420(IntPtr src); public static GMat RGB2I420(GMat src) { return new GMat(cveGapiRGB2I420(src), needDispose: true); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern IntPtr cveGapiRGB2I420(IntPtr src); public static GMat I4202BGR(GMat src) { return new GMat(cveGapiI4202BGR(src), needDispose: true); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern IntPtr cveGapiI4202BGR(IntPtr src); public static GMat I4202RGB(GMat src) { return new GMat(cveGapiI4202RGB(src), needDispose: true); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern IntPtr cveGapiI4202RGB(IntPtr src); public static GMat BGR2LUV(GMat src) { return new GMat(cveGapiBGR2LUV(src), needDispose: true); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern IntPtr cveGapiBGR2LUV(IntPtr src); public static GMat LUV2BGR(GMat src) { return new GMat(cveGapiLUV2BGR(src), needDispose: true); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern IntPtr cveGapiLUV2BGR(IntPtr src); public static GMat YUV2BGR(GMat src) { return new GMat(cveGapiYUV2BGR(src), needDispose: true); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern IntPtr cveGapiYUV2BGR(IntPtr src); public static GMat BGR2YUV(GMat src) { return new GMat(cveGapiBGR2YUV(src), needDispose: true); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern IntPtr cveGapiBGR2YUV(IntPtr src); public static GMat RGB2Lab(GMat src) { return new GMat(cveGapiRGB2Lab(src), needDispose: true); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern IntPtr cveGapiRGB2Lab(IntPtr src); public static GMat YUV2RGB(GMat src) { return new GMat(cveGapiYUV2RGB(src), needDispose: true); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern IntPtr cveGapiYUV2RGB(IntPtr src); public static GMat NV12toRGB(GMat srcY, GMat srcUV) { return new GMat(cveGapiNV12toRGB(srcY, srcUV), needDispose: true); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern IntPtr cveGapiNV12toRGB(IntPtr srcY, IntPtr srcUV); public static GMat NV12toGray(GMat srcY, GMat srcUV) { return new GMat(cveGapiNV12toGray(srcY, srcUV), needDispose: true); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern IntPtr cveGapiNV12toGray(IntPtr srcY, IntPtr srcUV); public static GMat NV12toBGR(GMat srcY, GMat srcUV) { return new GMat(cveGapiNV12toBGR(srcY, srcUV), needDispose: true); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern IntPtr cveGapiNV12toBGR(IntPtr srcY, IntPtr srcUV); public static GMat BayerGR2RGB(GMat src) { return new GMat(cveGapiBayerGR2RGB(src), needDispose: true); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern IntPtr cveGapiBayerGR2RGB(IntPtr srcGR); public static GMat RGB2HSV(GMat src) { return new GMat(cveGapiRGB2HSV(src), needDispose: true); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern IntPtr cveGapiRGB2HSV(IntPtr src); public static GMat RGB2YUV422(GMat src) { return new GMat(cveGapiRGB2YUV422(src), needDispose: true); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern IntPtr cveGapiRGB2YUV422(IntPtr src); public static GMat Select(GMat src1, GMat src2, GMat mask) { return new GMat(cveGapiSelect(src1, src2, mask), needDispose: true); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern IntPtr cveGapiSelect(IntPtr src1, IntPtr src2, IntPtr mask); public static GMat Min(GMat src1, GMat src2) { return new GMat(cveGapiMin(src1, src2), needDispose: true); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern IntPtr cveGapiMin(IntPtr src1, IntPtr src2); public static GMat Max(GMat src1, GMat src2) { return new GMat(cveGapiMax(src1, src2), needDispose: true); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern IntPtr cveGapiMax(IntPtr src1, IntPtr src2); public static GMat AbsDiff(GMat src1, GMat src2) { return new GMat(cveGapiAbsDiff(src1, src2), needDispose: true); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern IntPtr cveGapiAbsDiff(IntPtr src1, IntPtr src2); public static GMat AbsDiffC(GMat src, GScalar c) { return new GMat(cveGapiAbsDiffC(src, c), needDispose: true); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern IntPtr cveGapiAbsDiffC(IntPtr src, IntPtr c); public static GScalar Sum(GMat src) { return new GScalar(cveGapiSum(src)); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern IntPtr cveGapiSum(IntPtr src); public static GMat AddWeighted(GMat src1, double alpha, GMat src2, double beta, double gamma, DepthType ddepth) { return new GMat(cveGapiAddWeighted(src1, alpha, src2, beta, gamma, ddepth), needDispose: true); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern IntPtr cveGapiAddWeighted(IntPtr src1, double alpha, IntPtr src2, double beta, double gamma, DepthType ddepth); public static GScalar NormL1(GMat src) { return new GScalar(cveGapiNormL1(src)); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern IntPtr cveGapiNormL1(IntPtr src); public static GScalar NormL2(GMat src) { return new GScalar(cveGapiNormL2(src)); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern IntPtr cveGapiNormL2(IntPtr src); public static GScalar NormInf(GMat src) { return new GScalar(cveGapiNormInf(src)); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern IntPtr cveGapiNormInf(IntPtr src); public static Tuple Integral(GMat src, DepthType sdepth = DepthType.Default, DepthType sqdepth = DepthType.Default) { GMat gMat = new GMat(); GMat gMat2 = new GMat(); cveGapiIntegral(src, sdepth, sqdepth, gMat, gMat2); return new Tuple(gMat, gMat2); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveGapiIntegral(IntPtr src, DepthType sdepth, DepthType sqdepth, IntPtr dst1, IntPtr dst2); public static GMat Threshold(GMat src, GScalar thresh, GScalar maxval, ThresholdType type) { return new GMat(cveGapiThreshold(src, thresh, maxval, type), needDispose: true); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern IntPtr cveGapiThreshold(IntPtr src, IntPtr thresh, IntPtr maxval, ThresholdType type); public static GMat InRange(GMat src, GScalar threshLow, GScalar threshUp) { return new GMat(cveGapiInRange(src, threshLow, threshUp), needDispose: true); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern IntPtr cveGapiInRange(IntPtr src, IntPtr threshLow, IntPtr threshUp); public static GMat Merge4(GMat src1, GMat src2, GMat src3, GMat src4) { return new GMat(cveGapiMerge4(src1, src2, src3, src4), needDispose: true); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern IntPtr cveGapiMerge4(IntPtr src1, IntPtr src2, IntPtr src3, IntPtr src4); public static GMat Merge3(GMat src1, GMat src2, GMat src3) { return new GMat(cveGapiMerge3(src1, src2, src3), needDispose: true); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern IntPtr cveGapiMerge3(IntPtr src1, IntPtr src2, IntPtr src3); public static Tuple Split4(GMat src) { GMat gMat = new GMat(); GMat gMat2 = new GMat(); GMat gMat3 = new GMat(); GMat gMat4 = new GMat(); cveGapiSplit4(src, gMat, gMat2, gMat3, gMat4); return new Tuple(gMat, gMat2, gMat3, gMat4); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveGapiSplit4(IntPtr src, IntPtr dst1, IntPtr dst2, IntPtr dst3, IntPtr dst4); public static Tuple Split3(GMat src) { GMat gMat = new GMat(); GMat gMat2 = new GMat(); GMat gMat3 = new GMat(); cveGapiSplit3(src, gMat, gMat2, gMat3); return new Tuple(gMat, gMat2, gMat3); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveGapiSplit3(IntPtr src, IntPtr dst1, IntPtr dst2, IntPtr dst3); public static GMat Remap(GMat src, Mat map1, Mat map2, Inter interpolation, BorderType borderMode = BorderType.Constant, MCvScalar borderValue = default(MCvScalar)) { return new GMat(cveGapiRemap(src, map1, map2, interpolation, borderMode, ref borderValue), needDispose: true); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern IntPtr cveGapiRemap(IntPtr src, IntPtr map1, IntPtr map2, Inter interpolation, BorderType borderMode, ref MCvScalar borderValue); public static GMat Flip(GMat src, FlipType flipCode) { return new GMat(cveGapiFlip(src, flipCode), needDispose: true); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern IntPtr cveGapiFlip(IntPtr src, FlipType flipCode); public static GMat Crop(GMat src, Rectangle rect) { return new GMat(cveGapiCrop(src, ref rect), needDispose: true); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern IntPtr cveGapiCrop(IntPtr src, ref Rectangle rect); public static GMat ConcatHor(GMat src1, GMat src2) { return new GMat(cveGapiConcatHor(src1, src2), needDispose: true); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern IntPtr cveGapiConcatHor(IntPtr src1, IntPtr src2); public static GMat ConcatHor(VectorOfGMat v) { return new GMat(cveGapiConcatHorV(v), needDispose: true); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern IntPtr cveGapiConcatHorV(IntPtr v); public static GMat ConcatVert(GMat src1, GMat src2) { return new GMat(cveGapiConcatVert(src1, src2), needDispose: true); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern IntPtr cveGapiConcatVert(IntPtr src1, IntPtr src2); public static GMat ConcatVert(VectorOfGMat v) { return new GMat(cveGapiConcatVertV(v), needDispose: true); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern IntPtr cveGapiConcatVertV(IntPtr v); public static GMat LUT(GMat src, Mat lut) { return new GMat(cveGapiLUT(src, lut), needDispose: true); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern IntPtr cveGapiLUT(IntPtr src, IntPtr lut); public static GMat ConvertTo(GMat src, DepthType rdepth, double alpha = 1.0, double beta = 0.0) { return new GMat(cveGapiConvertTo(src, rdepth, alpha, beta), needDispose: true); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern IntPtr cveGapiConvertTo(IntPtr src, DepthType rdepth, double alpha, double beta); public static GMat Normalize(GMat src, double alpha, double beta, NormType normType = NormType.L2, DepthType dType = DepthType.Default) { return new GMat(cveGapiNormalize(src, alpha, beta, normType, dType), needDispose: true); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern IntPtr cveGapiNormalize(IntPtr src, double alpha, double beta, NormType normType, DepthType ddepth); public static GMat WarpPerspective(GMat src, Mat m, Size dsize, Inter interMethod = Inter.Linear, Warp warpMethod = Warp.Default, BorderType borderMode = BorderType.Constant, MCvScalar borderValue = default(MCvScalar)) { return new GMat(cveGapiWarpPerspective(src, m, ref dsize, (int)interMethod | (int)warpMethod, borderMode, ref borderValue), needDispose: true); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern IntPtr cveGapiWarpPerspective(IntPtr src, IntPtr m, ref Size dsize, int flags, BorderType borderMode, ref MCvScalar borderValue); public static GMat WarpAffine(GMat src, Mat m, Size dsize, Inter interMethod = Inter.Linear, Warp warpMethod = Warp.Default, BorderType borderMode = BorderType.Constant, MCvScalar borderValue = default(MCvScalar)) { return new GMat(cveGapiWarpAffine(src, m, ref dsize, (int)interMethod | (int)warpMethod, borderMode, ref borderValue), needDispose: true); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern IntPtr cveGapiWarpAffine(IntPtr src, IntPtr m, ref Size dsize, int flags, BorderType borderMode, ref MCvScalar borderValue); public static GMat Transpose(GMat src) { return new GMat(cveGapiTranspose(src), needDispose: true); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern IntPtr cveGapiTranspose(IntPtr src); public static GMat Stereo(GMat left, GMat right, StereoOutputFormat of) { return new GMat(cveGapiStereo(left, right, of), needDispose: true); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern IntPtr cveGapiStereo(IntPtr left, IntPtr right, StereoOutputFormat of); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveGComputationCreate1(IntPtr input, IntPtr output); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveGComputationCreate2(IntPtr input, IntPtr output); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveGComputationCreate3(IntPtr input1, IntPtr input2, IntPtr output); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveGComputationCreate4(IntPtr input1, IntPtr input2, IntPtr output); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveGComputationCreate5(IntPtr inputs, IntPtr outputs); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveGComputationRelease(ref IntPtr computation); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveGComputationApply1(IntPtr computation, IntPtr input, IntPtr output); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveGComputationApply2(IntPtr computation, IntPtr input, ref MCvScalar output); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveGComputationApply3(IntPtr computation, IntPtr input1, IntPtr input2, IntPtr output); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveGComputationApply4(IntPtr computation, IntPtr input1, IntPtr input2, ref MCvScalar output); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveGComputationApply5(IntPtr computation, IntPtr inputs, IntPtr outputs); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveGMatCreate(); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveGMatRelease(ref IntPtr gmat); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveGScalarCreate(ref MCvScalar value); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveGScalarRelease(ref IntPtr gscalar); } public class GComputation : UnmanagedObject { public GComputation(GMat input, GMat output) { _ptr = GapiInvoke.cveGComputationCreate1(input, output); } public GComputation(GMat input, GScalar output) { _ptr = GapiInvoke.cveGComputationCreate2(input, output); } public GComputation(GMat input1, GMat input2, GMat output) { _ptr = GapiInvoke.cveGComputationCreate3(input1, input2, output); } public GComputation(GMat input1, GMat input2, GScalar output) { _ptr = GapiInvoke.cveGComputationCreate4(input1, input2, output); } public GComputation(VectorOfGMat inputs, VectorOfGMat outputs) { _ptr = GapiInvoke.cveGComputationCreate5(inputs, outputs); } public void Apply(Mat input, Mat output) { GapiInvoke.cveGComputationApply1(_ptr, input, output); } public MCvScalar ApplyS(Mat input) { MCvScalar output = default(MCvScalar); GapiInvoke.cveGComputationApply2(_ptr, input, ref output); return output; } public void Apply(Mat input1, Mat input2, Mat output) { GapiInvoke.cveGComputationApply3(_ptr, input1, input2, output); } public MCvScalar ApplyS(Mat input1, Mat input2) { MCvScalar output = default(MCvScalar); GapiInvoke.cveGComputationApply4(_ptr, input1, input2, ref output); return output; } public void Apply(VectorOfMat input, VectorOfMat output) { GapiInvoke.cveGComputationApply5(_ptr, input, output); } protected override void DisposeObject() { if (IntPtr.Zero != _ptr) { GapiInvoke.cveGComputationRelease(ref _ptr); } } } public class GMat : UnmanagedObject { internal bool _needDispose; internal GMat(IntPtr ptr, bool needDispose) { _ptr = ptr; _needDispose = needDispose; } public GMat() : this(GapiInvoke.cveGMatCreate(), needDispose: true) { } protected override void DisposeObject() { if (_needDispose && IntPtr.Zero != _ptr) { GapiInvoke.cveGMatRelease(ref _ptr); } } } public class GScalar : UnmanagedObject { internal GScalar(IntPtr ptr) { _ptr = ptr; } public GScalar(MCvScalar value) { _ptr = GapiInvoke.cveGScalarCreate(ref value); } public GScalar(double value) : this(new MCvScalar(value)) { } protected override void DisposeObject() { if (IntPtr.Zero != _ptr) { GapiInvoke.cveGScalarRelease(ref _ptr); } } } public static class TrackingInvoke { [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveMultiTrackerCreate(); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.U1)] internal static extern bool cveMultiTrackerAdd(IntPtr multiTracker, IntPtr tracker, IntPtr image, ref Rectangle boundingBox); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.U1)] internal static extern bool cveMultiTrackerUpdate(IntPtr tracker, IntPtr image, IntPtr boundingBox); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveMultiTrackerRelease(ref IntPtr tracker); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveMultiTrackerGetObjects(IntPtr tracker, IntPtr boundingBox); static TrackingInvoke() { CvInvoke.Init(); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.U1)] internal static extern bool cveLegacyTrackerInit(IntPtr tracker, IntPtr image, ref Rectangle boundingBox); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.U1)] internal static extern bool cveLegacyTrackerUpdate(IntPtr tracker, IntPtr image, ref Rectangle boundingBox); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveTrackerBoostingCreate(int numClassifiers, float samplerOverlap, float samplerSearchFactor, int iterationInit, int featureSetNumFeatures, ref IntPtr tracker, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveTrackerBoostingRelease(ref IntPtr tracker, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveTrackerCSRTCreate(float psr_threshold, [MarshalAs(UnmanagedType.U1)] bool useHog, [MarshalAs(UnmanagedType.U1)] bool useColorNames, [MarshalAs(UnmanagedType.U1)] bool useGray, [MarshalAs(UnmanagedType.U1)] bool useRgb, [MarshalAs(UnmanagedType.U1)] bool useChannelWeights, [MarshalAs(UnmanagedType.U1)] bool useSegmentation, IntPtr windowFunction, float kaiserAlpha, float chebAttenuation, float templateSize, float gslSigma, float hogOrientations, float hogClip, float padding, float filterLr, float weightsLr, int numHogChannelsUsed, int admmIterations, int histogramBins, float histogramLr, int backgroundRatio, int numberOfScales, float scaleSigmaFactor, float scaleModelMaxArea, float scaleLr, float scaleStep, ref IntPtr tracker, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveTrackerCSRTRelease(ref IntPtr tracker, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveTrackerKCFCreate(float detectThresh, float sigma, float lambda, float interpFactor, float outputSigmaFactor, float pcaLearningRate, [MarshalAs(UnmanagedType.U1)] bool resize, [MarshalAs(UnmanagedType.U1)] bool splitCoeff, [MarshalAs(UnmanagedType.U1)] bool wrapKernel, [MarshalAs(UnmanagedType.U1)] bool compressFeature, int maxPatchSize, int compressedSize, TrackerKCF.Mode descPca, TrackerKCF.Mode descNpca, ref IntPtr tracker, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveTrackerKCFRelease(ref IntPtr tracker, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveTrackerMedianFlowCreate(int pointsInGrid, ref Size winSize, int maxLevel, ref MCvTermCriteria termCriteria, ref Size winSizeNCC, double maxMedianLengthOfDisplacementDifference, ref IntPtr tracker, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveTrackerMedianFlowRelease(ref IntPtr tracker, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveTrackerMOSSECreate(ref IntPtr tracker, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveTrackerMOSSERelease(ref IntPtr tracker, ref IntPtr sharedPTr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveTrackerTLDCreate(ref IntPtr tracker, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveTrackerTLDRelease(ref IntPtr tracker, ref IntPtr sharedPtr); } public class TrackerCSRT : Tracker { private IntPtr _sharedPtr; public TrackerCSRT(float psr_threshold = 2f, bool useHog = true, bool useColorNames = true, bool useGray = true, bool useRgb = false, bool useChannelWeights = true, bool useSegmentation = true, string windowFunction = null, float kaiserAlpha = 3.75f, float chebAttenuation = 45f, float templateSize = 200f, float gslSigma = 1f, float hogOrientations = 9f, float hogClip = 0.2f, float padding = 3f, float filterLr = 0.02f, float weightsLr = 0.02f, int numHogChannelsUsed = 18, int admmIterations = 4, int histogramBins = 16, float histogramLr = 0.04f, int backgroundRatio = 2, int numberOfScales = 33, float scaleSigmaFactor = 0.25f, float scaleModelMaxArea = 512f, float scaleLr = 0.025f, float scaleStep = 1.02f) { using CvString cvString = new CvString(windowFunction); _ptr = TrackingInvoke.cveTrackerCSRTCreate(psr_threshold, useHog, useColorNames, useGray, useRgb, useChannelWeights, useSegmentation, cvString, kaiserAlpha, chebAttenuation, templateSize, gslSigma, hogOrientations, hogClip, padding, filterLr, weightsLr, numHogChannelsUsed, admmIterations, histogramBins, histogramLr, backgroundRatio, numberOfScales, scaleSigmaFactor, scaleModelMaxArea, scaleLr, scaleStep, ref _trackerPtr, ref _sharedPtr); } protected override void DisposeObject() { if (IntPtr.Zero != _ptr) { TrackingInvoke.cveTrackerCSRTRelease(ref _ptr, ref _sharedPtr); } base.DisposeObject(); } } public class TrackerKCF : Tracker { public enum Mode { Gray = 1, Cn = 2, Custom = 4 } private IntPtr _sharedPtr; public TrackerKCF(float detectThresh = 0.5f, float sigma = 0.2f, float lambda = 0.01f, float interpFactor = 0.075f, float outputSigmaFactor = 0.0625f, float pcaLearningRate = 0.15f, bool resize = true, bool splitCoeff = true, bool wrapKernel = false, bool compressFeature = true, int maxPatchSize = 6400, int compressedSize = 2, Mode descPca = Mode.Cn, Mode descNpca = Mode.Gray) { _ptr = TrackingInvoke.cveTrackerKCFCreate(detectThresh, sigma, lambda, interpFactor, outputSigmaFactor, pcaLearningRate, resize, splitCoeff, wrapKernel, compressFeature, maxPatchSize, compressedSize, descPca, descNpca, ref _trackerPtr, ref _sharedPtr); } protected override void DisposeObject() { if (IntPtr.Zero != _ptr) { TrackingInvoke.cveTrackerKCFRelease(ref _ptr, ref _sharedPtr); } base.DisposeObject(); } } public class WeChatQRCode : UnmanagedObject { public class QRCode { public string Code { get; set; } public Point[] Region { get; set; } } public WeChatQRCode(string detectorPrototxtPath, string detectorCaffeModelPath, string superResolutionPrototxtPath, string superResolutionCaffeModelPath) { using CvString cvString = new CvString(detectorPrototxtPath); using CvString cvString2 = new CvString(detectorCaffeModelPath); using CvString cvString3 = new CvString(superResolutionPrototxtPath); using CvString cvString4 = new CvString(superResolutionCaffeModelPath); _ptr = WeChatQRCodeInvoke.cveWeChatQRCodeCreate(cvString, cvString2, cvString3, cvString4); } public string[] DetectAndDecode(IInputArray img, IOutputArrayOfArrays points) { using InputArray inputArray = img.GetInputArray(); using OutputArray outputArray = ((points == null) ? OutputArray.GetEmpty() : points.GetOutputArray()); using VectorOfCvString vectorOfCvString = new VectorOfCvString(); WeChatQRCodeInvoke.cveWeChatQRCodeDetectAndDecode(_ptr, inputArray, outputArray, vectorOfCvString); return vectorOfCvString.ToArray(); } public QRCode[] DetectAndDecode(IInputArray img) { using (img.GetInputArray()) { using VectorOfMat vectorOfMat = new VectorOfMat(); using (new VectorOfCvString()) { string[] array = DetectAndDecode(img, vectorOfMat); if (array.Length == 0) { return new QRCode[0]; } Point[][] array2 = VectorOfMatToPoints(vectorOfMat); QRCode[] array3 = new QRCode[array.Length]; for (int i = 0; i < array.Length; i++) { QRCode qRCode = new QRCode(); qRCode.Code = array[i]; qRCode.Region = array2[i]; array3[i] = qRCode; } return array3; } } } private static Point[][] VectorOfMatToPoints(VectorOfMat vm) { Point[][] array = new Point[vm.Size][]; for (int i = 0; i < array.Length; i++) { using Mat m = vm[i]; array[i] = MatToPoints(m); } return array; } private static Point[] MatToPoints(Mat m) { PointF[] array = new PointF[m.Width * m.Height / 2]; GCHandle gCHandle = GCHandle.Alloc(array, GCHandleType.Pinned); CvToolbox.Memcpy(gCHandle.AddrOfPinnedObject(), m.DataPointer, array.Length * Marshal.SizeOf()); gCHandle.Free(); return Array.ConvertAll(array, Point.Round); } protected override void DisposeObject() { if (_ptr != IntPtr.Zero) { WeChatQRCodeInvoke.cveWeChatQRCodeRelease(ref _ptr); } } } internal static class WeChatQRCodeInvoke { static WeChatQRCodeInvoke() { CvInvoke.Init(); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveWeChatQRCodeCreate(IntPtr detectorPrototxtPath, IntPtr detectorCaffeModelPath, IntPtr superResolutionPrototxtPath, IntPtr superResolutionCaffeModelPath); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveWeChatQRCodeRelease(ref IntPtr detector); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveWeChatQRCodeDetectAndDecode(IntPtr detector, IntPtr img, IntPtr points, IntPtr results); } public class BarcodeDetector : UnmanagedObject { public class Barcode { public string DecodedInfo { get; set; } public BarcodeType Type { get; set; } public PointF[] Points { get; set; } } public enum BarcodeType { None, EAN_8, EAN_13, UPC_A, UPC_E, UPC_EAN_Extension } public BarcodeDetector(string prototxtPath, string modelPath) { using CvString cvString = new CvString(prototxtPath); using CvString cvString2 = new CvString(modelPath); _ptr = BarcodeInvoke.cveBarcodeDetectorCreate(cvString, cvString2); } protected override void DisposeObject() { if (_ptr != IntPtr.Zero) { BarcodeInvoke.cveBarcodeDetectorRelease(ref _ptr); } } public bool Detect(IInputArray image, IOutputArray points) { using InputArray inputArray = image.GetInputArray(); using OutputArray outputArray = points.GetOutputArray(); return BarcodeInvoke.cveBarcodeDetectorDetect(_ptr, inputArray, outputArray); } public bool Decode(IInputArray image, IInputArray points, VectorOfCvString decodedInfo, VectorOfInt decodedType) { using InputArray inputArray = image.GetInputArray(); using InputArray inputArray2 = points.GetInputArray(); return BarcodeInvoke.cveBarcodeDetectorDecode(_ptr, inputArray, inputArray2, decodedInfo, decodedType); } public bool DetectAndDecode(IInputArray image, VectorOfCvString decodedInfo, VectorOfInt decodedType, IOutputArray points = null) { using InputArray inputArray = image.GetInputArray(); using OutputArray outputArray = ((points == null) ? OutputArray.GetEmpty() : points.GetOutputArray()); return BarcodeInvoke.cveBarcodeDetectorDetectAndDecode(_ptr, inputArray, decodedInfo, decodedType, outputArray); } public Barcode[] DetectAndDecode(IInputArray image) { using VectorOfCvString vectorOfCvString = new VectorOfCvString(); using VectorOfInt vectorOfInt = new VectorOfInt(); using Mat mat = new Mat(); if (!DetectAndDecode(image, vectorOfCvString, vectorOfInt, mat)) { return new Barcode[0]; } PointF[] array = new PointF[4 * mat.Rows]; if (array.Length != 0) { GCHandle gCHandle = GCHandle.Alloc(array, GCHandleType.Pinned); CvInvoke.cveMemcpy(gCHandle.AddrOfPinnedObject(), mat.DataPointer, array.Length * Marshal.SizeOf()); gCHandle.Free(); } string[] array2 = vectorOfCvString.ToArray(); int[] array3 = vectorOfInt.ToArray(); Barcode[] array4 = new Barcode[array2.Length]; for (int i = 0; i < array4.Length; i++) { Barcode barcode = new Barcode(); barcode.DecodedInfo = array2[i]; barcode.Type = (BarcodeType)array3[i]; PointF[] array5 = new PointF[4]; Array.Copy(array, 4 * i, array5, 0, 4); barcode.Points = array5; array4[i] = barcode; } return array4; } } internal static class BarcodeInvoke { static BarcodeInvoke() { CvInvoke.Init(); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveBarcodeDetectorCreate(IntPtr prototxtPath, IntPtr modelPath); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveBarcodeDetectorRelease(ref IntPtr detector); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.U1)] internal static extern bool cveBarcodeDetectorDetect(IntPtr detector, IntPtr img, IntPtr points); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.U1)] internal static extern bool cveBarcodeDetectorDecode(IntPtr detector, IntPtr img, IntPtr points, IntPtr decodedInfo, IntPtr decodedType); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.U1)] internal static extern bool cveBarcodeDetectorDetectAndDecode(IntPtr detector, IntPtr img, IntPtr decodedInfo, IntPtr decodedType, IntPtr points); } } namespace Emgu.CV.Reg { public interface IMap { IntPtr MapPtr { get; } } public static class RegInvoke { static RegInvoke() { CvInvoke.Init(); } public static void Warp(this IMap map, IInputArray img1, IOutputArray img2) { using InputArray inputArray = img1.GetInputArray(); using OutputArray outputArray = img2.GetOutputArray(); cveMapWarp(map.MapPtr, inputArray, outputArray); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveMapWarp(IntPtr map, IntPtr img1, IntPtr img2); public static void InverseWarp(this IMap map, IInputArray img1, IOutputArray img2) { using InputArray inputArray = img1.GetInputArray(); using OutputArray outputArray = img2.GetOutputArray(); cveMapInverseWarp(map.MapPtr, inputArray, outputArray); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveMapInverseWarp(IntPtr map, IntPtr img1, IntPtr img2); public static void Scale(this IMap map, double factor) { cveMapScale(map.MapPtr, factor); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveMapScale(IntPtr map, double factor); public static Map Calculate(this IMapper mapper, IInputArray img1, IInputArray img2, Map init = null) { IntPtr sharedPtr = IntPtr.Zero; IntPtr ptr; using (InputArray inputArray = img1.GetInputArray()) { using InputArray inputArray2 = img2.GetInputArray(); ptr = cveMapperCalculate(mapper.MapperPtr, inputArray, inputArray2, init, ref sharedPtr); } return new Map(ptr, sharedPtr); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveMapperCalculate(IntPtr mapper, IntPtr img1, IntPtr img2, IntPtr init, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveMapRelease(ref IntPtr mapSharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveMapAffineCreate(IntPtr lineTr, IntPtr shift, ref IntPtr map); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveMapAffineRelease(ref IntPtr mapAffine); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveMapperGradAffineCreate(ref IntPtr mapper); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveMapperGradAffineRelease(ref IntPtr mapper); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveMapperGradEuclidCreate(ref IntPtr mapper); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveMapperGradEuclidRelease(ref IntPtr mapper); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveMapperGradProjCreate(ref IntPtr mapper); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveMapperGradProjRelease(ref IntPtr mapper); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveMapperGradShiftCreate(ref IntPtr mapper); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveMapperGradShiftRelease(ref IntPtr mapper); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveMapperGradSimilarCreate(ref IntPtr mapper); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveMapperGradSimilarRelease(ref IntPtr mapper); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveMapperPyramidCreate(IntPtr baseMapper, ref IntPtr mapper); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveMapperPyramidRelease(ref IntPtr mapper); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveMapProjecCreate(IntPtr projTr, ref IntPtr map); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveMapProjecRelease(ref IntPtr mapShift); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveMapShiftCreate(ref MCvPoint2D64f shift, ref IntPtr map); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveMapShiftRelease(ref IntPtr mapShift); } public interface IMapper { IntPtr MapperPtr { get; } } public class Map : SharedPtrObject, IMap { public IntPtr MapPtr => _ptr; internal Map(IntPtr ptr, IntPtr sharedPtr) { _ptr = ptr; _sharedPtr = sharedPtr; } protected override void DisposeObject() { if (_sharedPtr != IntPtr.Zero) { RegInvoke.cveMapRelease(ref _sharedPtr); } } } public class MapAffine : UnmanagedObject, IMap { private IntPtr _mapPtr; public IntPtr MapPtr => _mapPtr; public MapAffine(IInputArray linTr, IInputArray shift) { using InputArray inputArray = linTr.GetInputArray(); using InputArray inputArray2 = shift.GetInputArray(); _ptr = RegInvoke.cveMapAffineCreate(inputArray, inputArray2, ref _mapPtr); } protected override void DisposeObject() { if (_ptr != IntPtr.Zero) { RegInvoke.cveMapAffineRelease(ref _ptr); _mapPtr = IntPtr.Zero; } } } public class MapperGradAffine : UnmanagedObject, IMapper { private IntPtr _mapperPtr; public IntPtr MapperPtr => _mapperPtr; public MapperGradAffine() { _ptr = RegInvoke.cveMapperGradAffineCreate(ref _mapperPtr); } protected override void DisposeObject() { if (_ptr != IntPtr.Zero) { RegInvoke.cveMapperGradAffineRelease(ref _ptr); _mapperPtr = IntPtr.Zero; } } } public class MapperGradEuclid : UnmanagedObject, IMapper { private IntPtr _mapperPtr; public IntPtr MapperPtr => _mapperPtr; public MapperGradEuclid() { _ptr = RegInvoke.cveMapperGradEuclidCreate(ref _mapperPtr); } protected override void DisposeObject() { if (_ptr != IntPtr.Zero) { RegInvoke.cveMapperGradShiftRelease(ref _ptr); _mapperPtr = IntPtr.Zero; } } } public class MapperGradProj : UnmanagedObject, IMapper { private IntPtr _mapperPtr; public IntPtr MapperPtr => _mapperPtr; public MapperGradProj() { _ptr = RegInvoke.cveMapperGradProjCreate(ref _mapperPtr); } protected override void DisposeObject() { if (_ptr != IntPtr.Zero) { RegInvoke.cveMapperGradProjRelease(ref _ptr); _mapperPtr = IntPtr.Zero; } } } public class MapperGradShift : UnmanagedObject, IMapper { private IntPtr _mapperPtr; public IntPtr MapperPtr => _mapperPtr; public MapperGradShift() { _ptr = RegInvoke.cveMapperGradShiftCreate(ref _mapperPtr); } protected override void DisposeObject() { if (_ptr != IntPtr.Zero) { RegInvoke.cveMapperGradShiftRelease(ref _ptr); _mapperPtr = IntPtr.Zero; } } } public class MapperGradSimilar : UnmanagedObject, IMapper { private IntPtr _mapperPtr; public IntPtr MapperPtr => _mapperPtr; public MapperGradSimilar() { _ptr = RegInvoke.cveMapperGradSimilarCreate(ref _mapperPtr); } protected override void DisposeObject() { if (_ptr != IntPtr.Zero) { RegInvoke.cveMapperGradSimilarRelease(ref _ptr); _mapperPtr = IntPtr.Zero; } } } public class MapperPyramid : UnmanagedObject, IMapper { private IntPtr _mapperPtr; public IntPtr MapperPtr => _mapperPtr; public MapperPyramid(IMapper baseMapper) { _ptr = RegInvoke.cveMapperPyramidCreate(baseMapper.MapperPtr, ref _mapperPtr); } protected override void DisposeObject() { if (_ptr != IntPtr.Zero) { RegInvoke.cveMapperPyramidRelease(ref _ptr); _mapperPtr = IntPtr.Zero; } } } public class MapProjec : UnmanagedObject, IMap { private IntPtr _mapPtr; public IntPtr MapPtr => _mapPtr; public MapProjec(IInputArray projTr) { using InputArray inputArray = projTr.GetInputArray(); _ptr = RegInvoke.cveMapProjecCreate(inputArray, ref _mapPtr); } protected override void DisposeObject() { if (_ptr != IntPtr.Zero) { RegInvoke.cveMapProjecRelease(ref _ptr); _mapPtr = IntPtr.Zero; } } } public class MapShift : UnmanagedObject, IMap { private IntPtr _mapPtr; public IntPtr MapPtr => _mapPtr; public MapShift(MCvPoint2D64f shift) { _ptr = RegInvoke.cveMapShiftCreate(ref shift, ref _mapPtr); } protected override void DisposeObject() { if (_ptr != IntPtr.Zero) { RegInvoke.cveMapShiftRelease(ref _ptr); _mapPtr = IntPtr.Zero; } } } } namespace Emgu.CV.Rgbd { public class Odometry : SharedPtrObject, IAlgorithm { private IntPtr _algorithmPtr; public IntPtr AlgorithmPtr => _algorithmPtr; public Odometry(string odometryType) { using CvString cvString = new CvString(odometryType); _ptr = RgbdInvoke.cveOdometryCreate(cvString, ref _algorithmPtr, ref _sharedPtr); } public bool Compute(Mat srcImage, Mat srcDepth, Mat srcMask, Mat dstImage, Mat dstDepth, Mat dstMask, IOutputArray rt, Mat initRt = null) { using OutputArray outputArray = rt.GetOutputArray(); return RgbdInvoke.cveOdometryCompute(_ptr, srcImage, srcDepth, srcMask, dstImage, dstDepth, dstMask, outputArray, initRt); } protected override void DisposeObject() { if (_sharedPtr != IntPtr.Zero) { RgbdInvoke.cveOdometryRelease(ref _sharedPtr); _algorithmPtr = IntPtr.Zero; _ptr = IntPtr.Zero; } } } public static class RgbdInvoke { static RgbdInvoke() { CvInvoke.Init(); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveOdometryCreate(IntPtr odometryType, ref IntPtr algorithm, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveOdometryRelease(ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.U1)] internal static extern bool cveOdometryCompute(IntPtr odometry, IntPtr srcImage, IntPtr srcDepth, IntPtr srcMask, IntPtr dstImage, IntPtr dstDepth, IntPtr dstMask, IntPtr rt, IntPtr initRt); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveRgbdNormalsCreate(int rows, int cols, DepthType depth, IntPtr K, int windowSize, RgbdNormals.Method method, ref IntPtr algorithm, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveRgbdNormalsRelease(ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.U1)] internal static extern bool cveRgbdNormalsApply(IntPtr rgbdNormals, IntPtr points, IntPtr normals); } public class RgbdNormals : SharedPtrObject, IAlgorithm { public enum Method { Fals, Linemod, Sri } private IntPtr _algorithmPtr; public IntPtr AlgorithmPtr => _algorithmPtr; public RgbdNormals(int rows, int cols, DepthType depth, IInputArray k, int windowSize = 5, Method method = Method.Fals) { using InputArray inputArray = k.GetInputArray(); _ptr = RgbdInvoke.cveRgbdNormalsCreate(rows, cols, depth, inputArray, windowSize, method, ref _algorithmPtr, ref _sharedPtr); } public void Apply(IInputArray points, IOutputArray normals) { using InputArray inputArray = points.GetInputArray(); using OutputArray outputArray = normals.GetOutputArray(); RgbdInvoke.cveRgbdNormalsApply(_ptr, inputArray, outputArray); } protected override void DisposeObject() { if (_sharedPtr != IntPtr.Zero) { RgbdInvoke.cveRgbdNormalsRelease(ref _sharedPtr); _algorithmPtr = IntPtr.Zero; _ptr = IntPtr.Zero; } } } } namespace Emgu.CV.Linemod { public abstract class Detector : SharedPtrObject { public string[] ClassIds { get { using VectorOfCvString vectorOfCvString = new VectorOfCvString(); LinemodInvoke.cveLinemodDetectorGetClassIds(_ptr, vectorOfCvString); return vectorOfCvString.ToArray(); } } public Modality[] Modalities { get { if (_ptr == IntPtr.Zero) { return null; } using VectorOfIntPtr vectorOfIntPtr = new VectorOfIntPtr(); LinemodInvoke.cveLinemodDetectorGetModalities(_ptr, vectorOfIntPtr); IntPtr[] array = vectorOfIntPtr.ToArray(); Modality[] array2 = new Modality[array.Length]; for (int i = 0; i < array.Length; i++) { array2[i] = new Modality(array[i], needDispose: false); } return array2; } } public int PyramidLevels => LinemodInvoke.cveDetectorPyramidLevels(_ptr); public int NumTemplates => LinemodInvoke.cveDetectorNumTemplates(_ptr); public int NumClasses => LinemodInvoke.cveDetectorNumClasses(_ptr); public void Read(FileNode fn) { LinemodInvoke.cveLinemodDetectorRead(_ptr, fn); } public void Write(FileStorage fs) { LinemodInvoke.cveLinemodDetectorWrite(_ptr, fs); } public int AddTemplate(VectorOfMat sources, string classId, Mat objectMask, ref Rectangle boundingBox) { using CvString cvString = new CvString(classId); return LinemodInvoke.cveLinemodDetectorAddTemplate(_ptr, sources, cvString, objectMask, ref boundingBox); } public void Match(VectorOfMat sources, float threshold, VectorOfLinemodMatch matches, VectorOfCvString classIds = null, IOutputArrayOfArrays quantizedImages = null, VectorOfMat masks = null) { using OutputArray outputArray = ((quantizedImages == null) ? OutputArray.GetEmpty() : quantizedImages.GetOutputArray()); LinemodInvoke.cveLinemodDetectorMatch(_ptr, sources, threshold, matches, classIds, outputArray, masks); } public int GetT(int pyramidLevel) { return LinemodInvoke.cveLinemodDetectorGetT(_ptr, pyramidLevel); } protected override void DisposeObject() { if (_sharedPtr != IntPtr.Zero) { LinemodInvoke.cveLinemodDetectorRelease(ref _sharedPtr); _ptr = IntPtr.Zero; } } } public class LineDetector : Detector { public LineDetector() { _ptr = LinemodInvoke.cveLinemodLineDetectorCreate(ref _sharedPtr); } } public class LinemodDetector : Detector { public LinemodDetector() { _ptr = LinemodInvoke.cveLinemodLinemodDetectorCreate(ref _sharedPtr); } } public static class LinemodInvoke { [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveLinemodLinemodDetectorCreate(ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveLinemodLineDetectorCreate(ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveLinemodDetectorRelease(ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveLinemodDetectorRead(IntPtr detector, IntPtr fn); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveLinemodDetectorWrite(IntPtr detector, IntPtr fs); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveLinemodDetectorGetClassIds(IntPtr detector, IntPtr classIds); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int cveLinemodDetectorAddTemplate(IntPtr detector, IntPtr sources, IntPtr classId, IntPtr objectMask, ref Rectangle boundingBox); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveLinemodDetectorMatch(IntPtr detector, IntPtr sources, float threshold, IntPtr matches, IntPtr classIds, IntPtr quantizedImages, IntPtr masks); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int cveLinemodDetectorGetT(IntPtr detector, int pyramidLevel); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveLinemodDetectorGetModalities(IntPtr detector, IntPtr vectorOfPtrs); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int cveDetectorPyramidLevels(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int cveDetectorNumTemplates(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int cveDetectorNumClasses(IntPtr obj); static LinemodInvoke() { CvInvoke.Init(); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveLinemodMatchCreate(); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveLinemodMatchRelease(ref IntPtr ptr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int cveMatchGetX(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveMatchSetX(IntPtr obj, int val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int cveMatchGetY(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveMatchSetY(IntPtr obj, int val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern float cveMatchGetSimilarity(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveMatchSetSimilarity(IntPtr obj, float val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int cveMatchGetTemplateId(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveMatchSetTemplateId(IntPtr obj, int val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveMatchGetclass_id(IntPtr obj, IntPtr str); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveMatchSetclass_id(IntPtr obj, IntPtr str); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveLinemodModalityCreate(IntPtr modalityType, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveLinemodModalityRelease(ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveModalityName(IntPtr obj, IntPtr str); } public class Match : UnmanagedObject { private readonly bool _needDispose; public int X { get { return LinemodInvoke.cveMatchGetX(_ptr); } set { LinemodInvoke.cveMatchSetX(_ptr, value); } } public int Y { get { return LinemodInvoke.cveMatchGetY(_ptr); } set { LinemodInvoke.cveMatchSetY(_ptr, value); } } public float Similarity { get { return LinemodInvoke.cveMatchGetSimilarity(_ptr); } set { LinemodInvoke.cveMatchSetSimilarity(_ptr, value); } } public int TemplateId { get { return LinemodInvoke.cveMatchGetTemplateId(_ptr); } set { LinemodInvoke.cveMatchSetTemplateId(_ptr, value); } } public string class_id { get { using CvString cvString = new CvString(); LinemodInvoke.cveMatchGetclass_id(_ptr, cvString); return cvString.ToString(); } set { using CvString cvString = new CvString(value); LinemodInvoke.cveMatchSetclass_id(_ptr, cvString); } } internal Match(IntPtr ptr, bool needDispose) { _ptr = ptr; _needDispose = needDispose; } public Match() { _ptr = LinemodInvoke.cveLinemodMatchCreate(); _needDispose = true; } protected override void DisposeObject() { if (_needDispose && _ptr != IntPtr.Zero) { LinemodInvoke.cveLinemodMatchRelease(ref _ptr); } } } public class Modality : SharedPtrObject { private bool _needDispose; public string Name { get { using CvString cvString = new CvString(); LinemodInvoke.cveModalityName(_ptr, cvString); return cvString.ToString(); } } internal Modality(IntPtr ptr, bool needDispose) { _ptr = ptr; _needDispose = needDispose; } public Modality(string modalityType) { using CvString cvString = new CvString(modalityType); _ptr = LinemodInvoke.cveLinemodModalityCreate(cvString, ref _sharedPtr); } protected override void DisposeObject() { if (_needDispose && _sharedPtr != IntPtr.Zero) { LinemodInvoke.cveLinemodDetectorRelease(ref _sharedPtr); } _sharedPtr = IntPtr.Zero; _ptr = IntPtr.Zero; } } [Serializable] [DebuggerTypeProxy(typeof(DebuggerProxy))] public class VectorOfLinemodMatch : UnmanagedVector { internal class DebuggerProxy { private VectorOfLinemodMatch _v; public Match[] Values { get { Match[] array = new Match[_v.Size]; for (int i = 0; i < array.Length; i++) { array[i] = _v[i]; } return array; } } public DebuggerProxy(VectorOfLinemodMatch v) { _v = v; } } private readonly bool _needDispose; public override int Size => VectorOfLinemodMatchGetSize(_ptr); public override IntPtr StartAddress => VectorOfLinemodMatchGetStartAddress(_ptr); public override long Length => VectorOfLinemodMatchGetMemorySize(_ptr); public Match this[int index] { get { IntPtr element = IntPtr.Zero; VectorOfLinemodMatchGetItemPtr(_ptr, index, ref element); return new Match(element, needDispose: false); } } public static int SizeOfItemInBytes => VectorOfLinemodMatchSizeOfItemInBytes(); static VectorOfLinemodMatch() { CvInvoke.Init(); } public VectorOfLinemodMatch() : this(VectorOfLinemodMatchCreate(), needDispose: true) { } internal VectorOfLinemodMatch(IntPtr ptr, bool needDispose) { _ptr = ptr; _needDispose = needDispose; } public VectorOfLinemodMatch(int size) : this(VectorOfLinemodMatchCreateSize(size), needDispose: true) { } public VectorOfLinemodMatch(params Match[] values) : this() { Push(values); } public void Clear() { VectorOfLinemodMatchClear(_ptr); } public void Push(Match value) { VectorOfLinemodMatchPush(_ptr, value.Ptr); } public void Push(Match[] values) { foreach (Match value in values) { Push(value); } } public void Push(VectorOfLinemodMatch other) { VectorOfLinemodMatchPushVector(_ptr, other); } protected override void DisposeObject() { if (_needDispose && _ptr != IntPtr.Zero) { VectorOfLinemodMatchRelease(ref _ptr); } } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr VectorOfLinemodMatchCreate(); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr VectorOfLinemodMatchCreateSize(int size); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfLinemodMatchRelease(ref IntPtr v); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int VectorOfLinemodMatchGetSize(IntPtr v); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr VectorOfLinemodMatchGetStartAddress(IntPtr v); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern long VectorOfLinemodMatchGetMemorySize(IntPtr v); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfLinemodMatchPush(IntPtr v, IntPtr value); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfLinemodMatchPushVector(IntPtr ptr, IntPtr otherPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfLinemodMatchClear(IntPtr v); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfLinemodMatchGetItemPtr(IntPtr vec, int index, ref IntPtr element); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int VectorOfLinemodMatchSizeOfItemInBytes(); } } namespace Emgu.CV.StructuredLight { public class GrayCodePattern : SharedPtrObject, IStructuredLightPattern, IAlgorithm { private IntPtr _structuredLightPatternPtr; private IntPtr _algorithmPtr; public IntPtr StructuredLightPatternPtr => _structuredLightPatternPtr; public IntPtr AlgorithmPtr => _algorithmPtr; public int NumberOfPatternImages => StructuredLightInvoke.cveGrayCodePatternGetNumberOfPatternImages(_ptr); public GrayCodePattern(int width = 1024, int height = 768) { _ptr = StructuredLightInvoke.cveGrayCodePatternCreate(width, height, ref _sharedPtr, ref _structuredLightPatternPtr, ref _algorithmPtr); } public void GetImagesForShadowMasks(IInputOutputArray blackImage, IInputOutputArray whiteImage) { using InputOutputArray inputOutputArray = blackImage.GetInputOutputArray(); using InputOutputArray inputOutputArray2 = whiteImage.GetInputOutputArray(); StructuredLightInvoke.cveGrayCodePatternGetImagesForShadowMasks(_ptr, inputOutputArray, inputOutputArray2); } public Point? GetProjPixel(IInputArray patternImages, int x, int y) { using InputArray inputArray = patternImages.GetInputArray(); Point projPix = default(Point); if (!StructuredLightInvoke.cveGrayCodePatternGetProjPixel(_ptr, inputArray, x, y, ref projPix)) { return null; } return projPix; } protected override void DisposeObject() { if (_sharedPtr != IntPtr.Zero) { StructuredLightInvoke.cveGrayCodePatternRelease(ref _sharedPtr); _ptr = IntPtr.Zero; _structuredLightPatternPtr = IntPtr.Zero; _algorithmPtr = IntPtr.Zero; } } public void SetWhiteThreshold(int value) { StructuredLightInvoke.cveGrayCodePatternSetWhiteThreshold(_ptr, value); } public void SetBlackThreshold(int value) { StructuredLightInvoke.cveGrayCodePatternSetBlackThreshold(_ptr, value); } } public static class StructuredLightInvoke { [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveGrayCodePatternCreate(int width, int height, ref IntPtr sharedPtr, ref IntPtr structuredLightPattern, ref IntPtr algorithm); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveGrayCodePatternRelease(ref IntPtr pattern); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveGrayCodePatternGetImagesForShadowMasks(IntPtr grayCodePattern, IntPtr blackImage, IntPtr whiteImage); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.U1)] internal static extern bool cveGrayCodePatternGetProjPixel(IntPtr grayCodePattern, IntPtr patternImages, int x, int y, ref Point projPix); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int cveGrayCodePatternGetNumberOfPatternImages(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveGrayCodePatternSetWhiteThreshold(IntPtr obj, int val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveGrayCodePatternSetBlackThreshold(IntPtr obj, int val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveSinusoidalPatternCreate(int width, int height, int nbrOfPeriods, float shiftValue, SinusoidalPattern.Method methodId, int nbrOfPixelsBetweenMarkers, [MarshalAs(UnmanagedType.U1)] bool horizontal, [MarshalAs(UnmanagedType.U1)] bool setMarkers, IntPtr markersLocation, ref IntPtr sharedPtr, ref IntPtr structuredLightPattern, ref IntPtr algorithm); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveSinusoidalPatternRelease(ref IntPtr pattern); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveSinusoidalPatternComputePhaseMap(IntPtr pattern, IntPtr patternImages, IntPtr wrappedPhaseMap, IntPtr shadowMask, IntPtr fundamental); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveSinusoidalPatternUnwrapPhaseMap(IntPtr pattern, IntPtr wrappedPhaseMap, IntPtr unwrappedPhaseMap, ref Size camSize, IntPtr shadowMask); static StructuredLightInvoke() { CvInvoke.Init(); } public static bool Generate(this IStructuredLightPattern structuredLightPattern, IOutputArrayOfArrays patternImages) { using OutputArray outputArray = patternImages.GetOutputArray(); return cveStructuredLightPatternGenerate(structuredLightPattern.StructuredLightPatternPtr, outputArray); } public static bool Decode(this IStructuredLightPattern structuredLightPattern, VectorOfVectorOfMat patternImages, IOutputArray disparityMap, IInputArrayOfArrays blackImages = null, IInputArrayOfArrays whiteImages = null, DecodeFlag flags = DecodeFlag.Decode3dUnderworld) { using OutputArray outputArray = disparityMap.GetOutputArray(); using InputArray inputArray = ((blackImages == null) ? InputArray.GetEmpty() : blackImages.GetInputArray()); using InputArray inputArray2 = ((whiteImages == null) ? InputArray.GetEmpty() : whiteImages.GetInputArray()); return cveStructuredLightPatternDecode(structuredLightPattern.StructuredLightPatternPtr, patternImages, outputArray, inputArray, inputArray2, flags); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.U1)] internal static extern bool cveStructuredLightPatternGenerate(IntPtr structuredLight, IntPtr patternImages); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.U1)] internal static extern bool cveStructuredLightPatternDecode(IntPtr structuredLight, IntPtr patternImages, IntPtr disparityMap, IntPtr blackImages, IntPtr whiteImages, DecodeFlag flags); } public class SinusoidalPattern : SharedPtrObject, IStructuredLightPattern, IAlgorithm { public enum Method { FTP, PSP, FAPS } private IntPtr _structuredLightPatternPtr; private IntPtr _algorithmPtr; public IntPtr StructuredLightPatternPtr => _structuredLightPatternPtr; public IntPtr AlgorithmPtr => _algorithmPtr; public SinusoidalPattern(int width = 800, int height = 600, int nbrOfPeriods = 20, float shiftValue = MathF.PI * 2f / 3f, Method methodId = Method.FAPS, int nbrOfPixelsBetweenMarkers = 56, bool horizontal = false, bool setMarkers = false, VectorOfPointF markersLocation = null) { _ptr = StructuredLightInvoke.cveSinusoidalPatternCreate(width, height, nbrOfPeriods, shiftValue, methodId, nbrOfPixelsBetweenMarkers, horizontal, setMarkers, markersLocation, ref _sharedPtr, ref _structuredLightPatternPtr, ref _algorithmPtr); } public void ComputePhaseMap(IInputArrayOfArrays patternImages, IOutputArray wrappedPhaseMap, IOutputArray shadowMask = null, IInputArray fundamental = null) { using InputArray inputArray = patternImages.GetInputArray(); using OutputArray outputArray = wrappedPhaseMap.GetOutputArray(); using OutputArray outputArray2 = ((shadowMask == null) ? OutputArray.GetEmpty() : shadowMask.GetOutputArray()); using InputArray inputArray2 = ((fundamental == null) ? InputArray.GetEmpty() : fundamental.GetInputArray()); StructuredLightInvoke.cveSinusoidalPatternComputePhaseMap(_ptr, inputArray, outputArray, outputArray2, inputArray2); } public void UnwrapPhaseMap(IInputArray wrappedPhaseMap, IOutputArray unwrappedPhaseMap, Size camSize, IInputArray shadowMask = null) { using InputArray inputArray = wrappedPhaseMap.GetInputArray(); using OutputArray outputArray = unwrappedPhaseMap.GetOutputArray(); using InputArray inputArray2 = ((shadowMask == null) ? InputArray.GetEmpty() : shadowMask.GetInputArray()); StructuredLightInvoke.cveSinusoidalPatternUnwrapPhaseMap(_ptr, inputArray, outputArray, ref camSize, inputArray2); } protected override void DisposeObject() { if (_sharedPtr != IntPtr.Zero) { StructuredLightInvoke.cveSinusoidalPatternRelease(ref _sharedPtr); _ptr = IntPtr.Zero; _structuredLightPatternPtr = IntPtr.Zero; _algorithmPtr = IntPtr.Zero; } } } public interface IStructuredLightPattern : IAlgorithm { IntPtr StructuredLightPatternPtr { get; } } public enum DecodeFlag { Decode3dUnderworld } } namespace Emgu.CV.DepthAI { public class CNNHostPipeline : SharedPtrObject { internal CNNHostPipeline(IntPtr sharedPtr, IntPtr ptr) { _sharedPtr = sharedPtr; _ptr = ptr; } public NNetAndDataPackets GetAvailableNNetAndDataPackets(bool blocking) { return new NNetAndDataPackets(DepthAIInvoke.depthaiCNNHostPipelineGetAvailableNNetAndDataPackets(_ptr, blocking)); } protected override void DisposeObject() { if (_sharedPtr != IntPtr.Zero) { DepthAIInvoke.depthaiCNNHostPipelineRelease(ref _sharedPtr); _ptr = IntPtr.Zero; } } } public class WarpRectify { public bool use_mesh { get; set; } public bool mirror_frame { get; set; } public int edge_fill_color { get; set; } } public class Depth { public string calibration_file { get; set; } public string left_mesh_file { get; set; } public string right_mesh_file { get; set; } public double padding_factor { get; set; } public double depth_limit_m { get; set; } public int median_kernel_size { get; set; } public bool lr_check { get; set; } public WarpRectify warp_rectify { get; set; } } public class Ai { public string blob_file { get; set; } public string blob_file_config { get; set; } public string blob_file2 { get; set; } public string blob_file_config2 { get; set; } public bool calc_dist_to_bb { get; set; } public bool keep_aspect_ratio { get; set; } public string camera_input { get; set; } public int shaves { get; set; } public int cmx_slices { get; set; } public int NN_engines { get; set; } } public class Ot { public int max_tracklets { get; set; } public double confidence_threshold { get; set; } } public class BoardConfig { public bool swap_left_and_right_cameras { get; set; } public double left_fov_deg { get; set; } public double rgb_fov_deg { get; set; } public double left_to_right_distance_cm { get; set; } public double left_to_rgb_distance_cm { get; set; } public bool store_to_eeprom { get; set; } public bool clear_eeprom { get; set; } public bool override_eeprom { get; set; } } public class Camera { public class Setting { public int resolution_h { get; set; } public double fps { get; set; } } public Setting rgb { get; set; } public Setting mono { get; set; } public Camera(Setting rgbSetting = null, Setting monoSetting = null) { if (rgbSetting == null) { rgbSetting = new Setting { resolution_h = 1080, fps = 30.0 }; } if (monoSetting == null) { monoSetting = new Setting { resolution_h = 720, fps = 30.0 }; } } } public class App { public bool sync_video_meta_streams { get; set; } public bool sync_sequence_numbers { get; set; } public int usb_chunk_KiB { get; set; } } public class Config { public List streams { get; set; } public Depth depth { get; set; } public Ai ai { get; set; } public Ot ot { get; set; } public BoardConfig board_config { get; set; } public Camera camera { get; set; } public App app { get; set; } } public static class DepthAIInvoke { private static readonly bool _haveDepthAI; public static bool HaveDepthAI => _haveDepthAI; static DepthAIInvoke() { CvInvoke.Init(); _haveDepthAI = CvInvoke.ConfigDict["HAVE_DEPTHAI"] == 1.0; } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr depthaiDeviceCreate(IntPtr usbDevice, [MarshalAs(UnmanagedType.U1)] bool usb2Mode); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void depthaiDeviceRelease(ref IntPtr usbDevice); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void depthaiDeviceGetAvailableStreams(IntPtr usbDevice, IntPtr availableStreams); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr depthaiDeviceCreatePipeline(IntPtr usb_device, IntPtr config_json_str, ref IntPtr hostedPipelineSharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void depthaiCNNHostPipelineRelease(ref IntPtr hostedPipelineSharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr depthaiCNNHostPipelineGetAvailableNNetAndDataPackets(IntPtr cnnHostPipeline, [MarshalAs(UnmanagedType.U1)] bool blocking); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void depthaiNNetAndDataPacketsRelease(ref IntPtr nnetAndDataPackets); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int depthaiNNetAndDataPacketsGetNNetCount(IntPtr nnetAndDataPackets); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void depthaiNNetAndDataPacketsGetNNetArr(IntPtr nnetAndDataPackets, IntPtr packetArr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int depthaiNNetAndDataPacketsGetHostDataPacketCount(IntPtr nnetAndDataPackets); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void depthaiNNetAndDataPacketsGetHostDataPacketArr(IntPtr nnetAndDataPackets, IntPtr packetArr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void depthaiHostDataPacketGetDimensions(IntPtr packet, IntPtr dimensions); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.U1)] internal static extern bool depthaiHostDataPacketGetMetadata(IntPtr packet, IntPtr metadata); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int depthaiNNetPacketGetDetectedObjectsCount(IntPtr packet); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void depthaiNNetPacketGetDetectedObjects(IntPtr packet, IntPtr detections); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.U1)] internal static extern bool depthaiNNetPacketGetMetadata(IntPtr packet, IntPtr metadata); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr depthaiFrameMetadataCreate(); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void depthaiFrameMetadataRelease(ref IntPtr metadata); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.U1)] internal static extern bool cveDeviceIsUsb3(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.U1)] internal static extern bool cveDeviceIsEepromLoaded(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.U1)] internal static extern bool cveDeviceIsRgbConnected(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.U1)] internal static extern bool cveDeviceIsLeftConnected(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.U1)] internal static extern bool cveDeviceIsRightConnected(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveFrameMetadataGetCameraName(IntPtr obj, IntPtr val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int cveFrameMetadataGetSequenceNum(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int cveFrameMetadataGetInstanceNum(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int cveFrameMetadataGetCategory(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern uint cveFrameMetadataGetStride(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern uint cveFrameMetadataGetFrameBytesPP(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern uint cveFrameMetadataGetFrameHeight(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern uint cveFrameMetadataGetFrameWidth(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int cveFrameMetadataGetFrameType(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern double cveFrameMetadataGetTimestamp(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.U1)] internal static extern bool cveFrameMetadataIsValid(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveHostDataPacketGetStreamName(IntPtr obj, IntPtr str); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int cveHostDataPacketSize(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveHostDataPacketGetData(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int cveHostDataPacketGetElemSize(IntPtr obj); } public class Device : UnmanagedObject { public string[] AvailableStreams { get { using VectorOfCvString vectorOfCvString = new VectorOfCvString(); DepthAIInvoke.depthaiDeviceGetAvailableStreams(_ptr, vectorOfCvString); return vectorOfCvString.ToArray(); } } public bool IsUsb3 => DepthAIInvoke.cveDeviceIsUsb3(_ptr); public bool IsEepromLoaded => DepthAIInvoke.cveDeviceIsEepromLoaded(_ptr); public bool IsRgbConnected => DepthAIInvoke.cveDeviceIsRgbConnected(_ptr); public bool IsLeftConnected => DepthAIInvoke.cveDeviceIsLeftConnected(_ptr); public bool IsRightConnected => DepthAIInvoke.cveDeviceIsRightConnected(_ptr); public Device(string usbDevice, bool usb2Mode = false) { using CvString cvString = new CvString(usbDevice); _ptr = DepthAIInvoke.depthaiDeviceCreate(cvString, usb2Mode); } public CNNHostPipeline CreatePipeline(string jsonConfigStr) { using CvString cvString = new CvString(jsonConfigStr); IntPtr hostedPipelineSharedPtr = IntPtr.Zero; IntPtr ptr = DepthAIInvoke.depthaiDeviceCreatePipeline(_ptr, cvString, ref hostedPipelineSharedPtr); return new CNNHostPipeline(hostedPipelineSharedPtr, ptr); } protected override void DisposeObject() { if (_ptr != IntPtr.Zero) { DepthAIInvoke.depthaiDeviceRelease(ref _ptr); } } } public class FrameMetadata : UnmanagedObject { public string CameraName { get { using CvString cvString = new CvString(); DepthAIInvoke.cveFrameMetadataGetCameraName(_ptr, cvString); return cvString.ToString(); } } public int SequenceNum => DepthAIInvoke.cveFrameMetadataGetSequenceNum(_ptr); public int InstanceNum => DepthAIInvoke.cveFrameMetadataGetInstanceNum(_ptr); public int Category => DepthAIInvoke.cveFrameMetadataGetCategory(_ptr); public uint Stride => DepthAIInvoke.cveFrameMetadataGetStride(_ptr); public uint FrameBytesPP => DepthAIInvoke.cveFrameMetadataGetFrameBytesPP(_ptr); public uint FrameHeight => DepthAIInvoke.cveFrameMetadataGetFrameHeight(_ptr); public uint FrameWidth => DepthAIInvoke.cveFrameMetadataGetFrameWidth(_ptr); public int FrameType => DepthAIInvoke.cveFrameMetadataGetFrameType(_ptr); public double Timestamp => DepthAIInvoke.cveFrameMetadataGetTimestamp(_ptr); public bool IsValid => DepthAIInvoke.cveFrameMetadataIsValid(_ptr); public FrameMetadata() { _ptr = DepthAIInvoke.depthaiFrameMetadataCreate(); } protected override void DisposeObject() { if (_ptr != IntPtr.Zero) { DepthAIInvoke.depthaiFrameMetadataRelease(ref _ptr); } } } public class HostDataPacket { private IntPtr _ptr; public int[] Dimension { get { using VectorOfInt vectorOfInt = new VectorOfInt(); DepthAIInvoke.depthaiHostDataPacketGetDimensions(_ptr, vectorOfInt); return vectorOfInt.ToArray(); } } public string StreamName { get { using CvString cvString = new CvString(); DepthAIInvoke.cveHostDataPacketGetStreamName(_ptr, cvString); return cvString.ToString(); } } public int Size => DepthAIInvoke.cveHostDataPacketSize(_ptr); public IntPtr Data => DepthAIInvoke.cveHostDataPacketGetData(_ptr); public int ElemSize => DepthAIInvoke.cveHostDataPacketGetElemSize(_ptr); public FrameMetadata GetFrameMetadata() { FrameMetadata frameMetadata = new FrameMetadata(); if (DepthAIInvoke.depthaiHostDataPacketGetMetadata(_ptr, frameMetadata.Ptr)) { return frameMetadata; } frameMetadata.Dispose(); return null; } public bool GetPreviewOut(Mat preview) { if (StreamName.Contains("previewout")) { int[] dimension = Dimension; if (dimension[0] == 3) { int num = dimension[2] * ElemSize; using Mat mat = new Mat(new Size(dimension[2], dimension[1]), DepthType.Cv8U, 1, Data, num); using Mat mat2 = new Mat(new Size(dimension[2], dimension[1]), DepthType.Cv8U, 1, new IntPtr(Data.ToInt64() + dimension[1] * num), num); using Mat mat3 = new Mat(new Size(dimension[2], dimension[1]), DepthType.Cv8U, 1, new IntPtr(Data.ToInt64() + dimension[1] * num * 2), num); using VectorOfMat mv = new VectorOfMat(mat, mat2, mat3); CvInvoke.Merge(mv, preview); return true; } } return false; } internal HostDataPacket(IntPtr ptr) { _ptr = ptr; } } public class NNetAndDataPackets : UnmanagedObject { public HostDataPacket[] HostDataPackets { get { IntPtr[] array = new IntPtr[DepthAIInvoke.depthaiNNetAndDataPacketsGetHostDataPacketCount(_ptr)]; GCHandle gCHandle = GCHandle.Alloc(array, GCHandleType.Pinned); DepthAIInvoke.depthaiNNetAndDataPacketsGetHostDataPacketArr(_ptr, gCHandle.AddrOfPinnedObject()); gCHandle.Free(); return Array.ConvertAll(array, (IntPtr ptr) => new HostDataPacket(ptr)); } } public NNetPacket[] NNetPackets { get { IntPtr[] array = new IntPtr[DepthAIInvoke.depthaiNNetAndDataPacketsGetNNetCount(_ptr)]; GCHandle gCHandle = GCHandle.Alloc(array, GCHandleType.Pinned); DepthAIInvoke.depthaiNNetAndDataPacketsGetNNetArr(_ptr, gCHandle.AddrOfPinnedObject()); gCHandle.Free(); return Array.ConvertAll(array, (IntPtr ptr) => new NNetPacket(ptr)); } } internal NNetAndDataPackets(IntPtr ptr) { _ptr = ptr; } protected override void DisposeObject() { if (_ptr != IntPtr.Zero) { DepthAIInvoke.depthaiNNetAndDataPacketsRelease(ref _ptr); } } } public class NNetPacket { public struct Detection { public uint Label; public float Confidence; public float XMin; public float YMin; public float XMax; public float YMax; public float DepthX; public float DepthY; public float DepthZ; } private IntPtr _ptr; public Detection[] Detections { get { Detection[] array = new Detection[DepthAIInvoke.depthaiNNetPacketGetDetectedObjectsCount(_ptr)]; GCHandle gCHandle = GCHandle.Alloc(array, GCHandleType.Pinned); DepthAIInvoke.depthaiNNetPacketGetDetectedObjects(_ptr, gCHandle.AddrOfPinnedObject()); gCHandle.Free(); return array; } } internal NNetPacket(IntPtr ptr) { _ptr = ptr; } public FrameMetadata GetFrameMetadata() { FrameMetadata frameMetadata = new FrameMetadata(); if (DepthAIInvoke.depthaiNNetPacketGetMetadata(_ptr, frameMetadata.Ptr)) { return frameMetadata; } frameMetadata.Dispose(); return null; } } } namespace Emgu.CV.Hdf { public class HDF5 : SharedPtrObject { public HDF5(string fileName) { using CvString cvString = new CvString(fileName); _ptr = HdfInvoke.cveHDF5Create(cvString, ref _sharedPtr); } public void Close() { HdfInvoke.cveHDF5Close(_ptr); } public void GrCreate(string grLabel) { using CvString cvString = new CvString(grLabel); HdfInvoke.cveHDF5GrCreate(_ptr, cvString); } public bool HlExist(string label) { using CvString cvString = new CvString(label); return HdfInvoke.cveHDF5HlExists(_ptr, cvString); } public void DsRead(IOutputArray array, string dsLabel) { using CvString cvString = new CvString(dsLabel); using OutputArray outputArray = array.GetOutputArray(); HdfInvoke.cveHDF5DsRead(_ptr, outputArray, cvString); } public void DsWrite(IInputArray array, string dsLabel) { using CvString cvString = new CvString(dsLabel); using InputArray inputArray = array.GetInputArray(); HdfInvoke.cveHDF5DsWrite(_ptr, inputArray, cvString); } public void DsCreate(int rows, int cols, DepthType depthType, int channels, string dsLabel, int compressLevel = -1, VectorOfInt dimsChunks = null) { using CvString cvString = new CvString(dsLabel); HdfInvoke.cveHDF5DsCreate(_ptr, rows, cols, CvInvoke.MakeType(depthType, channels), cvString, compressLevel, dimsChunks); } public bool AtExists(string atLabel) { using CvString cvString = new CvString(atLabel); return HdfInvoke.cveHDF5AtExists(_ptr, cvString); } public void AtDelete(string atLabel) { using CvString cvString = new CvString(atLabel); HdfInvoke.cveHDF5AtDelete(_ptr, cvString); } public int AtReadInt(string atLabel) { int value = 0; using CvString cvString = new CvString(atLabel); HdfInvoke.cveHDF5AtReadInt(_ptr, ref value, cvString); return value; } public void AtWrite(int value, string atLabel) { using CvString cvString = new CvString(atLabel); HdfInvoke.cveHDF5AtWriteInt(_ptr, value, cvString); } public double AtReadDouble(string atLabel) { double value = 0.0; using CvString cvString = new CvString(atLabel); HdfInvoke.cveHDF5AtReadDouble(_ptr, ref value, cvString); return value; } public void AtWrite(double value, string atLabel) { using CvString cvString = new CvString(atLabel); HdfInvoke.cveHDF5AtWriteDouble(_ptr, value, cvString); } public string AtReadString(string atLabel) { using CvString cvString = new CvString(); using CvString cvString2 = new CvString(atLabel); HdfInvoke.cveHDF5AtReadString(_ptr, cvString, cvString2); return cvString.ToString(); } public void AtWrite(string value, string atLabel) { using CvString cvString = new CvString(value); using CvString cvString2 = new CvString(atLabel); HdfInvoke.cveHDF5AtWriteString(_ptr, cvString, cvString2); } public void AtReadArray(IOutputArray array, string atLabel) { using OutputArray outputArray = array.GetOutputArray(); using CvString cvString = new CvString(atLabel); HdfInvoke.cveHDF5AtReadArray(_ptr, outputArray, cvString); } public void AtWrite(IInputArray value, string atLabel) { using InputArray inputArray = value.GetInputArray(); using CvString cvString = new CvString(atLabel); HdfInvoke.cveHDF5AtWriteArray(_ptr, inputArray, cvString); } public void KpRead(VectorOfKeyPoint keypoints, string kpLabel, int offset = -1, int counts = -1) { using CvString cvString = new CvString(kpLabel); HdfInvoke.cveHDF5KpRead(_ptr, keypoints, cvString, offset, counts); } public void KpWrite(VectorOfKeyPoint keypoints, string atLabel, int offset = -1, int counts = -1) { using CvString cvString = new CvString(atLabel); HdfInvoke.cveHDF5KpWrite(_ptr, keypoints, cvString, offset, counts); } protected override void DisposeObject() { if (_sharedPtr != IntPtr.Zero) { HdfInvoke.cveHDF5Release(ref _sharedPtr); _ptr = IntPtr.Zero; } } } public static class HdfInvoke { static HdfInvoke() { CvInvoke.Init(); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveHDF5Create(IntPtr fileName, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveHDF5Release(ref IntPtr hdfPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveHDF5GrCreate(IntPtr hdf, IntPtr grlabel); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.U1)] internal static extern bool cveHDF5HlExists(IntPtr hdf, IntPtr label); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveHDF5DsCreate(IntPtr hdf, int rows, int cols, int type, IntPtr dslabel, int compresslevel, IntPtr dimsChunks); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveHDF5DsWrite(IntPtr hdf, IntPtr array, IntPtr dslabel); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveHDF5DsRead(IntPtr hdf, IntPtr array, IntPtr dslabel); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.U1)] internal static extern bool cveHDF5AtExists(IntPtr hdf, IntPtr atlabel); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveHDF5AtDelete(IntPtr hdf, IntPtr atlabel); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveHDF5AtWriteInt(IntPtr hdf, int value, IntPtr atlabel); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveHDF5AtReadInt(IntPtr hdf, ref int value, IntPtr atlabel); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveHDF5AtWriteDouble(IntPtr hdf, double value, IntPtr atlabel); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveHDF5AtReadDouble(IntPtr hdf, ref double value, IntPtr atlabel); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveHDF5AtWriteString(IntPtr hdf, IntPtr value, IntPtr atlabel); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveHDF5AtReadString(IntPtr hdf, IntPtr value, IntPtr atlabel); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveHDF5AtReadArray(IntPtr hdf, IntPtr value, IntPtr atlabel); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveHDF5AtWriteArray(IntPtr hdf, IntPtr value, IntPtr atlabel); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveHDF5KpRead(IntPtr hdf, IntPtr keypoints, IntPtr kplabel, int offset, int counts); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveHDF5KpWrite(IntPtr hdf, IntPtr keypoints, IntPtr kplabel, int offset, int counts); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveHDF5Close(IntPtr hdf); } } namespace Emgu.CV.Ccm { public class ColorCorrectionModel : UnmanagedObject { public enum ColorChecker { Macbeth, Vinyl, DigitalSG } public enum CcmType { Ccm3x3, Ccm4x3 } public enum DistanceType { Cie76, Cie94GraphicArts, Cie94Textiles, Cie2000, Cmc1To1, Cmc2To1, Rgb, Rgbl } public enum LinearType { Identity, Gamma, ColorPolyFit, ColorLogPolyFit, GrayPolyFit, GrayLogPolyFit } private bool _needDispose; public double Loss => CcmInvoke.cveColorCorrectionModelGetLoss(_ptr); internal ColorCorrectionModel(IntPtr ptr, bool needDispose) { _ptr = ptr; _needDispose = needDispose; } public ColorCorrectionModel(Mat src, ColorChecker color) { _ptr = CcmInvoke.cveColorCorrectionModelCreate(src, color); _needDispose = true; } protected override void DisposeObject() { if (_ptr != IntPtr.Zero && _needDispose) { CcmInvoke.cveColorCorrectionModelRelease(ref _ptr); } } public void SetCcmType(CcmType value) { CcmInvoke.cveColorCorrectionModelSetCcmType(_ptr, value); } public void SetDistanceType(DistanceType value) { CcmInvoke.cveColorCorrectionModelSetDistanceType(_ptr, value); } public void SetLinearType(LinearType value) { CcmInvoke.cveColorCorrectionModelSetLinearType(_ptr, value); } public void SetLinearGamma(double value) { CcmInvoke.cveColorCorrectionModelSetLinearGamma(_ptr, value); } public void SetLinearDegree(int value) { CcmInvoke.cveColorCorrectionModelSetLinearDegree(_ptr, value); } public void SetWeightCoeff(double value) { CcmInvoke.cveColorCorrectionModelSetWeightCoeff(_ptr, value); } public void SetMaxCount(int value) { CcmInvoke.cveColorCorrectionModelSetMaxCount(_ptr, value); } } public static class CcmInvoke { static CcmInvoke() { CvInvoke.Init(); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveColorCorrectionModelCreate(IntPtr src, ColorCorrectionModel.ColorChecker constcolor); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveColorCorrectionModelRelease(ref IntPtr ccm); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveColorCorrectionModelSetCcmType(IntPtr obj, ColorCorrectionModel.CcmType val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern double cveColorCorrectionModelGetLoss(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveColorCorrectionModelSetDistanceType(IntPtr obj, ColorCorrectionModel.DistanceType val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveColorCorrectionModelSetLinearType(IntPtr obj, ColorCorrectionModel.LinearType val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveColorCorrectionModelSetLinearGamma(IntPtr obj, double val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveColorCorrectionModelSetLinearDegree(IntPtr obj, int val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveColorCorrectionModelSetWeightCoeff(IntPtr obj, double val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveColorCorrectionModelSetMaxCount(IntPtr obj, int val); } } namespace Emgu.CV.Mcc { public class CChecker : SharedPtrObject { public enum TypeChart { MCC24, SG140, Vinyl18 } private bool _needDispose; public PointF[] Box { get { using VectorOfPointF vectorOfPointF = new VectorOfPointF(); MccInvoke.cveCCheckerGetBox(_ptr, vectorOfPointF); return vectorOfPointF.ToArray(); } set { using VectorOfPointF vectorOfPointF = new VectorOfPointF(value); MccInvoke.cveCCheckerSetBox(_ptr, vectorOfPointF); } } public PointF Center { get { PointF center = default(PointF); MccInvoke.cveCCheckerGetCenter(_ptr, ref center); return center; } set { MccInvoke.cveCCheckerSetCenter(_ptr, ref value); } } public TypeChart Target { get { return MccInvoke.cveCCheckerGetTarget(_ptr); } set { MccInvoke.cveCCheckerSetTarget(_ptr, value); } } public float Cost { get { return MccInvoke.cveCCheckerGetCost(_ptr); } set { MccInvoke.cveCCheckerSetCost(_ptr, value); } } internal CChecker(IntPtr ptr, bool needDispose) { _ptr = ptr; _needDispose = needDispose; } public CChecker() { _ptr = MccInvoke.cveCCheckerCreate(ref _sharedPtr); _needDispose = true; } public void GetChartsRGB(IOutputArray chartsRgb) { using OutputArray outputArray = chartsRgb.GetOutputArray(); MccInvoke.cveCCheckerGetChartsRGB(_ptr, outputArray); } public void SetChartsRGB(Mat chartsRgb) { MccInvoke.cveCCheckerSetChartsRGB(_ptr, chartsRgb); } protected override void DisposeObject() { if (_sharedPtr != IntPtr.Zero && _needDispose) { MccInvoke.cveCCheckerRelease(ref _sharedPtr); _ptr = IntPtr.Zero; } } } public static class MccInvoke { static MccInvoke() { CvInvoke.Init(); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveCCheckerCreate(ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveCCheckerRelease(ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveCCheckerGetBox(IntPtr checker, IntPtr box); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveCCheckerSetBox(IntPtr checker, IntPtr box); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveCCheckerGetCenter(IntPtr checker, ref PointF center); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveCCheckerSetCenter(IntPtr checker, ref PointF center); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveCCheckerGetChartsRGB(IntPtr checker, IntPtr chartsRgb); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveCCheckerSetChartsRGB(IntPtr checker, IntPtr chartsRgb); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern CChecker.TypeChart cveCCheckerGetTarget(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveCCheckerSetTarget(IntPtr obj, CChecker.TypeChart val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern float cveCCheckerGetCost(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveCCheckerSetCost(IntPtr obj, float val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveCCheckerDetectorCreate(ref IntPtr algorithm, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.U1)] internal static extern bool cveCCheckerDetectorProcess(IntPtr detector, IntPtr image, CChecker.TypeChart chartType, int nc, [MarshalAs(UnmanagedType.U1)] bool useNet, IntPtr param); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveCCheckerDetectorGetBestColorChecker(IntPtr detector); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveCCheckerDetectorRelease(ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveCCheckerDrawCreate(IntPtr pChecker, ref MCvScalar color, int thickness, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveCCheckerDrawDraw(IntPtr ccheckerDraw, IntPtr img); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveCCheckerDrawRelease(ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveCCheckerDetectorParametersCreate(); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveCCheckerDetectorParametersRelease(ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int cveDetectorParametersGetAdaptiveThreshWinSizeMin(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveDetectorParametersSetAdaptiveThreshWinSizeMin(IntPtr obj, int val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int cveDetectorParametersGetAdaptiveThreshWinSizeMax(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveDetectorParametersSetAdaptiveThreshWinSizeMax(IntPtr obj, int val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int cveDetectorParametersGetAdaptiveThreshWinSizeStep(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveDetectorParametersSetAdaptiveThreshWinSizeStep(IntPtr obj, int val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern double cveDetectorParametersGetAdaptiveThreshConstant(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveDetectorParametersSetAdaptiveThreshConstant(IntPtr obj, double val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern double cveDetectorParametersGetMinContoursAreaRate(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveDetectorParametersSetMinContoursAreaRate(IntPtr obj, double val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern double cveDetectorParametersGetMinContoursArea(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveDetectorParametersSetMinContoursArea(IntPtr obj, double val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern double cveDetectorParametersGetConfidenceThreshold(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveDetectorParametersSetConfidenceThreshold(IntPtr obj, double val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern double cveDetectorParametersGetMinContourSolidity(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveDetectorParametersSetMinContourSolidity(IntPtr obj, double val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern double cveDetectorParametersGetFindCandidatesApproxPolyDPEpsMultiplier(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveDetectorParametersSetFindCandidatesApproxPolyDPEpsMultiplier(IntPtr obj, double val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int cveDetectorParametersGetBorderWidth(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveDetectorParametersSetBorderWidth(IntPtr obj, int val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern float cveDetectorParametersGetB0factor(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveDetectorParametersSetB0factor(IntPtr obj, float val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern float cveDetectorParametersGetMaxError(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveDetectorParametersSetMaxError(IntPtr obj, float val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int cveDetectorParametersGetMinContourPointsAllowed(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveDetectorParametersSetMinContourPointsAllowed(IntPtr obj, int val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int cveDetectorParametersGetMinContourLengthAllowed(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveDetectorParametersSetMinContourLengthAllowed(IntPtr obj, int val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int cveDetectorParametersGetMinInterContourDistance(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveDetectorParametersSetMinInterContourDistance(IntPtr obj, int val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int cveDetectorParametersGetMinInterCheckerDistance(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveDetectorParametersSetMinInterCheckerDistance(IntPtr obj, int val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int cveDetectorParametersGetMinImageSize(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveDetectorParametersSetMinImageSize(IntPtr obj, int val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern uint cveDetectorParametersGetMinGroupSize(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveDetectorParametersSetMinGroupSize(IntPtr obj, uint val); } public class CCheckerDetector : SharedPtrObject, IAlgorithm { private IntPtr _algorithmPtr; public IntPtr AlgorithmPtr => _algorithmPtr; public CChecker BestColorChecker { get { IntPtr intPtr = MccInvoke.cveCCheckerDetectorGetBestColorChecker(_ptr); if (intPtr == IntPtr.Zero) { return null; } return new CChecker(intPtr, needDispose: false); } } public CCheckerDetector() { _ptr = MccInvoke.cveCCheckerDetectorCreate(ref _algorithmPtr, ref _sharedPtr); } protected override void DisposeObject() { if (_sharedPtr != IntPtr.Zero) { MccInvoke.cveCCheckerDetectorRelease(ref _sharedPtr); _ptr = IntPtr.Zero; } } public bool Process(IInputArray image, CChecker.TypeChart chartType, int nc = 1, bool useNet = false, DetectorParameters p = null) { using InputArray inputArray = image.GetInputArray(); return MccInvoke.cveCCheckerDetectorProcess(_ptr, inputArray, chartType, nc, useNet, (p != null) ? ((IntPtr)p) : IntPtr.Zero); } } public class CCheckerDraw : SharedPtrObject { public CCheckerDraw(CChecker cchecker, MCvScalar color, int thickness = 2) { _ptr = MccInvoke.cveCCheckerDrawCreate(cchecker, ref color, thickness, ref _sharedPtr); } public void Draw(IInputOutputArray img) { using InputOutputArray inputOutputArray = img.GetInputOutputArray(); MccInvoke.cveCCheckerDrawDraw(_ptr, inputOutputArray); } protected override void DisposeObject() { if (_sharedPtr != IntPtr.Zero) { MccInvoke.cveCCheckerDrawRelease(ref _sharedPtr); _ptr = IntPtr.Zero; } } } public class DetectorParameters : UnmanagedObject { public int AdaptiveThreshWinSizeMin { get { return MccInvoke.cveDetectorParametersGetAdaptiveThreshWinSizeMin(_ptr); } set { MccInvoke.cveDetectorParametersSetAdaptiveThreshWinSizeMin(_ptr, value); } } public int AdaptiveThreshWinSizeMax { get { return MccInvoke.cveDetectorParametersGetAdaptiveThreshWinSizeMax(_ptr); } set { MccInvoke.cveDetectorParametersSetAdaptiveThreshWinSizeMax(_ptr, value); } } public int AdaptiveThreshWinSizeStep { get { return MccInvoke.cveDetectorParametersGetAdaptiveThreshWinSizeStep(_ptr); } set { MccInvoke.cveDetectorParametersSetAdaptiveThreshWinSizeStep(_ptr, value); } } public double AdaptiveThreshConstant { get { return MccInvoke.cveDetectorParametersGetAdaptiveThreshConstant(_ptr); } set { MccInvoke.cveDetectorParametersSetAdaptiveThreshConstant(_ptr, value); } } public double MinContoursAreaRate { get { return MccInvoke.cveDetectorParametersGetMinContoursAreaRate(_ptr); } set { MccInvoke.cveDetectorParametersSetMinContoursAreaRate(_ptr, value); } } public double MinContoursArea { get { return MccInvoke.cveDetectorParametersGetMinContoursArea(_ptr); } set { MccInvoke.cveDetectorParametersSetMinContoursArea(_ptr, value); } } public double ConfidenceThreshold { get { return MccInvoke.cveDetectorParametersGetConfidenceThreshold(_ptr); } set { MccInvoke.cveDetectorParametersSetConfidenceThreshold(_ptr, value); } } public double MinContourSolidity { get { return MccInvoke.cveDetectorParametersGetMinContourSolidity(_ptr); } set { MccInvoke.cveDetectorParametersSetMinContourSolidity(_ptr, value); } } public double FindCandidatesApproxPolyDPEpsMultiplier { get { return MccInvoke.cveDetectorParametersGetFindCandidatesApproxPolyDPEpsMultiplier(_ptr); } set { MccInvoke.cveDetectorParametersSetFindCandidatesApproxPolyDPEpsMultiplier(_ptr, value); } } public int BorderWidth { get { return MccInvoke.cveDetectorParametersGetBorderWidth(_ptr); } set { MccInvoke.cveDetectorParametersSetBorderWidth(_ptr, value); } } public float B0factor { get { return MccInvoke.cveDetectorParametersGetB0factor(_ptr); } set { MccInvoke.cveDetectorParametersSetB0factor(_ptr, value); } } public float MaxError { get { return MccInvoke.cveDetectorParametersGetMaxError(_ptr); } set { MccInvoke.cveDetectorParametersSetMaxError(_ptr, value); } } public int MinContourPointsAllowed { get { return MccInvoke.cveDetectorParametersGetMinContourPointsAllowed(_ptr); } set { MccInvoke.cveDetectorParametersSetMinContourPointsAllowed(_ptr, value); } } public int MinContourLengthAllowed { get { return MccInvoke.cveDetectorParametersGetMinContourLengthAllowed(_ptr); } set { MccInvoke.cveDetectorParametersSetMinContourLengthAllowed(_ptr, value); } } public int MinInterContourDistance { get { return MccInvoke.cveDetectorParametersGetMinInterContourDistance(_ptr); } set { MccInvoke.cveDetectorParametersSetMinInterContourDistance(_ptr, value); } } public int MinInterCheckerDistance { get { return MccInvoke.cveDetectorParametersGetMinInterCheckerDistance(_ptr); } set { MccInvoke.cveDetectorParametersSetMinInterCheckerDistance(_ptr, value); } } public int MinImageSize { get { return MccInvoke.cveDetectorParametersGetMinImageSize(_ptr); } set { MccInvoke.cveDetectorParametersSetMinImageSize(_ptr, value); } } public uint MinGroupSize { get { return MccInvoke.cveDetectorParametersGetMinGroupSize(_ptr); } set { MccInvoke.cveDetectorParametersSetMinGroupSize(_ptr, value); } } public DetectorParameters() { _ptr = MccInvoke.cveCCheckerDetectorParametersCreate(); } protected override void DisposeObject() { if (_ptr != IntPtr.Zero) { MccInvoke.cveCCheckerDetectorParametersRelease(ref _ptr); } } } } namespace Emgu.CV.Rapid { public interface ITracker { IntPtr TrackerPtr { get; } } public class Rapid : SharedPtrObject, ITracker, IAlgorithm { private IntPtr _trackerPtr; private IntPtr _algorithmPtr; public IntPtr TrackerPtr => _trackerPtr; public IntPtr AlgorithmPtr => _algorithmPtr; public Rapid(IInputArray pts3d, IInputArray tris) { using InputArray inputArray = pts3d.GetInputArray(); using InputArray inputArray2 = tris.GetInputArray(); _ptr = RapidInvoke.cveRapidCreate(inputArray, inputArray2, ref _trackerPtr, ref _algorithmPtr, ref _sharedPtr); } protected override void DisposeObject() { if (_sharedPtr != IntPtr.Zero) { RapidInvoke.cveRapidRelease(ref _sharedPtr); _ptr = IntPtr.Zero; _algorithmPtr = IntPtr.Zero; _trackerPtr = IntPtr.Zero; } } } public class OLSTracker : SharedPtrObject, ITracker, IAlgorithm { private IntPtr _trackerPtr; private IntPtr _algorithmPtr; public IntPtr TrackerPtr => _trackerPtr; public IntPtr AlgorithmPtr => _algorithmPtr; public OLSTracker(IInputArray pts3d, IInputArray tris, int histBins = 8, byte sobelThresh = 10) { using InputArray inputArray = pts3d.GetInputArray(); using InputArray inputArray2 = tris.GetInputArray(); _ptr = RapidInvoke.cveOLSTrackerCreate(inputArray, inputArray2, histBins, sobelThresh, ref _trackerPtr, ref _algorithmPtr, ref _sharedPtr); } protected override void DisposeObject() { if (_sharedPtr != IntPtr.Zero) { RapidInvoke.cveOLSTrackerRelease(ref _sharedPtr); _ptr = IntPtr.Zero; _algorithmPtr = IntPtr.Zero; _trackerPtr = IntPtr.Zero; } } } public static class RapidInvoke { static RapidInvoke() { CvInvoke.Init(); } public static void DrawCorrespondencies(IInputOutputArray bundle, IInputArray cols, IInputArray colors = null) { using InputOutputArray inputOutputArray = bundle.GetInputOutputArray(); using InputArray inputArray = cols.GetInputArray(); using InputArray inputArray2 = ((colors == null) ? InputArray.GetEmpty() : colors.GetInputArray()); cveDrawCorrespondencies(inputOutputArray, inputArray, inputArray2); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveDrawCorrespondencies(IntPtr bundle, IntPtr cols, IntPtr colors); public static void DrawSearchLines(IInputOutputArray img, IInputArray locations, MCvScalar color) { using InputOutputArray inputOutputArray = img.GetInputOutputArray(); using InputArray inputArray = locations.GetInputArray(); cveDrawSearchLines(inputOutputArray, inputArray, ref color); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveDrawSearchLines(IntPtr img, IntPtr locations, ref MCvScalar color); public static void DrawWireframe(IInputOutputArray img, IInputArray pts2d, IInputArray tris, MCvScalar color, LineType type = LineType.EightConnected, bool cullBackface = false) { using InputOutputArray inputOutputArray = img.GetInputOutputArray(); using InputArray inputArray = pts2d.GetInputArray(); using InputArray inputArray2 = tris.GetInputArray(); cveDrawWireframe(inputOutputArray, inputArray, inputArray2, ref color, type, cullBackface); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveDrawWireframe(IntPtr img, IntPtr pts2d, IntPtr tris, ref MCvScalar color, LineType type, [MarshalAs(UnmanagedType.U1)] bool cullBackface); public static void ExtractControlPoints(int num, int len, IInputArray pts3d, IInputArray rvec, IInputArray tvec, IInputArray K, Size imsize, IInputArray tris, IOutputArray ctl2d, IOutputArray ctl3d) { using InputArray inputArray = pts3d.GetInputArray(); using InputArray inputArray2 = rvec.GetInputArray(); using InputArray inputArray3 = tvec.GetInputArray(); using InputArray inputArray4 = K.GetInputArray(); using InputArray inputArray5 = tris.GetInputArray(); using OutputArray outputArray = ctl2d.GetOutputArray(); using OutputArray outputArray2 = ctl3d.GetOutputArray(); cveExtractControlPoints(num, len, inputArray, inputArray2, inputArray3, inputArray4, ref imsize, inputArray5, outputArray, outputArray2); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveExtractControlPoints(int num, int len, IntPtr pts3d, IntPtr rvec, IntPtr tvec, IntPtr K, ref Size imsize, IntPtr tris, IntPtr ctl2d, IntPtr ctl3d); public static void ExtractLineBundle(int len, IInputArray ctl2d, IInputArray img, IOutputArray bundle, IOutputArray srcLocations) { using InputArray inputArray = ctl2d.GetInputArray(); using InputArray inputArray2 = img.GetInputArray(); using OutputArray outputArray = bundle.GetOutputArray(); using OutputArray outputArray2 = srcLocations.GetOutputArray(); cveExtractLineBundle(len, inputArray, inputArray2, outputArray, outputArray2); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveExtractLineBundle(int len, IntPtr ctl2d, IntPtr img, IntPtr bundle, IntPtr srcLocations); public static void FindCorrespondencies(IInputArray bundle, IOutputArray cols, IOutputArray response) { using InputArray inputArray = bundle.GetInputArray(); using OutputArray outputArray = cols.GetOutputArray(); using OutputArray outputArray2 = response.GetOutputArray(); cveFindCorrespondencies(inputArray, outputArray, outputArray2); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveFindCorrespondencies(IntPtr bundle, IntPtr cols, IntPtr response); public static void ConvertCorrespondencies(IInputArray cols, IInputArray srcLocations, IOutputArray pts2d, IInputOutputArray pts3d = null, IInputArray mask = null) { using InputArray inputArray = cols.GetInputArray(); using InputArray inputArray2 = srcLocations.GetInputArray(); using OutputArray outputArray = pts2d.GetOutputArray(); using InputOutputArray inputOutputArray = pts3d.GetInputOutputArray(); using InputArray inputArray3 = ((mask == null) ? InputArray.GetEmpty() : mask.GetInputArray()); cveConvertCorrespondencies(inputArray, inputArray2, outputArray, inputOutputArray, inputArray3); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveConvertCorrespondencies(IntPtr cols, IntPtr srcLocations, IntPtr pts2d, IntPtr pts3d, IntPtr mask); public static float Rapid(IInputArray img, int num, int len, IInputArray pts3d, IInputArray tris, IInputArray K, IInputOutputArray rvec, IInputOutputArray tvec, ref double rmsd) { using InputArray inputArray = img.GetInputArray(); using InputArray inputArray2 = pts3d.GetInputArray(); using InputArray inputArray3 = tris.GetInputArray(); using InputArray inputArray4 = K.GetInputArray(); using InputOutputArray inputOutputArray = rvec.GetInputOutputArray(); using InputOutputArray inputOutputArray2 = tvec.GetInputOutputArray(); return cveRapid(inputArray, num, len, inputArray2, inputArray3, inputArray4, inputOutputArray, inputOutputArray2, ref rmsd); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern float cveRapid(IntPtr img, int num, int len, IntPtr pts3d, IntPtr tris, IntPtr K, IntPtr rvec, IntPtr tvec, ref double rmsd); public static float Compute(this ITracker tracker, IInputArray img, int num, int len, IInputArray K, IInputOutputArray rvec, IInputOutputArray tvec, MCvTermCriteria termcrit) { using InputArray inputArray = img.GetInputArray(); using InputArray inputArray2 = K.GetInputArray(); using InputOutputArray inputOutputArray = rvec.GetInputOutputArray(); using InputOutputArray inputOutputArray2 = tvec.GetInputOutputArray(); return cveTrackerCompute(tracker.TrackerPtr, inputArray, num, len, inputArray2, inputOutputArray, inputOutputArray2, ref termcrit); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern float cveTrackerCompute(IntPtr tracker, IntPtr img, int num, int len, IntPtr K, IntPtr rvec, IntPtr tvec, ref MCvTermCriteria termcrit); public static void ClearState(this ITracker tracker) { cveTrackerClearState(tracker.TrackerPtr); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveTrackerClearState(IntPtr tracker); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveRapidCreate(IntPtr pts3d, IntPtr tris, ref IntPtr tracker, ref IntPtr algorithm, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveRapidRelease(ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveOLSTrackerCreate(IntPtr pts3d, IntPtr tris, int histBins, byte sobelThresh, ref IntPtr tracker, ref IntPtr algorithm, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveOLSTrackerRelease(ref IntPtr sharedPtr); } } namespace Emgu.CV.IntensityTransform { public static class IntensityTransformInvoke { static IntensityTransformInvoke() { CvInvoke.Init(); } public static void LogTransform(Mat input, Mat output) { cveLogTransform(input, output); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveLogTransform(IntPtr input, IntPtr output); public static void GammaCorrection(Mat input, Mat output, float gamma) { cveGammaCorrection(input, output, gamma); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveGammaCorrection(IntPtr input, IntPtr output, float gamma); public static void Autoscaling(Mat input, Mat output) { cveAutoscaling(input, output); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveAutoscaling(IntPtr input, IntPtr output); public static void ContrastStretching(Mat input, Mat output, int r1, int s1, int r2, int s2) { cveContrastStretching(input, output, r1, s1, r2, s2); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveContrastStretching(IntPtr input, IntPtr output, int r1, int s1, int r2, int s2); public static void BIMEF(IInputArray input, IOutputArray output, float mu = 0.5f, float a = -0.3293f, float b = 1.1258f) { using InputArray inputArray = input.GetInputArray(); using OutputArray outputArray = output.GetOutputArray(); cveBIMEF(inputArray, outputArray, mu, a, b); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveBIMEF(IntPtr input, IntPtr output, float mu, float a, float b); public static void BIMEF(IInputArray input, IOutputArray output, float k, float mu, float a, float b) { using InputArray inputArray = input.GetInputArray(); using OutputArray outputArray = output.GetOutputArray(); cveBIMEF2(inputArray, outputArray, k, mu, a, b); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveBIMEF2(IntPtr input, IntPtr output, float k, float mu, float a, float b); } } namespace Emgu.CV.DnnSuperres { public class DnnSuperResImpl : UnmanagedObject { public int Scale => DnnSuperresInvoke.cveDnnSuperResImplGetScale(_ptr); public string Algorithm { get { using CvString cvString = new CvString(); DnnSuperresInvoke.cveDnnSuperResImplGetAlgorithm(_ptr, cvString); return cvString.ToString(); } } public DnnSuperResImpl() { _ptr = DnnSuperresInvoke.cveDnnSuperResImplCreate(); } public DnnSuperResImpl(string algorithm, int scale) { using CvString cvString = new CvString(algorithm); _ptr = DnnSuperresInvoke.cveDnnSuperResImplCreate2(cvString, scale); } public void ReadModel(string path) { using CvString cvString = new CvString(path); DnnSuperresInvoke.cveDnnSuperResImplReadModel1(_ptr, cvString); } public void ReadModel(string weight, string definition) { using CvString cvString = new CvString(weight); using CvString cvString2 = new CvString(definition); DnnSuperresInvoke.cveDnnSuperResImplReadModel2(_ptr, cvString, cvString2); } public void SetModel(string algorithm, int scale) { using CvString cvString = new CvString(algorithm); DnnSuperresInvoke.cveDnnSuperResImplSetModel(_ptr, cvString, scale); } public void Upsample(IInputArray img, IOutputArray result) { using InputArray inputArray = img.GetInputArray(); using OutputArray outputArray = result.GetOutputArray(); DnnSuperresInvoke.cveDnnSuperResImplUpsample(_ptr, inputArray, outputArray); } public void SetPreferableBackend(Emgu.CV.Dnn.Backend backendId) { DnnSuperresInvoke.cveDnnSuperResImplSetPreferableBackend(_ptr, backendId); } public void SetPreferableTarget(Target targetId) { DnnSuperresInvoke.cveDnnSuperResImplSetPreferableTarget(_ptr, targetId); } protected override void DisposeObject() { if (_ptr != IntPtr.Zero) { DnnSuperresInvoke.cveDnnSuperResImplRelease(ref _ptr); } } } internal static class DnnSuperresInvoke { static DnnSuperresInvoke() { CvInvoke.Init(); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveDnnSuperResImplCreate(); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveDnnSuperResImplCreate2(IntPtr algorithm, int scale); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveDnnSuperResImplSetModel(IntPtr dnnSuperRes, IntPtr algorithm, int scale); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveDnnSuperResImplReadModel1(IntPtr dnnSuperRes, IntPtr path); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveDnnSuperResImplReadModel2(IntPtr dnnSuperRes, IntPtr weights, IntPtr definition); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveDnnSuperResImplUpsample(IntPtr dnnSuperRes, IntPtr img, IntPtr result); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveDnnSuperResImplRelease(ref IntPtr dnnSuperRes); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int cveDnnSuperResImplGetScale(IntPtr dnnSuperRes); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveDnnSuperResImplGetAlgorithm(IntPtr dnnSuperRes, IntPtr algorithm); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveDnnSuperResImplSetPreferableBackend(IntPtr dnnSuperRes, Emgu.CV.Dnn.Backend backendId); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveDnnSuperResImplSetPreferableTarget(IntPtr dnnSuperRes, Target targetId); } } namespace Emgu.CV.PpfMatch3d { public class ICP : UnmanagedObject { public enum SamplingType { Uniform, Gelfand } public ICP(int iterations, float tolerance = 0.05f, float rejectionScale = 2.5f, int numLevels = 6, SamplingType sampleType = SamplingType.Uniform, int numMaxCorr = 1) { _ptr = PpfMatch3dInvoke.cveICPCreate(iterations, tolerance, rejectionScale, numLevels, sampleType, numMaxCorr); } protected override void DisposeObject() { if (IntPtr.Zero != _ptr) { PpfMatch3dInvoke.cveICPRelease(ref _ptr); } } public int RegisterModelToScene(Mat srcPC, Mat dstPC, ref double residual, Mat pose) { return PpfMatch3dInvoke.cveICPRegisterModelToScene(_ptr, srcPC, dstPC, ref residual, pose); } public int RegisterModelToScene(Mat srcPC, Mat dstPC, VectorOfPose3D poses) { return PpfMatch3dInvoke.cveICPRegisterModelToScene2(_ptr, srcPC, dstPC, poses); } } public static class PpfMatch3dInvoke { static PpfMatch3dInvoke() { CvInvoke.Init(); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveICPCreate(int iterations, float tolerance, float rejectionScale, int numLevels, ICP.SamplingType sampleType, int numMaxCorr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveICPRelease(ref IntPtr icp); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int cveICPRegisterModelToScene(IntPtr icp, IntPtr srcPC, IntPtr dstPC, ref double residual, IntPtr pose); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int cveICPRegisterModelToScene2(IntPtr icp, IntPtr srcPC, IntPtr dstPC, IntPtr poses); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cvePose3DCreate(); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cvePose3DUpdatePose(IntPtr pose3d, IntPtr pose); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cvePose3DRelease(ref IntPtr icp); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cvePose3DGetT(IntPtr pose3d, ref MCvPoint3D64f t); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cvePose3DSetT(IntPtr pose3d, ref MCvPoint3D64f t); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cvePose3DGetQ(IntPtr pose3d, ref MCvScalar q); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cvePose3DSetQ(IntPtr pose3d, ref MCvScalar q); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern double cvePose3DGetAlpha(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cvePose3DSetAlpha(IntPtr obj, double val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern double cvePose3DGetResidual(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cvePose3DSetResidual(IntPtr obj, double val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern double cvePose3DGetAngle(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cvePose3DSetAngle(IntPtr obj, double val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int cvePose3DGetModelIndex(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cvePose3DSetModelIndex(IntPtr obj, int val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int cvePose3DGetNumVotes(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cvePose3DSetNumVotes(IntPtr obj, int val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cvePPF3DDetectorCreate(double relativeSamplingStep, double relativeDistanceStep, double numAngles); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cvePPF3DDetectorRelease(ref IntPtr detector); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cvePPF3DDetectorTrainModel(IntPtr detector, IntPtr model); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cvePPF3DDetectorMatch(IntPtr detector, IntPtr scene, IntPtr results, double relativeSceneSampleStep, double relativeSceneDistance); public static void LoadPLYSimple(string fileName, int withNormals, IOutputArray result) { using CvString cvString = new CvString(fileName); using OutputArray outputArray = result.GetOutputArray(); cveLoadPLYSimple(cvString, withNormals, outputArray); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveLoadPLYSimple(IntPtr fileName, int withNormals, IntPtr result); public static void TransformPCPose(Mat pc, Mat pose, IOutputArray result) { using OutputArray outputArray = result.GetOutputArray(); cveTransformPCPose(pc, pose, outputArray); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveTransformPCPose(IntPtr pc, IntPtr pose, IntPtr result); } public class Pose3D : UnmanagedObject { private bool _needDispose = true; public MCvPoint3D64f T { get { MCvPoint3D64f t = default(MCvPoint3D64f); PpfMatch3dInvoke.cvePose3DGetT(_ptr, ref t); return t; } set { PpfMatch3dInvoke.cvePose3DSetT(_ptr, ref value); } } public MCvScalar Q { get { MCvScalar q = default(MCvScalar); PpfMatch3dInvoke.cvePose3DGetQ(_ptr, ref q); return q; } set { PpfMatch3dInvoke.cvePose3DSetQ(_ptr, ref value); } } public double Alpha { get { return PpfMatch3dInvoke.cvePose3DGetAlpha(_ptr); } set { PpfMatch3dInvoke.cvePose3DSetAlpha(_ptr, value); } } public double Residual { get { return PpfMatch3dInvoke.cvePose3DGetResidual(_ptr); } set { PpfMatch3dInvoke.cvePose3DSetResidual(_ptr, value); } } public double Angle { get { return PpfMatch3dInvoke.cvePose3DGetAngle(_ptr); } set { PpfMatch3dInvoke.cvePose3DSetAngle(_ptr, value); } } public int ModelIndex { get { return PpfMatch3dInvoke.cvePose3DGetModelIndex(_ptr); } set { PpfMatch3dInvoke.cvePose3DSetModelIndex(_ptr, value); } } public int NumVotes { get { return PpfMatch3dInvoke.cvePose3DGetNumVotes(_ptr); } set { PpfMatch3dInvoke.cvePose3DSetNumVotes(_ptr, value); } } public Pose3D() { _ptr = PpfMatch3dInvoke.cvePose3DCreate(); _needDispose = true; } internal Pose3D(IntPtr pose3dPtr, bool needDispose) { _ptr = pose3dPtr; _needDispose = needDispose; } public void UpdatePose(Mat pose) { PpfMatch3dInvoke.cvePose3DUpdatePose(_ptr, pose); } protected override void DisposeObject() { if (_needDispose && IntPtr.Zero != _ptr) { PpfMatch3dInvoke.cvePose3DRelease(ref _ptr); } } } public class PPF3DDetector : UnmanagedObject { public PPF3DDetector(double relativeSamplingStep = 0.05, double relativeDistanceStep = 0.05, double numAngles = 30.0) { _ptr = PpfMatch3dInvoke.cvePPF3DDetectorCreate(relativeSamplingStep, relativeDistanceStep, numAngles); } public void TrainModel(Mat model) { PpfMatch3dInvoke.cvePPF3DDetectorTrainModel(_ptr, model); } public void Match(Mat scene, VectorOfPose3D results, double relativeSceneSampleStep, double relativeSceneDistance) { PpfMatch3dInvoke.cvePPF3DDetectorMatch(_ptr, scene, results, relativeSceneSampleStep, relativeSceneDistance); } protected override void DisposeObject() { if (IntPtr.Zero != _ptr) { PpfMatch3dInvoke.cvePPF3DDetectorRelease(ref _ptr); } } } [Serializable] [DebuggerTypeProxy(typeof(DebuggerProxy))] public class VectorOfPose3D : UnmanagedVector { internal class DebuggerProxy { private VectorOfPose3D _v; public Pose3D[] Values { get { Pose3D[] array = new Pose3D[_v.Size]; for (int i = 0; i < array.Length; i++) { array[i] = _v[i]; } return array; } } public DebuggerProxy(VectorOfPose3D v) { _v = v; } } private readonly bool _needDispose; public override int Size => VectorOfPose3DGetSize(_ptr); public override IntPtr StartAddress => VectorOfPose3DGetStartAddress(_ptr); public override long Length => VectorOfPose3DGetMemorySize(_ptr); public Pose3D this[int index] { get { IntPtr element = IntPtr.Zero; VectorOfPose3DGetItemPtr(_ptr, index, ref element); return new Pose3D(element, needDispose: false); } } public static int SizeOfItemInBytes => VectorOfPose3DSizeOfItemInBytes(); static VectorOfPose3D() { CvInvoke.Init(); } public VectorOfPose3D() : this(VectorOfPose3DCreate(), needDispose: true) { } internal VectorOfPose3D(IntPtr ptr, bool needDispose) { _ptr = ptr; _needDispose = needDispose; } public VectorOfPose3D(int size) : this(VectorOfPose3DCreateSize(size), needDispose: true) { } public VectorOfPose3D(params Pose3D[] values) : this() { Push(values); } public void Clear() { VectorOfPose3DClear(_ptr); } public void Push(Pose3D value) { VectorOfPose3DPush(_ptr, value.Ptr); } public void Push(Pose3D[] values) { foreach (Pose3D value in values) { Push(value); } } public void Push(VectorOfPose3D other) { VectorOfPose3DPushVector(_ptr, other); } protected override void DisposeObject() { if (_needDispose && _ptr != IntPtr.Zero) { VectorOfPose3DRelease(ref _ptr); } } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr VectorOfPose3DCreate(); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr VectorOfPose3DCreateSize(int size); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfPose3DRelease(ref IntPtr v); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int VectorOfPose3DGetSize(IntPtr v); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr VectorOfPose3DGetStartAddress(IntPtr v); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern long VectorOfPose3DGetMemorySize(IntPtr v); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfPose3DPush(IntPtr v, IntPtr value); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfPose3DPushVector(IntPtr ptr, IntPtr otherPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfPose3DClear(IntPtr v); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfPose3DGetItemPtr(IntPtr vec, int index, ref IntPtr element); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int VectorOfPose3DSizeOfItemInBytes(); } } namespace Emgu.CV.Stereo { public class QuasiDenseStereo : SharedPtrObject { public struct PropagationParameters { public int CorrWinSizeX; public int CorrWinSizeY; public int BorderX; public int BorderY; public float CorrelationThreshold; public float TextrureThreshold; public int NeighborhoodSize; public int DisparityGradient; public int LkTemplateSize; public int LkPyrLvl; public int LkTermParam1; public float LkTermParam2; public float GftQualityThres; public int GftMinSeperationDist; public int GftMaxNumFeatures; } public PropagationParameters Param { get { return StereoInvoke.cveQuasiDenseStereoGetParam(_ptr); } set { StereoInvoke.cveQuasiDenseStereoSetParam(_ptr, value); } } public QuasiDenseStereo(Size monoImgSize, string paramFilepath = "") { using CvString cvString = new CvString(paramFilepath); _ptr = StereoInvoke.cveQuasiDenseStereoCreate(ref monoImgSize, cvString, ref _sharedPtr); } protected override void DisposeObject() { if (_sharedPtr != IntPtr.Zero) { StereoInvoke.cveQuasiDenseStereoRelease(ref _sharedPtr); _ptr = IntPtr.Zero; } } public void Process(Mat imgLeft, Mat imgRight) { StereoInvoke.cveQuasiDenseStereoProcess(_ptr, imgLeft, imgRight); } public Mat GetDisparity() { Mat mat = new Mat(); StereoInvoke.cveQuasiDenseStereoGetDisparity(_ptr, mat); return mat; } } public static class StereoInvoke { static StereoInvoke() { CvInvoke.Init(); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveQuasiDenseStereoCreate(ref Size monoImgSize, IntPtr paramFilepath, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveQuasiDenseStereoRelease(ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveQuasiDenseStereoProcess(IntPtr stereo, IntPtr imgLeft, IntPtr imgRight); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveQuasiDenseStereoGetDisparity(IntPtr stereo, IntPtr disparity); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern QuasiDenseStereo.PropagationParameters cveQuasiDenseStereoGetParam(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveQuasiDenseStereoSetParam(IntPtr obj, QuasiDenseStereo.PropagationParameters val); } } namespace Emgu.CV.Quality { public interface IQualityBase : IAlgorithm { IntPtr QualityBasePtr { get; } } public static class QualityInvoke { static QualityInvoke() { CvInvoke.Init(); } public static MCvScalar Compute(this IQualityBase qualityBase, IInputArrayOfArrays cmpImgs) { MCvScalar score = default(MCvScalar); using InputArray inputArray = cmpImgs.GetInputArray(); cveQualityBaseCompute(qualityBase.QualityBasePtr, inputArray, ref score); return score; } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveQualityBaseCompute(IntPtr qualityBase, IntPtr cmpImgs, ref MCvScalar score); public static void GetQualityMap(this IQualityBase qualityBase, IOutputArrayOfArrays dst) { using OutputArray outputArray = dst.GetOutputArray(); cveQualityBaseGetQualityMap(qualityBase.QualityBasePtr, outputArray); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveQualityBaseGetQualityMap(IntPtr qualityBase, IntPtr dst); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveQualityBRISQUERelease(ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveQualityBRISQUECreate(IntPtr modelFilePath, IntPtr rangeFilePath, ref IntPtr qualityBase, ref IntPtr algorithm, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveQualityGMSDCreate(IntPtr refImgs, ref IntPtr qualityBase, ref IntPtr algorithm, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveQualityGMSDRelease(ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveQualityMSECreate(IntPtr refImgs, ref IntPtr qualityBase, ref IntPtr algorithm, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveQualityMSERelease(ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveQualityPSNRCreate(IntPtr refImgs, double maxPixelValue, ref IntPtr qualityBase, ref IntPtr algorithm, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveQualityPSNRRelease(ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveQualitySSIMCreate(IntPtr refImgs, ref IntPtr qualityBase, ref IntPtr algorithm, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveQualitySSIMRelease(ref IntPtr sharedPtr); } public class QualityBRISQUE : SharedPtrObject, IQualityBase, IAlgorithm { private IntPtr _qualityBasePtr; private IntPtr _algorithmPtr; public IntPtr QualityBasePtr => _qualityBasePtr; public IntPtr AlgorithmPtr => _algorithmPtr; public QualityBRISQUE(string modelFilePath = "", string rangeFilePath = "") { using CvString cvString = new CvString(modelFilePath); using CvString cvString2 = new CvString(rangeFilePath); _ptr = QualityInvoke.cveQualityBRISQUECreate(cvString, cvString2, ref _qualityBasePtr, ref _algorithmPtr, ref _sharedPtr); } protected override void DisposeObject() { if (_sharedPtr != IntPtr.Zero) { QualityInvoke.cveQualityBRISQUERelease(ref _sharedPtr); _ptr = IntPtr.Zero; _qualityBasePtr = IntPtr.Zero; _algorithmPtr = IntPtr.Zero; } } } public class QualityGMSD : SharedPtrObject, IQualityBase, IAlgorithm { private IntPtr _qualityBasePtr; private IntPtr _algorithmPtr; public IntPtr QualityBasePtr => _qualityBasePtr; public IntPtr AlgorithmPtr => _algorithmPtr; public QualityGMSD(IInputArrayOfArrays refImgs) { using InputArray inputArray = refImgs.GetInputArray(); _ptr = QualityInvoke.cveQualityGMSDCreate(inputArray, ref _qualityBasePtr, ref _algorithmPtr, ref _sharedPtr); } protected override void DisposeObject() { if (_sharedPtr != IntPtr.Zero) { QualityInvoke.cveQualityGMSDRelease(ref _sharedPtr); _ptr = IntPtr.Zero; _algorithmPtr = IntPtr.Zero; _sharedPtr = IntPtr.Zero; } } } public class QualityMSE : SharedPtrObject, IQualityBase, IAlgorithm { private IntPtr _qualityBasePtr; private IntPtr _algorithmPtr; public IntPtr QualityBasePtr => _qualityBasePtr; public IntPtr AlgorithmPtr => _algorithmPtr; public QualityMSE(IInputArrayOfArrays refImgs) { using InputArray inputArray = refImgs.GetInputArray(); _ptr = QualityInvoke.cveQualityMSECreate(inputArray, ref _qualityBasePtr, ref _algorithmPtr, ref _sharedPtr); } protected override void DisposeObject() { if (_sharedPtr != IntPtr.Zero) { QualityInvoke.cveQualityMSERelease(ref _sharedPtr); _ptr = IntPtr.Zero; _algorithmPtr = IntPtr.Zero; _qualityBasePtr = IntPtr.Zero; } } } public class QualityPSNR : SharedPtrObject, IQualityBase, IAlgorithm { private IntPtr _qualityBasePtr; private IntPtr _algorithmPtr; public IntPtr QualityBasePtr => _qualityBasePtr; public IntPtr AlgorithmPtr => _algorithmPtr; public QualityPSNR(IInputArrayOfArrays refImgs, double maxPixelValue = 255.0) { using InputArray inputArray = refImgs.GetInputArray(); _ptr = QualityInvoke.cveQualityPSNRCreate(inputArray, maxPixelValue, ref _qualityBasePtr, ref _algorithmPtr, ref _sharedPtr); } protected override void DisposeObject() { if (_sharedPtr != IntPtr.Zero) { QualityInvoke.cveQualityPSNRRelease(ref _sharedPtr); _ptr = IntPtr.Zero; _algorithmPtr = IntPtr.Zero; _qualityBasePtr = IntPtr.Zero; } } } public class QualitySSIM : SharedPtrObject, IQualityBase, IAlgorithm { private IntPtr _qualityBasePtr; private IntPtr _algorithmPtr; public IntPtr QualityBasePtr => _qualityBasePtr; public IntPtr AlgorithmPtr => _algorithmPtr; public QualitySSIM(IInputArrayOfArrays refImgs) { using InputArray inputArray = refImgs.GetInputArray(); _ptr = QualityInvoke.cveQualitySSIMCreate(inputArray, ref _qualityBasePtr, ref _algorithmPtr, ref _sharedPtr); } protected override void DisposeObject() { if (_sharedPtr != IntPtr.Zero) { QualityInvoke.cveQualitySSIMRelease(ref _sharedPtr); _ptr = IntPtr.Zero; _algorithmPtr = IntPtr.Zero; _qualityBasePtr = IntPtr.Zero; } } } } namespace Emgu.CV.PhaseUnwrapping { public class HistogramPhaseUnwrapping : UnmanagedObject { private IntPtr _sharedPtr; public HistogramPhaseUnwrapping(int width = 800, int height = 600, float histThresh = 29.608812f, int nbrOfSmallBins = 10, int nbrOfLargeBins = 5) { _ptr = PhaseUnwrappingInvoke.cveHistogramPhaseUnwrappingCreate(width, height, histThresh, nbrOfSmallBins, nbrOfLargeBins, ref _sharedPtr); } protected override void DisposeObject() { if (IntPtr.Zero != _ptr) { PhaseUnwrappingInvoke.cveHistogramPhaseUnwrappingRelease(ref _ptr, ref _sharedPtr); } } public void GetInverseReliabilityMap(IOutputArray reliabilityMap) { using OutputArray outputArray = reliabilityMap.GetOutputArray(); PhaseUnwrappingInvoke.cveHistogramPhaseUnwrappingGetInverseReliabilityMap(_ptr, outputArray); } public void UnwrapPhaseMap(IInputArray wrappedPhaseMap, IOutputArray unwrappedPhaseMap, IInputArray shadowMask = null) { using InputArray inputArray = wrappedPhaseMap.GetInputArray(); using OutputArray outputArray = unwrappedPhaseMap.GetOutputArray(); using InputArray inputArray2 = ((shadowMask == null) ? InputArray.GetEmpty() : shadowMask.GetInputArray()); PhaseUnwrappingInvoke.cveHistogramPhaseMapUnwrappingUnwrapPhaseMap(_ptr, inputArray, outputArray, inputArray2); } } public static class PhaseUnwrappingInvoke { static PhaseUnwrappingInvoke() { CvInvoke.Init(); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveHistogramPhaseUnwrappingCreate(int width, int height, float histThresh, int nbrOfSmallBins, int nbrOfLargeBins, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveHistogramPhaseUnwrappingRelease(ref IntPtr phaseUnwrapping, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveHistogramPhaseUnwrappingGetInverseReliabilityMap(IntPtr phaseUnwrapping, IntPtr reliabilityMap); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveHistogramPhaseMapUnwrappingUnwrapPhaseMap(IntPtr phaseUnwrapping, IntPtr wrappedPhaseMap, IntPtr unwrappedPhaseMap, IntPtr shadowMask); } } namespace Emgu.CV.ImgHash { public class AverageHash : ImgHashBase { private IntPtr _sharedPtr; public AverageHash() { _ptr = ImgHashInvoke.cveAverageHashCreate(ref _imgHashBase, ref _sharedPtr); } protected override void DisposeObject() { if (_ptr != IntPtr.Zero) { ImgHashInvoke.cveAverageHashRelease(ref _ptr, ref _sharedPtr); } base.DisposeObject(); } } internal static class ImgHashInvoke { [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveAverageHashCreate(ref IntPtr imgHash, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveAverageHashRelease(ref IntPtr hash, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveBlockMeanHashCreate(ref IntPtr imgHash, BlockMeanHash.Mode mode, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveBlockMeanHashRelease(ref IntPtr hash, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveColorMomentHashCreate(ref IntPtr imgHash, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveColorMomentHashRelease(ref IntPtr hash, ref IntPtr sharedPtr); static ImgHashInvoke() { CvInvoke.Init(); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveImgHashBaseCompute(IntPtr imgHash, IntPtr inputArr, IntPtr outputArr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern double cveImgHashBaseCompare(IntPtr imgHash, IntPtr hashOne, IntPtr hashTwo); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveMarrHildrethHashCreate(ref IntPtr imgHash, float alpha, float scale, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveMarrHildrethHashRelease(ref IntPtr hash, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cvePHashCreate(ref IntPtr imgHash, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cvePHashRelease(ref IntPtr hash, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveRadialVarianceHashCreate(ref IntPtr imgHash, double sigma, int numOfAngleLine, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveRadialVarianceHashRelease(ref IntPtr hash, ref IntPtr sharedPtr); } public class BlockMeanHash : ImgHashBase { public enum Mode { HashMode0, HashMode1 } private IntPtr _sharedPtr; public BlockMeanHash(Mode mode = Mode.HashMode0) { _ptr = ImgHashInvoke.cveBlockMeanHashCreate(ref _imgHashBase, mode, ref _sharedPtr); } protected override void DisposeObject() { if (_ptr != IntPtr.Zero) { ImgHashInvoke.cveBlockMeanHashRelease(ref _ptr, ref _sharedPtr); } base.DisposeObject(); } } public class ColorMomentHash : ImgHashBase { private IntPtr _sharedPtr; public ColorMomentHash() { _ptr = ImgHashInvoke.cveColorMomentHashCreate(ref _imgHashBase, ref _sharedPtr); } protected override void DisposeObject() { if (_ptr != IntPtr.Zero) { ImgHashInvoke.cveColorMomentHashRelease(ref _ptr, ref _sharedPtr); } base.DisposeObject(); } } public abstract class ImgHashBase : UnmanagedObject { protected IntPtr _imgHashBase; public IntPtr ImgHashBasePtr => _imgHashBase; protected override void DisposeObject() { _imgHashBase = IntPtr.Zero; } public void Compute(IInputArray inputArr, IOutputArray outputArr) { using InputArray inputArray = inputArr.GetInputArray(); using OutputArray outputArray = outputArr.GetOutputArray(); ImgHashInvoke.cveImgHashBaseCompute(_imgHashBase, inputArray, outputArray); } public double Compare(IInputArray hashOne, IInputArray hashTwo) { using InputArray inputArray = hashOne.GetInputArray(); using InputArray inputArray2 = hashTwo.GetInputArray(); return ImgHashInvoke.cveImgHashBaseCompare(_imgHashBase, inputArray, inputArray2); } } public class MarrHildrethHash : ImgHashBase { private IntPtr _sharedPtr; public MarrHildrethHash(float alpha = 2f, float scale = 1f) { _ptr = ImgHashInvoke.cveMarrHildrethHashCreate(ref _imgHashBase, alpha, scale, ref _sharedPtr); } protected override void DisposeObject() { if (_ptr != IntPtr.Zero) { ImgHashInvoke.cveMarrHildrethHashRelease(ref _ptr, ref _sharedPtr); } base.DisposeObject(); } } public class PHash : ImgHashBase { private IntPtr _sharedPtr; public PHash() { _ptr = ImgHashInvoke.cvePHashCreate(ref _imgHashBase, ref _sharedPtr); } protected override void DisposeObject() { if (_ptr != IntPtr.Zero) { ImgHashInvoke.cvePHashRelease(ref _ptr, ref _sharedPtr); } base.DisposeObject(); } } public class RadialVarianceHash : ImgHashBase { private IntPtr _sharedPtr; public RadialVarianceHash(double sigma = 1.0, int numOfAngleLine = 180) { _ptr = ImgHashInvoke.cveRadialVarianceHashCreate(ref _imgHashBase, sigma, numOfAngleLine, ref _sharedPtr); } protected override void DisposeObject() { if (_ptr != IntPtr.Zero) { ImgHashInvoke.cveRadialVarianceHashRelease(ref _ptr, ref _sharedPtr); } base.DisposeObject(); } } } namespace Emgu.CV.Bioinspired { public static class BioinspiredInvoke { static BioinspiredInvoke() { CvInvoke.Init(); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveRetinaCreate(ref Size inputSize, [MarshalAs(UnmanagedType.U1)] bool colorMode, Retina.ColorSamplingMethod colorSamplingMethod, [MarshalAs(UnmanagedType.U1)] bool useRetinaLogSampling, double reductionFactor, double samplingStrength, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveRetinaRun(IntPtr retina, IntPtr image); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveRetinaGetParvo(IntPtr retina, IntPtr parvo); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveRetinaGetMagno(IntPtr retina, IntPtr magno); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveRetinaRelease(ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveRetinaClearBuffers(IntPtr retina); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveRetinaGetParameters(IntPtr retina, ref Retina.RetinaParameters parameters); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveRetinaSetParameters(IntPtr retina, ref Retina.RetinaParameters parameters); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveRetinaFastToneMappingCreate(ref Size inputSize, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveRetinaFastToneMappingApplyFastToneMapping(IntPtr toneMapping, IntPtr inputImage, IntPtr outputToneMappedImage); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveRetinaFastToneMappingSetup(IntPtr toneMapping, float photoreceptorsNeighborhoodRadius, float ganglioncellsNeighborhoodRadius, float meanLuminanceModulatorK); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveRetinaFastToneMappingRelease(ref IntPtr sharedPtr); } public class Retina : SharedPtrObject { public enum ColorSamplingMethod { ColorRandom, ColorDiagonal, ColorBayer } public struct OPLandIplParvoParameters { [MarshalAs(UnmanagedType.U1)] public bool ColorMode; [MarshalAs(UnmanagedType.U1)] public bool NormaliseOutput; public float PhotoreceptorsLocalAdaptationSensitivity; public float PhotoreceptorsTemporalConstant; public float PhotoreceptorsSpatialConstant; public float HorizontalCellsGain; public float HcellsTemporalConstant; public float HcellsSpatialConstant; public float GanglionCellsSensitivity; } public struct IplMagnoParameters { [MarshalAs(UnmanagedType.U1)] public bool NormaliseOutput; public float ParasolCellsBeta; public float ParasolCellsTau; public float ParasolCellsK; public float AmacrinCellsTemporalCutFrequency; public float V0CompressionParameter; public float LocalAdaptintegrationTau; public float LocalAdaptintegrationK; } public struct RetinaParameters { public OPLandIplParvoParameters OPLandIplParvo; public IplMagnoParameters IplMagno; } public RetinaParameters Parameters { get { RetinaParameters parameters = default(RetinaParameters); BioinspiredInvoke.cveRetinaGetParameters(_ptr, ref parameters); return parameters; } set { BioinspiredInvoke.cveRetinaSetParameters(_ptr, ref value); } } public Retina(Size inputSize) : this(inputSize, colorMode: true, ColorSamplingMethod.ColorBayer, useRetinaLogSampling: false, 1.0, 10.0) { } public Retina(Size inputSize, bool colorMode, ColorSamplingMethod colorSamplingMethod, bool useRetinaLogSampling, double reductionFactor, double samplingStrength) { _ptr = BioinspiredInvoke.cveRetinaCreate(ref inputSize, colorMode, colorSamplingMethod, useRetinaLogSampling, reductionFactor, samplingStrength, ref _sharedPtr); } public void Run(IInputArray image) { using InputArray inputArray = image.GetInputArray(); BioinspiredInvoke.cveRetinaRun(_ptr, inputArray); } public void GetParvo(IOutputArray parvo) { if (_ptr != IntPtr.Zero) { using (OutputArray outputArray = parvo.GetOutputArray()) { BioinspiredInvoke.cveRetinaGetParvo(_ptr, outputArray); } } } public void GetMagno(IOutputArray magno) { if (_ptr != IntPtr.Zero) { using (OutputArray outputArray = magno.GetOutputArray()) { BioinspiredInvoke.cveRetinaGetMagno(_ptr, outputArray); } } } public void ClearBuffers() { BioinspiredInvoke.cveRetinaClearBuffers(_ptr); } protected override void DisposeObject() { if (_sharedPtr != IntPtr.Zero) { BioinspiredInvoke.cveRetinaRelease(ref _sharedPtr); _ptr = IntPtr.Zero; } } } public class RetinaFastToneMapping : SharedPtrObject { public RetinaFastToneMapping(Size inputSize) { _ptr = BioinspiredInvoke.cveRetinaFastToneMappingCreate(ref inputSize, ref _sharedPtr); } public void ApplyFastToneMapping(IInputArray inputImage, IOutputArray outputToneMappedImage) { using InputArray inputArray = inputImage.GetInputArray(); using OutputArray outputArray = outputToneMappedImage.GetOutputArray(); BioinspiredInvoke.cveRetinaFastToneMappingApplyFastToneMapping(_ptr, inputArray, outputArray); } public void Setup(float photoreceptorsNeighborhoodRadius = 3f, float ganglioncellsNeighborhoodRadius = 1f, float meanLuminanceModulatorK = 1f) { BioinspiredInvoke.cveRetinaFastToneMappingSetup(_ptr, photoreceptorsNeighborhoodRadius, ganglioncellsNeighborhoodRadius, meanLuminanceModulatorK); } protected override void DisposeObject() { if (_sharedPtr != IntPtr.Zero) { BioinspiredInvoke.cveRetinaFastToneMappingRelease(ref _sharedPtr); _ptr = IntPtr.Zero; } } } } namespace Emgu.CV.XObjdetect { public class WBDetector : UnmanagedObject { private IntPtr _sharedPtr; public WBDetector() { _ptr = XObjdetectInvoke.cveWBDetectorCreate(ref _sharedPtr); } public void Read(FileNode node) { XObjdetectInvoke.cveWBDetectorRead(_ptr, node); } public void Write(FileStorage fs) { XObjdetectInvoke.cveWBDetectorWrite(_ptr, fs); } public void Train(string posSamples, string negImgs) { using CvString cvString = new CvString(posSamples); using CvString cvString2 = new CvString(negImgs); XObjdetectInvoke.cveWBDetectorTrain(_ptr, cvString, cvString2); } public void Detect(Mat image, VectorOfRect bboxes, VectorOfDouble confidences) { XObjdetectInvoke.cveWBDetectorDetect(_ptr, image, bboxes, confidences); } protected override void DisposeObject() { if (IntPtr.Zero != _ptr) { XObjdetectInvoke.cveWBDetectorRelease(ref _ptr, ref _sharedPtr); } } } public static class XObjdetectInvoke { static XObjdetectInvoke() { CvInvoke.Init(); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveWBDetectorCreate(ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveWBDetectorRead(IntPtr detector, IntPtr node); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveWBDetectorWrite(IntPtr detector, IntPtr fs); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveWBDetectorTrain(IntPtr detector, IntPtr posSamples, IntPtr negImgs); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveWBDetectorDetect(IntPtr detector, IntPtr img, IntPtr bboxes, IntPtr confidences); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveWBDetectorRelease(ref IntPtr detector, ref IntPtr sharedPtr); } } namespace Emgu.CV.LineDescriptor { public class BinaryDescriptor : SharedPtrObject { public BinaryDescriptor() { _ptr = LineDescriptorInvoke.cveLineDescriptorBinaryDescriptorCreate(ref _sharedPtr); } public void Detect(Mat image, VectorOfKeyLine keylines, Mat mask = null) { LineDescriptorInvoke.cveLineDescriptorBinaryDescriptorDetect(_ptr, image, keylines, mask); } public void Compute(Mat image, VectorOfKeyLine keylines, Mat descriptors, bool returnFloatDescr = false) { LineDescriptorInvoke.cveLineDescriptorBinaryDescriptorCompute(_ptr, image, keylines, descriptors, returnFloatDescr); } protected override void DisposeObject() { if (_sharedPtr != IntPtr.Zero) { LineDescriptorInvoke.cveLineDescriptorBinaryDescriptorRelease(ref _sharedPtr); _ptr = IntPtr.Zero; } } } public static class LineDescriptorInvoke { static LineDescriptorInvoke() { CvInvoke.Init(); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveLineDescriptorBinaryDescriptorCreate(ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveLineDescriptorBinaryDescriptorDetect(IntPtr descriptor, IntPtr image, IntPtr keypoints, IntPtr mask); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveLineDescriptorBinaryDescriptorCompute(IntPtr descriptor, IntPtr image, IntPtr keylines, IntPtr descriptors, [MarshalAs(UnmanagedType.U1)] bool returnFloatDescr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveLineDescriptorBinaryDescriptorRelease(ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveLineDescriptorLSDDetectorCreate(ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveLineDescriptorLSDDetectorDetect(IntPtr detector, IntPtr image, IntPtr keypoints, int scale, int numOctaves, IntPtr mask); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveLineDescriptorLSDDetectorRelease(ref IntPtr sharedPtr); } public class LSDDetector : SharedPtrObject { public LSDDetector() { _ptr = LineDescriptorInvoke.cveLineDescriptorLSDDetectorCreate(ref _sharedPtr); } public void Detect(Mat image, VectorOfKeyLine keylines, int scale, int numOctaves, Mat mask = null) { LineDescriptorInvoke.cveLineDescriptorLSDDetectorDetect(_ptr, image, keylines, scale, numOctaves, mask); } protected override void DisposeObject() { if (_sharedPtr != IntPtr.Zero) { LineDescriptorInvoke.cveLineDescriptorLSDDetectorRelease(ref _sharedPtr); _ptr = IntPtr.Zero; } } } public struct MKeyLine { public float Angle; public int ClassId; public int Octave; public PointF Pt; public float Response; public float Size; public float StartPointX; public float StartPointY; public float EndPointX; public float EndPointY; public float SPointInOctaveX; public float SPointInOctaveY; public float EPointInOctaveX; public float EPointInOctaveY; public float LineLength; public int NumOfPixels; } [Serializable] [DebuggerTypeProxy(typeof(DebuggerProxy))] public class VectorOfKeyLine : UnmanagedVector, ISerializable { internal class DebuggerProxy { private VectorOfKeyLine _v; public MKeyLine[] Values => _v.ToArray(); public DebuggerProxy(VectorOfKeyLine v) { _v = v; } } private readonly bool _needDispose; public override int Size => VectorOfKeyLineGetSize(_ptr); public override IntPtr StartAddress => VectorOfKeyLineGetStartAddress(_ptr); public override long Length => VectorOfKeyLineGetMemorySize(_ptr); public MKeyLine this[int index] { get { MKeyLine element = default(MKeyLine); VectorOfKeyLineGetItem(_ptr, index, ref element); return element; } } public static int SizeOfItemInBytes => VectorOfKeyLineSizeOfItemInBytes(); static VectorOfKeyLine() { CvInvoke.Init(); } public VectorOfKeyLine(SerializationInfo info, StreamingContext context) : this() { Push((MKeyLine[])info.GetValue("KeyLineArray", typeof(MKeyLine[]))); } public void GetObjectData(SerializationInfo info, StreamingContext context) { info.AddValue("KeyLineArray", ToArray()); } public VectorOfKeyLine() : this(VectorOfKeyLineCreate(), needDispose: true) { } internal VectorOfKeyLine(IntPtr ptr, bool needDispose) { _ptr = ptr; _needDispose = needDispose; } public VectorOfKeyLine(int size) : this(VectorOfKeyLineCreateSize(size), needDispose: true) { } public VectorOfKeyLine(MKeyLine[] values) : this() { Push(values); } public void Push(MKeyLine[] value) { if (value.Length != 0) { GCHandle gCHandle = GCHandle.Alloc(value, GCHandleType.Pinned); VectorOfKeyLinePushMulti(_ptr, gCHandle.AddrOfPinnedObject(), value.Length); gCHandle.Free(); } } public void Push(VectorOfKeyLine other) { VectorOfKeyLinePushVector(_ptr, other); } public MKeyLine[] ToArray() { MKeyLine[] array = new MKeyLine[Size]; if (array.Length != 0) { GCHandle gCHandle = GCHandle.Alloc(array, GCHandleType.Pinned); VectorOfKeyLineCopyData(_ptr, gCHandle.AddrOfPinnedObject()); gCHandle.Free(); } return array; } public void Clear() { VectorOfKeyLineClear(_ptr); } protected override void DisposeObject() { if (_needDispose && _ptr != IntPtr.Zero) { VectorOfKeyLineRelease(ref _ptr); } } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr VectorOfKeyLineCreate(); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr VectorOfKeyLineCreateSize(int size); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfKeyLineRelease(ref IntPtr v); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int VectorOfKeyLineGetSize(IntPtr v); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfKeyLineCopyData(IntPtr v, IntPtr data); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr VectorOfKeyLineGetStartAddress(IntPtr v); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern long VectorOfKeyLineGetMemorySize(IntPtr v); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfKeyLinePushMulti(IntPtr v, IntPtr values, int count); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfKeyLinePushVector(IntPtr ptr, IntPtr otherPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfKeyLineClear(IntPtr v); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfKeyLineGetItem(IntPtr vec, int index, ref MKeyLine element); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int VectorOfKeyLineSizeOfItemInBytes(); } } namespace Emgu.CV.Hfs { public static class HfsInvoke { static HfsInvoke() { CvInvoke.Init(); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveHfsSegmentCreate(int height, int width, float segEgbThresholdI, int minRegionSizeI, float segEgbThresholdII, int minRegionSizeII, float spatialWeight, int slicSpixelSize, int numSlicIter, ref IntPtr algorithmPtr, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveHfsSegmentRelease(ref IntPtr hfsSegmentPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveHfsPerformSegment(IntPtr hfsSegment, IntPtr src, IntPtr dst, bool ifDraw, bool useGpu); } public class HfsSegment : SharedPtrObject, IAlgorithm { private IntPtr _algorithmPtr; public IntPtr AlgorithmPtr => _algorithmPtr; public HfsSegment(int height, int width, float segEgbThresholdI = 0.08f, int minRegionSizeI = 100, float segEgbThresholdII = 0.28f, int minRegionSizeII = 200, float spatialWeight = 0.6f, int slicSpixelSize = 8, int numSlicIter = 5) { _ptr = HfsInvoke.cveHfsSegmentCreate(height, width, segEgbThresholdI, minRegionSizeI, segEgbThresholdII, minRegionSizeII, spatialWeight, slicSpixelSize, numSlicIter, ref _algorithmPtr, ref _sharedPtr); } protected override void DisposeObject() { if (_sharedPtr != IntPtr.Zero) { HfsInvoke.cveHfsSegmentRelease(ref _sharedPtr); _algorithmPtr = IntPtr.Zero; _ptr = IntPtr.Zero; } } public Mat PerformSegmentGpu(IInputArray src, bool ifDraw = true) { using InputArray inputArray = src.GetInputArray(); Mat mat = new Mat(); HfsInvoke.cveHfsPerformSegment(_ptr, inputArray, mat, ifDraw, useGpu: true); return mat; } public Mat PerformSegmentCpu(IInputArray src, bool ifDraw = true) { using InputArray inputArray = src.GetInputArray(); Mat mat = new Mat(); HfsInvoke.cveHfsPerformSegment(_ptr, inputArray, mat, ifDraw, useGpu: false); return mat; } } } namespace Emgu.CV.Fuzzy { public static class FuzzyInvoke { public enum Function { Linear = 1, Sinus } public enum InpaintAlgorithm { OneStep = 1, MultiStep, Iterative } static FuzzyInvoke() { CvInvoke.Init(); } public static void CreateKernel(IInputArray A, IInputArray B, IOutputArray kernel, int chn = 1) { using InputArray inputArray = A.GetInputArray(); using InputArray inputArray2 = B.GetInputArray(); using OutputArray outputArray = kernel.GetOutputArray(); cveFtCreateKernel(inputArray, inputArray2, outputArray, chn); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveFtCreateKernel(IntPtr A, IntPtr B, IntPtr kernel, int chn); public static void CreateKernel(Function function, int radius, IOutputArray kernel, int chn = 1) { using OutputArray outputArray = kernel.GetOutputArray(); cveFtcreateKernelFromFunction(function, radius, outputArray, chn); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveFtcreateKernelFromFunction(Function function, int radius, IntPtr kernel, int chn); public static void Inpaint(Mat image, Mat mask, Mat output, int radius = 2, Function function = Function.Linear, InpaintAlgorithm algorithm = InpaintAlgorithm.OneStep) { cveFtInpaint(image, mask, output, radius, function, algorithm); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveFtInpaint(IntPtr image, IntPtr mask, IntPtr output, int radius, Function function, InpaintAlgorithm algorithm); public static void Filter(Mat image, Mat kernel, Mat output) { cveFtFilter(image, kernel, output); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveFtFilter(IntPtr image, IntPtr kernel, IntPtr output); } } namespace Emgu.CV.Aruco { public static class ArucoInvoke { static ArucoInvoke() { CvInvoke.Init(); } public static void DrawMarker(Dictionary dict, int id, int sidePixels, IOutputArray img, int borderBits = 1) { using OutputArray outputArray = img.GetOutputArray(); cveArucoDrawMarker(dict, id, sidePixels, outputArray, borderBits); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveArucoDrawMarker(IntPtr dictionary, int id, int sidePixels, IntPtr img, int borderBits); public static void DetectMarkers(IInputArray image, Dictionary dict, IOutputArrayOfArrays corners, IOutputArray ids, DetectorParameters parameters, IOutputArrayOfArrays rejectedImgPoints = null) { using InputArray inputArray = image.GetInputArray(); using OutputArray outputArray = corners.GetOutputArray(); using OutputArray outputArray2 = ids.GetOutputArray(); using OutputArray outputArray3 = ((rejectedImgPoints != null) ? rejectedImgPoints.GetOutputArray() : OutputArray.GetEmpty()); cveArucoDetectMarkers(inputArray, dict, outputArray, outputArray2, ref parameters, outputArray3); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveArucoDetectMarkers(IntPtr image, IntPtr dictionary, IntPtr corners, IntPtr ids, ref DetectorParameters parameters, IntPtr rejectedImgPoints); public static void EstimatePoseSingleMarkers(IInputArrayOfArrays corners, float markerLength, IInputArray cameraMatrix, IInputArray distCoeffs, IOutputArrayOfArrays rvecs, IOutputArrayOfArrays tvecs) { using InputArray inputArray = corners.GetInputArray(); using InputArray inputArray2 = cameraMatrix.GetInputArray(); using InputArray inputArray3 = distCoeffs.GetInputArray(); using OutputArray outputArray = rvecs.GetOutputArray(); using OutputArray outputArray2 = tvecs.GetOutputArray(); cveArucoEstimatePoseSingleMarkers(inputArray, markerLength, inputArray2, inputArray3, outputArray, outputArray2); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveArucoEstimatePoseSingleMarkers(IntPtr corners, float markerLength, IntPtr cameraMatrix, IntPtr distCoeffs, IntPtr rvecs, IntPtr tvecs); public static void RefineDetectedMarkers(IInputArray image, IBoard board, IInputOutputArray detectedCorners, IInputOutputArray detectedIds, IInputOutputArray rejectedCorners, IInputArray cameraMatrix, IInputArray distCoeffs, float minRepDistance, float errorCorrectionRate, bool checkAllOrders, IOutputArray recoveredIdxs, DetectorParameters parameters) { using InputArray inputArray = image.GetInputArray(); using InputOutputArray inputOutputArray = detectedCorners.GetInputOutputArray(); using InputOutputArray inputOutputArray2 = detectedIds.GetInputOutputArray(); using InputOutputArray inputOutputArray3 = rejectedCorners.GetInputOutputArray(); using InputArray inputArray2 = ((cameraMatrix == null) ? InputArray.GetEmpty() : cameraMatrix.GetInputArray()); using InputArray inputArray3 = ((distCoeffs == null) ? InputArray.GetEmpty() : distCoeffs.GetInputArray()); using OutputArray outputArray = ((recoveredIdxs == null) ? OutputArray.GetEmpty() : recoveredIdxs.GetOutputArray()); cveArucoRefineDetectedMarkers(inputArray, board.BoardPtr, inputOutputArray, inputOutputArray2, inputOutputArray3, inputArray2, inputArray3, minRepDistance, errorCorrectionRate, checkAllOrders, outputArray, ref parameters); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveArucoRefineDetectedMarkers(IntPtr image, IntPtr board, IntPtr detectedCorners, IntPtr detectedIds, IntPtr rejectedCorners, IntPtr cameraMatrix, IntPtr distCoeffs, float minRepDistance, float errorCorrectionRate, [MarshalAs(UnmanagedType.U1)] bool checkAllOrders, IntPtr ecoveredIdxs, ref DetectorParameters parameters); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveArucoDetectorParametersGetDefault(ref DetectorParameters parameters); public static void DrawDetectedMarkers(IInputOutputArray image, IInputArray corners, IInputArray ids, MCvScalar borderColor) { using InputOutputArray inputOutputArray = image.GetInputOutputArray(); using InputArray inputArray = corners.GetInputArray(); using InputArray inputArray2 = ids.GetInputArray(); cveArucoDrawDetectedMarkers(inputOutputArray, inputArray, inputArray2, ref borderColor); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveArucoDrawDetectedMarkers(IntPtr image, IntPtr corners, IntPtr ids, ref MCvScalar borderColor); public static double CalibrateCameraAruco(IInputArrayOfArrays corners, IInputArray ids, IInputArray counter, IBoard board, Size imageSize, IInputOutputArray cameraMatrix, IInputOutputArray distCoeffs, IOutputArray rvecs, IOutputArray tvecs, CalibType flags, MCvTermCriteria criteria) { return CalibrateCameraAruco(corners, ids, counter, board, imageSize, cameraMatrix, distCoeffs, rvecs, tvecs, null, null, null, flags, criteria); } public static double CalibrateCameraAruco(IInputArrayOfArrays corners, IInputArray ids, IInputArray counter, IBoard board, Size imageSize, IInputOutputArray cameraMatrix, IInputOutputArray distCoeffs, IOutputArray rvecs, IOutputArray tvecs, IOutputArray stdDeviationsIntrinsics, IOutputArray stdDeviationsExtrinsics, IOutputArray perViewErrors, CalibType flags, MCvTermCriteria criteria) { using InputArray inputArray = corners.GetInputArray(); using InputArray inputArray2 = ids.GetInputArray(); using InputArray inputArray3 = counter.GetInputArray(); using InputOutputArray inputOutputArray = cameraMatrix.GetInputOutputArray(); using InputOutputArray inputOutputArray2 = distCoeffs.GetInputOutputArray(); using OutputArray outputArray = ((rvecs == null) ? OutputArray.GetEmpty() : rvecs.GetOutputArray()); using OutputArray outputArray2 = ((tvecs == null) ? OutputArray.GetEmpty() : tvecs.GetOutputArray()); using OutputArray outputArray3 = ((stdDeviationsIntrinsics == null) ? OutputArray.GetEmpty() : stdDeviationsIntrinsics.GetOutputArray()); using OutputArray outputArray4 = ((stdDeviationsExtrinsics == null) ? OutputArray.GetEmpty() : stdDeviationsExtrinsics.GetOutputArray()); using OutputArray outputArray5 = ((perViewErrors == null) ? OutputArray.GetEmpty() : perViewErrors.GetOutputArray()); return cveArucoCalibrateCameraAruco(inputArray, inputArray2, inputArray3, board.BoardPtr, ref imageSize, inputOutputArray, inputOutputArray2, outputArray, outputArray2, outputArray3, outputArray4, outputArray5, flags, ref criteria); } public static double CalibrateCameraCharuco(IInputArrayOfArrays charucoCorners, IInputArrayOfArrays charucoIds, CharucoBoard board, Size imageSize, IInputOutputArray cameraMatrix, IInputOutputArray distCoeffs, IOutputArray rvecs, IOutputArray tvecs, CalibType flags, MCvTermCriteria criteria) { return CalibrateCameraCharuco(charucoCorners, charucoIds, board, imageSize, cameraMatrix, distCoeffs, rvecs, tvecs, null, null, null, flags, criteria); } public static double CalibrateCameraCharuco(IInputArrayOfArrays charucoCorners, IInputArrayOfArrays charucoIds, CharucoBoard board, Size imageSize, IInputOutputArray cameraMatrix, IInputOutputArray distCoeffs, IOutputArray rvecs, IOutputArray tvecs, IOutputArray stdDeviationsIntrinsics, IOutputArray stdDeviationsExtrinsics, IOutputArray perViewErrors, CalibType flags, MCvTermCriteria criteria) { using InputArray inputArray = charucoCorners.GetInputArray(); using InputArray inputArray2 = charucoIds.GetInputArray(); using InputOutputArray inputOutputArray = cameraMatrix.GetInputOutputArray(); using InputOutputArray inputOutputArray2 = distCoeffs.GetInputOutputArray(); using OutputArray outputArray = ((rvecs == null) ? OutputArray.GetEmpty() : rvecs.GetOutputArray()); using OutputArray outputArray2 = ((tvecs == null) ? OutputArray.GetEmpty() : tvecs.GetOutputArray()); using OutputArray outputArray3 = ((stdDeviationsIntrinsics == null) ? OutputArray.GetEmpty() : stdDeviationsIntrinsics.GetOutputArray()); using OutputArray outputArray4 = ((stdDeviationsExtrinsics == null) ? OutputArray.GetEmpty() : stdDeviationsExtrinsics.GetOutputArray()); using OutputArray outputArray5 = ((perViewErrors == null) ? OutputArray.GetEmpty() : perViewErrors.GetOutputArray()); return cveArucoCalibrateCameraCharuco(inputArray, inputArray2, board.BoardPtr, ref imageSize, inputOutputArray, inputOutputArray2, outputArray, outputArray2, outputArray3, outputArray4, outputArray5, flags, ref criteria); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern double cveArucoCalibrateCameraAruco(IntPtr corners, IntPtr ids, IntPtr counter, IntPtr board, ref Size imageSize, IntPtr cameraMatrix, IntPtr distCoeffs, IntPtr rvecs, IntPtr tvecs, IntPtr stdDeviationsIntrinsics, IntPtr stdDeviationsExtrinsics, IntPtr perViewErrors, CalibType flags, ref MCvTermCriteria criteria); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern double cveArucoCalibrateCameraCharuco(IntPtr charucoCorners, IntPtr charucoIds, IntPtr board, ref Size imageSize, IntPtr cameraMatrix, IntPtr distCoeffs, IntPtr rvecs, IntPtr tvecs, IntPtr stdDeviationsIntrinsics, IntPtr stdDeviationsExtrinsics, IntPtr perViewErrors, CalibType flags, ref MCvTermCriteria criteria); public static int InterpolateCornersCharuco(IInputArrayOfArrays markerCorners, IInputArray markerIds, IInputArray image, CharucoBoard board, IOutputArray charucoCorners, IOutputArray charucoIds, IInputArray cameraMatrix = null, IInputArray distCoeffs = null, int minMarkers = 2) { using InputArray inputArray = markerCorners.GetInputArray(); using InputArray inputArray2 = markerIds.GetInputArray(); using InputArray inputArray3 = image.GetInputArray(); using OutputArray outputArray = charucoCorners.GetOutputArray(); using OutputArray outputArray2 = charucoIds.GetOutputArray(); using InputArray inputArray4 = ((cameraMatrix == null) ? InputArray.GetEmpty() : cameraMatrix.GetInputArray()); using InputArray inputArray5 = ((distCoeffs == null) ? InputArray.GetEmpty() : distCoeffs.GetInputArray()); return cveArucoInterpolateCornersCharuco(inputArray, inputArray2, inputArray3, board, outputArray, outputArray2, inputArray4, inputArray5, minMarkers); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int cveArucoInterpolateCornersCharuco(IntPtr markerCorners, IntPtr markerIds, IntPtr image, IntPtr board, IntPtr charucoCorners, IntPtr charucoIds, IntPtr cameraMatrix, IntPtr distCoeffs, int minMarkers); public static void DrawDetectedCornersCharuco(IInputOutputArray image, IInputArray charucoCorners, IInputArray charucoIds, MCvScalar cornerColor) { using InputOutputArray inputOutputArray = image.GetInputOutputArray(); using InputArray inputArray = charucoCorners.GetInputArray(); using InputArray inputArray2 = ((charucoIds == null) ? InputArray.GetEmpty() : charucoIds.GetInputArray()); cveArucoDrawDetectedCornersCharuco(inputOutputArray, inputArray, inputArray2, ref cornerColor); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveArucoDrawDetectedCornersCharuco(IntPtr image, IntPtr charucoCorners, IntPtr charucoIds, ref MCvScalar cornerColor); public static bool EstimatePoseCharucoBoard(IInputArray charucoCorners, IInputArray charucoIds, CharucoBoard board, IInputArray cameraMatrix, IInputArray distCoeffs, IInputOutputArray rvec, IInputOutputArray tvec, bool useExtrinsicGuess = false) { using InputArray inputArray = charucoCorners.GetInputArray(); using InputArray inputArray2 = charucoIds.GetInputArray(); using InputArray inputArray3 = cameraMatrix.GetInputArray(); using InputArray inputArray4 = distCoeffs.GetInputArray(); using InputOutputArray inputOutputArray = rvec.GetInputOutputArray(); using InputOutputArray inputOutputArray2 = tvec.GetInputOutputArray(); return cveArucoEstimatePoseCharucoBoard(inputArray, inputArray2, board, inputArray3, inputArray4, inputOutputArray, inputOutputArray2, useExtrinsicGuess); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.U1)] internal static extern bool cveArucoEstimatePoseCharucoBoard(IntPtr charucoCorners, IntPtr charucoIds, IntPtr board, IntPtr cameraMatrix, IntPtr distCoeffs, IntPtr rvec, IntPtr tvec, [MarshalAs(UnmanagedType.U1)] bool useExtrinsicGuess); public static void DetectCharucoDiamond(IInputArray image, IInputArray markerCorners, IInputArray markerIds, float squareMarkerLengthRate, IOutputArray diamondCorners, IOutputArray diamondIds, IInputArray cameraMatrix = null, IInputArray distCoeffs = null) { using InputArray inputArray = image.GetInputArray(); using InputArray inputArray2 = markerCorners.GetInputArray(); using InputArray inputArray3 = markerIds.GetInputArray(); using OutputArray outputArray = diamondCorners.GetOutputArray(); using OutputArray outputArray2 = diamondIds.GetOutputArray(); using InputArray inputArray4 = ((cameraMatrix == null) ? InputArray.GetEmpty() : cameraMatrix.GetInputArray()); using InputArray inputArray5 = ((distCoeffs == null) ? InputArray.GetEmpty() : distCoeffs.GetInputArray()); cveArucoDetectCharucoDiamond(inputArray, inputArray2, inputArray3, squareMarkerLengthRate, outputArray, outputArray2, inputArray4, inputArray5); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveArucoDetectCharucoDiamond(IntPtr image, IntPtr markerCorners, IntPtr markerIds, float squareMarkerLengthRate, IntPtr diamondCorners, IntPtr diamondIds, IntPtr cameraMatrix, IntPtr distCoeffs); public static void DrawDetectedDiamonds(IInputOutputArray image, IInputArrayOfArrays diamondCorners, IInputArray diamondIds, MCvScalar borderColor) { using InputOutputArray inputOutputArray = image.GetInputOutputArray(); using InputArray inputArray = diamondCorners.GetInputArray(); using InputArray inputArray2 = ((diamondIds == null) ? InputArray.GetEmpty() : diamondIds.GetInputArray()); cveArucoDrawDetectedDiamonds(inputOutputArray, inputArray, inputArray2, ref borderColor); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveArucoDrawDetectedDiamonds(IntPtr image, IntPtr diamondCorners, IntPtr diamondIds, ref MCvScalar borderColor); public static void DrawCharucoDiamond(Dictionary dictionary, int[] ids, int squareLength, int markerLength, IOutputArray img, int marginSize = 0, int borderBits = 1) { GCHandle gCHandle = GCHandle.Alloc(ids, GCHandleType.Pinned); using (OutputArray outputArray = img.GetOutputArray()) { cveArucoDrawCharucoDiamond(dictionary, gCHandle.AddrOfPinnedObject(), squareLength, markerLength, outputArray, marginSize, borderBits); } gCHandle.Free(); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveArucoDrawCharucoDiamond(IntPtr dictionary, IntPtr ids, int squareLength, int markerLength, IntPtr img, int marginSize, int borderBits); public static void DrawPlanarBoard(IBoard board, Size outSize, IOutputArray img, int marginSize = 0, int borderBits = 1) { using OutputArray outputArray = img.GetOutputArray(); cveArucoDrawPlanarBoard(board.BoardPtr, ref outSize, outputArray, marginSize, borderBits); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveArucoDrawPlanarBoard(IntPtr board, ref Size outSize, IntPtr img, int marginSize, int borderBits); public static int EstimatePoseBoard(IInputArrayOfArrays corners, IInputArray ids, IBoard board, IInputArray cameraMatrix, IInputArray distCoeffs, IInputOutputArray rvec, IInputOutputArray tvec, bool useExtrinsicGuess = false) { using InputArray inputArray = corners.GetInputArray(); using InputArray inputArray2 = ids.GetInputArray(); using InputArray inputArray3 = cameraMatrix.GetInputArray(); using InputArray inputArray4 = distCoeffs.GetInputArray(); using InputOutputArray inputOutputArray = rvec.GetInputOutputArray(); using InputOutputArray inputOutputArray2 = tvec.GetInputOutputArray(); return cveArucoEstimatePoseBoard(inputArray, inputArray2, board.BoardPtr, inputArray3, inputArray4, inputOutputArray, inputOutputArray2, useExtrinsicGuess); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int cveArucoEstimatePoseBoard(IntPtr corners, IntPtr ids, IntPtr board, IntPtr cameraMatrix, IntPtr distCoeffs, IntPtr rvec, IntPtr tvec, [MarshalAs(UnmanagedType.U1)] bool useExtrinsicGuess); public static void GetBoardObjectAndImagePoints(IBoard board, IInputArray detectedCorners, IInputArray detectedIds, IOutputArray objPoints, IOutputArray imgPoints) { using InputArray inputArray = detectedCorners.GetInputArray(); using InputArray inputArray2 = detectedIds.GetInputArray(); using OutputArray outputArray = objPoints.GetOutputArray(); using OutputArray outputArray2 = imgPoints.GetOutputArray(); cveArucoGetBoardObjectAndImagePoints(board.BoardPtr, inputArray, inputArray2, outputArray, outputArray2); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveArucoGetBoardObjectAndImagePoints(IntPtr board, IntPtr detectedCorners, IntPtr detectedIds, IntPtr objPoints, IntPtr imgPoints); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveArucoGetPredefinedDictionary(Dictionary.PredefinedDictionaryName name, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveArucoDictionaryCreate1(int nMarkers, int markerSize, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveArucoDictionaryCreate2(int nMarkers, int markerSize, IntPtr baseDictionary, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveArucoDictionaryRelease(ref IntPtr dict, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveArucoGridBoardCreate(int markersX, int markersY, float markerLength, float markerSeparation, IntPtr dictionary, int firstMarker, ref IntPtr boardPtr, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveArucoGridBoardRelease(ref IntPtr gridBoard, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveArucoGridBoardDraw(IntPtr gridBoard, ref Size outSize, IntPtr img, int marginSize, int borderBits); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveCharucoBoardCreate(int squaresX, int squaresY, float squareLength, float markerLength, IntPtr dictionary, ref IntPtr boardPtr, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveCharucoBoardDraw(IntPtr charucoBoard, ref Size outSize, IntPtr img, int marginSize, int borderBits); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveCharucoBoardRelease(ref IntPtr charucoBoard, ref IntPtr sharedPtr); } public struct DetectorParameters { public enum RefinementMethod { None, Subpix, Contour } public int AdaptiveThreshWinSizeMin; public int AdaptiveThreshWinSizeMax; public int AdaptiveThreshWinSizeStep; public double AdaptiveThreshConstant; public double MinMarkerPerimeterRate; public double MaxMarkerPerimeterRate; public double PolygonalApproxAccuracyRate; public double MinCornerDistanceRate; public int MinDistanceToBorder; public double MinMarkerDistanceRate; public RefinementMethod CornerRefinementMethod; public int CornerRefinementWinSize; public int CornerRefinementMaxIterations; public double CornerRefinementMinAccuracy; public int MarkerBorderBits; public int PerspectiveRemovePixelPerCell; public double PerspectiveRemoveIgnoredMarginPerCell; public double MaxErroneousBitsInBorderRate; public double MinOtsuStdDev; public double ErrorCorrectionRate; public float AprilTagQuadDecimate; public float AprilTagQuadSigma; public int AprilTagMinClusterPixels; public int AprilTagMaxNmaxima; public float AprilTagCriticalRad; public float AprilTagMaxLineFitMse; public int AprilTagMinWhiteBlackDiff; public int AprilTagDeglitch; [MarshalAs(UnmanagedType.U1)] public bool DetectInvertedMarker; public static DetectorParameters GetDefault() { DetectorParameters parameters = default(DetectorParameters); ArucoInvoke.cveArucoDetectorParametersGetDefault(ref parameters); return parameters; } } public class Dictionary : UnmanagedObject { public enum PredefinedDictionaryName { Dict4X4_50, Dict4X4_100, Dict4X4_250, Dict4X4_1000, Dict5X5_50, Dict5X5_100, Dict5X5_250, Dict5X5_1000, Dict6X6_50, Dict6X6_100, Dict6X6_250, Dict6X6_1000, Dict7X7_50, Dict7X7_100, Dict7X7_250, Dict7X7_1000, DictArucoOriginal } private IntPtr _sharedPtr; public Dictionary(PredefinedDictionaryName name) { _ptr = ArucoInvoke.cveArucoGetPredefinedDictionary(name, ref _sharedPtr); } public Dictionary(int nMarkers, int markerSize) { _ptr = ArucoInvoke.cveArucoDictionaryCreate1(nMarkers, markerSize, ref _sharedPtr); } public Dictionary(int nMarkers, int markerSize, Dictionary baseDictionary) { _ptr = ArucoInvoke.cveArucoDictionaryCreate2(nMarkers, markerSize, baseDictionary._sharedPtr, ref _sharedPtr); } protected override void DisposeObject() { if (_ptr != IntPtr.Zero) { ArucoInvoke.cveArucoDictionaryRelease(ref _ptr, ref _sharedPtr); } } } public interface IBoard { IntPtr BoardPtr { get; } } public class GridBoard : UnmanagedObject, IBoard { private IntPtr _boardPtr; private IntPtr _sharedPtr; public IntPtr BoardPtr => _boardPtr; public GridBoard(int markersX, int markersY, float markerLength, float markerSeparation, Dictionary dictionary, int firstMarker = 0) { _ptr = ArucoInvoke.cveArucoGridBoardCreate(markersX, markersY, markerLength, markerSeparation, dictionary, firstMarker, ref _boardPtr, ref _sharedPtr); } public void Draw(Size outSize, IOutputArray img, int marginSize = 0, int borderBits = 1) { using OutputArray outputArray = img.GetOutputArray(); ArucoInvoke.cveArucoGridBoardDraw(_ptr, ref outSize, outputArray, marginSize, borderBits); } protected override void DisposeObject() { if (_ptr != IntPtr.Zero) { ArucoInvoke.cveArucoGridBoardRelease(ref _ptr, ref _sharedPtr); } _boardPtr = IntPtr.Zero; } } public class CharucoBoard : UnmanagedObject, IBoard { private IntPtr _boardPtr; private IntPtr _sharedPtr; public IntPtr BoardPtr => _boardPtr; public CharucoBoard(int squaresX, int squaresY, float squareLength, float markerLength, Dictionary dictionary) { _ptr = ArucoInvoke.cveCharucoBoardCreate(squaresX, squaresY, squareLength, markerLength, dictionary, ref _boardPtr, ref _sharedPtr); } public void Draw(Size outSize, IOutputArray img, int margindSize = 0, int borderBits = 1) { using OutputArray outputArray = img.GetOutputArray(); ArucoInvoke.cveCharucoBoardDraw(_ptr, ref outSize, outputArray, margindSize, borderBits); } protected override void DisposeObject() { if (_ptr != IntPtr.Zero) { ArucoInvoke.cveCharucoBoardRelease(ref _ptr, ref _sharedPtr); } _boardPtr = IntPtr.Zero; } } } namespace Emgu.CV.Plot { public class Plot2d : UnmanagedObject { private IntPtr _sharedPtr; public Plot2d(IInputArray data) { using InputArray inputArray = data.GetInputArray(); _ptr = PlotInvoke.cvePlot2dCreateFrom(inputArray, ref _sharedPtr); } public Plot2d(IInputArray dataX, IInputArray dataY) { using InputArray inputArray = dataX.GetInputArray(); using InputArray inputArray2 = dataY.GetInputArray(); _ptr = PlotInvoke.cvePlot2dCreateFromXY(inputArray, inputArray2, ref _sharedPtr); } public void Render(IOutputArray result) { using OutputArray outputArray = result.GetOutputArray(); PlotInvoke.cvePlot2dRender(_ptr, outputArray); } public void SetPlotLineColor(MCvScalar plotLineColor) { PlotInvoke.cvePlot2dSetPlotLineColor(_ptr, ref plotLineColor); } public void SetPlotBackgroundColor(MCvScalar plotBackgroundColor) { PlotInvoke.cvePlot2dSetPlotBackgroundColor(_ptr, ref plotBackgroundColor); } public void SetPlotAxisColor(MCvScalar plotAxisColor) { PlotInvoke.cvePlot2dSetPlotAxisColor(_ptr, ref plotAxisColor); } public void SetPlotGridColor(MCvScalar plotGridColor) { PlotInvoke.cvePlot2dSetPlotGridColor(_ptr, ref plotGridColor); } public void SetPlotTextColor(MCvScalar plotTextColor) { PlotInvoke.cvePlot2dSetPlotTextColor(_ptr, ref plotTextColor); } public void SetPlotSize(int width, int height) { PlotInvoke.cvePlot2dSetPlotSize(_ptr, width, height); } protected override void DisposeObject() { if (_ptr != IntPtr.Zero) { PlotInvoke.cvePlot2dRelease(ref _ptr, ref _sharedPtr); } } public void SetMinX(double value) { PlotInvoke.cvePlot2dSetMinX(_ptr, value); } public void SetMinY(double value) { PlotInvoke.cvePlot2dSetMinY(_ptr, value); } public void SetMaxX(double value) { PlotInvoke.cvePlot2dSetMaxX(_ptr, value); } public void SetMaxY(double value) { PlotInvoke.cvePlot2dSetMaxY(_ptr, value); } public void SetPlotLineWidth(int value) { PlotInvoke.cvePlot2dSetPlotLineWidth(_ptr, value); } public void SetGridLinesNumber(int value) { PlotInvoke.cvePlot2dSetGridLinesNumber(_ptr, value); } public void SetPointIdxToPrint(int value) { PlotInvoke.cvePlot2dSetPointIdxToPrint(_ptr, value); } public void SetInvertOrientation(bool value) { PlotInvoke.cvePlot2dSetInvertOrientation(_ptr, value); } public void SetShowText(bool value) { PlotInvoke.cvePlot2dSetShowText(_ptr, value); } public void SetShowGrid(bool value) { PlotInvoke.cvePlot2dSetShowGrid(_ptr, value); } public void SetNeedPlotLine(bool value) { PlotInvoke.cvePlot2dSetNeedPlotLine(_ptr, value); } } public static class PlotInvoke { static PlotInvoke() { CvInvoke.Init(); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cvePlot2dCreateFrom(IntPtr data, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cvePlot2dCreateFromXY(IntPtr dataX, IntPtr dataY, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cvePlot2dRender(IntPtr plot, IntPtr result); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cvePlot2dRelease(ref IntPtr plot, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cvePlot2dSetPlotLineColor(IntPtr plot, ref MCvScalar plotLineColor); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cvePlot2dSetPlotBackgroundColor(IntPtr plot, ref MCvScalar plotBackgroundColor); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cvePlot2dSetPlotAxisColor(IntPtr plot, ref MCvScalar plotAxisColor); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cvePlot2dSetPlotGridColor(IntPtr plot, ref MCvScalar plotGridColor); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cvePlot2dSetPlotTextColor(IntPtr plot, ref MCvScalar plotTextColor); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cvePlot2dSetPlotSize(IntPtr plot, int plotSizeWidth, int plotSizeHeight); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cvePlot2dSetMinX(IntPtr obj, double val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cvePlot2dSetMinY(IntPtr obj, double val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cvePlot2dSetMaxX(IntPtr obj, double val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cvePlot2dSetMaxY(IntPtr obj, double val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cvePlot2dSetPlotLineWidth(IntPtr obj, int val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cvePlot2dSetGridLinesNumber(IntPtr obj, int val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cvePlot2dSetPointIdxToPrint(IntPtr obj, int val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cvePlot2dSetInvertOrientation(IntPtr obj, [MarshalAs(UnmanagedType.U1)] bool val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cvePlot2dSetShowText(IntPtr obj, [MarshalAs(UnmanagedType.U1)] bool val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cvePlot2dSetShowGrid(IntPtr obj, [MarshalAs(UnmanagedType.U1)] bool val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cvePlot2dSetNeedPlotLine(IntPtr obj, [MarshalAs(UnmanagedType.U1)] bool val); } } namespace Emgu.CV.Legacy { public class MultiTracker : UnmanagedObject { public MultiTracker() { _ptr = TrackingInvoke.cveMultiTrackerCreate(); } public bool Add(Tracker tracker, IInputArray image, Rectangle boundingBox) { using InputArray inputArray = image.GetInputArray(); return TrackingInvoke.cveMultiTrackerAdd(_ptr, tracker, inputArray, ref boundingBox); } public bool Update(Mat image, VectorOfRect boundingBox) { return TrackingInvoke.cveMultiTrackerUpdate(_ptr, image, boundingBox); } public Rectangle[] GetObjects() { using VectorOfRect vectorOfRect = new VectorOfRect(); TrackingInvoke.cveMultiTrackerGetObjects(_ptr, vectorOfRect); return vectorOfRect.ToArray(); } protected override void DisposeObject() { if (_ptr != IntPtr.Zero) { TrackingInvoke.cveMultiTrackerRelease(ref _ptr); } } } public abstract class Tracker : UnmanagedObject { protected IntPtr _trackerPtr; public bool Init(Mat image, Rectangle boundingBox) { return TrackingInvoke.cveLegacyTrackerInit(_trackerPtr, image, ref boundingBox); } public bool Update(Mat image, out Rectangle boundingBox) { boundingBox = default(Rectangle); return TrackingInvoke.cveLegacyTrackerUpdate(_trackerPtr, image, ref boundingBox); } protected override void DisposeObject() { _trackerPtr = IntPtr.Zero; } } public class TrackerBoosting : Tracker { private IntPtr _sharedPtr; public TrackerBoosting(int numClassifiers = 100, float samplerOverlap = 0.99f, float samplerSearchFactor = 1.8f, int iterationInit = 50, int featureSetNumFeatures = 1050) { TrackingInvoke.cveTrackerBoostingCreate(numClassifiers, samplerOverlap, samplerSearchFactor, iterationInit, featureSetNumFeatures, ref _trackerPtr, ref _sharedPtr); } protected override void DisposeObject() { if (IntPtr.Zero != _ptr) { TrackingInvoke.cveTrackerBoostingRelease(ref _ptr, ref _sharedPtr); } base.DisposeObject(); } } public class TrackerMedianFlow : Tracker { private IntPtr _sharedPtr; public TrackerMedianFlow(int pointsInGrid, Size winSize, int maxLevel, MCvTermCriteria termCriteria, Size winSizeNCC, double maxMedianLengthOfDisplacementDifference = 10.0) { TrackingInvoke.cveTrackerMedianFlowCreate(pointsInGrid, ref winSize, maxLevel, ref termCriteria, ref winSizeNCC, maxMedianLengthOfDisplacementDifference, ref _trackerPtr, ref _sharedPtr); } protected override void DisposeObject() { if (IntPtr.Zero != _ptr) { TrackingInvoke.cveTrackerMedianFlowRelease(ref _ptr, ref _sharedPtr); } base.DisposeObject(); } } public class TrackerMOSSE : Tracker { private IntPtr _sharedPtr; public TrackerMOSSE() { _ptr = TrackingInvoke.cveTrackerMOSSECreate(ref _trackerPtr, ref _sharedPtr); } protected override void DisposeObject() { if (IntPtr.Zero != _ptr) { TrackingInvoke.cveTrackerMOSSERelease(ref _ptr, ref _sharedPtr); } base.DisposeObject(); } } public class TrackerTLD : Tracker { private IntPtr _sharedPtr; public TrackerTLD() { _ptr = TrackingInvoke.cveTrackerTLDCreate(ref _trackerPtr, ref _sharedPtr); } protected override void DisposeObject() { if (IntPtr.Zero != _ptr) { TrackingInvoke.cveTrackerTLDRelease(ref _ptr, ref _sharedPtr); } base.DisposeObject(); } } } namespace Emgu.CV.XPhoto { public class GrayworldWB : WhiteBalancer { private IntPtr _sharedPtr; public float SaturationThreshold { get { return XPhotoInvoke.cveGrayworldWBGetSaturationThreshold(_ptr); } set { XPhotoInvoke.cveGrayworldWBSetSaturationThreshold(_ptr, value); } } public GrayworldWB() { _ptr = XPhotoInvoke.cveGrayworldWBCreate(ref _whiteBalancerPtr, ref _sharedPtr); } protected override void DisposeObject() { if (_ptr != IntPtr.Zero) { XPhotoInvoke.cveGrayworldWBRelease(ref _sharedPtr); _ptr = IntPtr.Zero; } base.DisposeObject(); } } public static class XPhotoInvoke { public enum InpaintType { Shiftmap, FsrBest, FsrFast } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveGrayworldWBCreate(ref IntPtr whiteBalancer, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveGrayworldWBRelease(ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern float cveGrayworldWBGetSaturationThreshold(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveGrayworldWBSetSaturationThreshold(IntPtr obj, float val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveLearningBasedWBCreate(ref IntPtr whiteBalancer, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveLearningBasedWBRelease(ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int cveLearningBasedWBGetRangeMaxVal(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveLearningBasedWBSetRangeMaxVal(IntPtr obj, int val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern float cveLearningBasedWBGetSaturationThreshold(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveLearningBasedWBSetSaturationThreshold(IntPtr obj, float val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int cveLearningBasedWBGetHistBinNum(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveLearningBasedWBSetHistBinNum(IntPtr obj, int val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveSimpleWBCreate(ref IntPtr whiteBalancer, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveSimpleWBRelease(ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern float cveSimpleWBGetInputMin(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveSimpleWBSetInputMin(IntPtr obj, float val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern float cveSimpleWBGetInputMax(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveSimpleWBSetInputMax(IntPtr obj, float val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern float cveSimpleWBGetOutputMin(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveSimpleWBSetOutputMin(IntPtr obj, float val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern float cveSimpleWBGetOutputMax(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveSimpleWBSetOutputMax(IntPtr obj, float val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern float cveSimpleWBGetP(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveSimpleWBSetP(IntPtr obj, float val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveTonemapDurandCreate(float gamma, float contrast, float saturation, float sigmaSpace, float sigmaColor, ref IntPtr tonemap, ref IntPtr algorithm, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveTonemapDurandRelease(ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern float cveTonemapDurandGetSaturation(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveTonemapDurandSetSaturation(IntPtr obj, float val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern float cveTonemapDurandGetContrast(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveTonemapDurandSetContrast(IntPtr obj, float val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern float cveTonemapDurandGetSigmaSpace(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveTonemapDurandSetSigmaSpace(IntPtr obj, float val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern float cveTonemapDurandGetSigmaColor(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveTonemapDurandSetSigmaColor(IntPtr obj, float val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveWhiteBalancerBalanceWhite(IntPtr whiteBalancer, IntPtr src, IntPtr dst); static XPhotoInvoke() { CvInvoke.Init(); } public static void DctDenoising(Mat src, Mat dst, double sigma, int psize = 16) { cveDctDenoising(src, dst, sigma, psize); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveDctDenoising(IntPtr src, IntPtr dst, double sigma, int psize); public static void Inpaint(Mat src, Mat mask, Mat dst, InpaintType algorithmType) { cveXInpaint(src, mask, dst, algorithmType); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveXInpaint(IntPtr src, IntPtr mask, IntPtr dst, InpaintType algorithmType); public static void ApplyChannelGains(IInputArray src, IOutputArray dst, float gainB, float gainG, float gainR) { using InputArray inputArray = src.GetInputArray(); using OutputArray outputArray = dst.GetOutputArray(); cveApplyChannelGains(inputArray, outputArray, gainB, gainG, gainR); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveApplyChannelGains(IntPtr src, IntPtr dst, float gainB, float gainG, float gainR); public static void Bm3dDenoising(IInputArray src, IInputOutputArray dstStep1, IOutputArray dstStep2, float h = 1f, int templateWindowSize = 4, int searchWindowSize = 16, int blockMatchingStep1 = 2500, int blockMatchingStep2 = 400, int groupSize = 8, int slidingStep = 1, float beta = 2f, NormType normType = NormType.L2, Bm3dSteps step = Bm3dSteps.All, TransformTypes transformType = TransformTypes.Haar) { using InputArray inputArray = src.GetInputArray(); using InputOutputArray inputOutputArray = dstStep1.GetInputOutputArray(); using OutputArray outputArray = dstStep2.GetOutputArray(); cveBm3dDenoising1(inputArray, inputOutputArray, outputArray, h, templateWindowSize, searchWindowSize, blockMatchingStep1, blockMatchingStep2, groupSize, slidingStep, beta, normType, step, transformType); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveBm3dDenoising1(IntPtr src, IntPtr dstStep1, IntPtr dstStep2, float h, int templateWindowSize, int searchWindowSize, int blockMatchingStep1, int blockMatchingStep2, int groupSize, int slidingStep, float beta, NormType normType, Bm3dSteps step, TransformTypes transformType); public static void Bm3dDenoising(IInputArray src, IOutputArray dst, float h = 1f, int templateWindowSize = 4, int searchWindowSize = 16, int blockMatchingStep1 = 2500, int blockMatchingStep2 = 400, int groupSize = 8, int slidingStep = 1, float beta = 2f, NormType normType = NormType.L2, Bm3dSteps step = Bm3dSteps.All, TransformTypes transformType = TransformTypes.Haar) { using InputArray inputArray = src.GetInputArray(); using OutputArray outputArray = dst.GetOutputArray(); cveBm3dDenoising2(inputArray, outputArray, h, templateWindowSize, searchWindowSize, blockMatchingStep1, blockMatchingStep2, groupSize, slidingStep, beta, normType, step, transformType); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveBm3dDenoising2(IntPtr src, IntPtr dst, float h, int templateWindowSize, int searchWindowSize, int blockMatchingStep1, int blockMatchingStep2, int groupSize, int slidingStep, float beta, NormType normType, Bm3dSteps step, TransformTypes transformType); public static void OilPainting(IInputArray src, IOutputArray dst, int size, int dynRatio, ColorConversion code = ColorConversion.Bgr2Gray) { using InputArray inputArray = src.GetInputArray(); using OutputArray outputArray = dst.GetOutputArray(); cveOilPainting(inputArray, outputArray, size, dynRatio, code); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveOilPainting(IntPtr src, IntPtr dst, int size, int dynRatio, ColorConversion code); } public class LearningBasedWB : WhiteBalancer { private IntPtr _sharedPtr; public int RangeMaxVal { get { return XPhotoInvoke.cveLearningBasedWBGetRangeMaxVal(_ptr); } set { XPhotoInvoke.cveLearningBasedWBSetRangeMaxVal(_ptr, value); } } public float SaturationThreshold { get { return XPhotoInvoke.cveLearningBasedWBGetSaturationThreshold(_ptr); } set { XPhotoInvoke.cveLearningBasedWBSetSaturationThreshold(_ptr, value); } } public int HistBinNum { get { return XPhotoInvoke.cveLearningBasedWBGetHistBinNum(_ptr); } set { XPhotoInvoke.cveLearningBasedWBSetHistBinNum(_ptr, value); } } public LearningBasedWB() { _ptr = XPhotoInvoke.cveLearningBasedWBCreate(ref _whiteBalancerPtr, ref _sharedPtr); } protected override void DisposeObject() { if (_ptr != IntPtr.Zero) { XPhotoInvoke.cveLearningBasedWBRelease(ref _sharedPtr); _ptr = IntPtr.Zero; } base.DisposeObject(); } } public class SimpleWB : WhiteBalancer { private IntPtr _sharedPtr; public float InputMin { get { return XPhotoInvoke.cveSimpleWBGetInputMin(_ptr); } set { XPhotoInvoke.cveSimpleWBSetInputMin(_ptr, value); } } public float InputMax { get { return XPhotoInvoke.cveSimpleWBGetInputMax(_ptr); } set { XPhotoInvoke.cveSimpleWBSetInputMax(_ptr, value); } } public float OutputMin { get { return XPhotoInvoke.cveSimpleWBGetOutputMin(_ptr); } set { XPhotoInvoke.cveSimpleWBSetOutputMin(_ptr, value); } } public float OutputMax { get { return XPhotoInvoke.cveSimpleWBGetOutputMax(_ptr); } set { XPhotoInvoke.cveSimpleWBSetOutputMax(_ptr, value); } } public float P { get { return XPhotoInvoke.cveSimpleWBGetP(_ptr); } set { XPhotoInvoke.cveSimpleWBSetP(_ptr, value); } } public SimpleWB() { _ptr = XPhotoInvoke.cveSimpleWBCreate(ref _whiteBalancerPtr, ref _sharedPtr); } protected override void DisposeObject() { if (_ptr != IntPtr.Zero) { XPhotoInvoke.cveSimpleWBRelease(ref _sharedPtr); _ptr = IntPtr.Zero; } base.DisposeObject(); } } public class TonemapDurand : Tonemap { private IntPtr _sharedPtr; public float Saturation { get { return XPhotoInvoke.cveTonemapDurandGetSaturation(_ptr); } set { XPhotoInvoke.cveTonemapDurandSetSaturation(_ptr, value); } } public float Contrast { get { return XPhotoInvoke.cveTonemapDurandGetContrast(_ptr); } set { XPhotoInvoke.cveTonemapDurandSetContrast(_ptr, value); } } public float SigmaSpace { get { return XPhotoInvoke.cveTonemapDurandGetSigmaSpace(_ptr); } set { XPhotoInvoke.cveTonemapDurandSetSigmaSpace(_ptr, value); } } public float SigmaColor { get { return XPhotoInvoke.cveTonemapDurandGetSigmaColor(_ptr); } set { XPhotoInvoke.cveTonemapDurandSetSigmaColor(_ptr, value); } } public TonemapDurand(float gamma = 1f, float contrast = 4f, float saturation = 1f, float sigmaSpace = 2f, float sigmaColor = 2f) : base(IntPtr.Zero, IntPtr.Zero) { _ptr = XPhotoInvoke.cveTonemapDurandCreate(gamma, contrast, saturation, sigmaSpace, sigmaColor, ref _tonemapPtr, ref _algorithmPtr, ref _sharedPtr); } protected override void DisposeObject() { if (IntPtr.Zero != _ptr) { XPhotoInvoke.cveTonemapDurandRelease(ref _sharedPtr); _ptr = IntPtr.Zero; _tonemapPtr = IntPtr.Zero; _algorithmPtr = IntPtr.Zero; } } } public abstract class WhiteBalancer : UnmanagedObject { protected IntPtr _whiteBalancerPtr; public void BalanceWhite(IInputArray src, IOutputArray dst) { using InputArray inputArray = src.GetInputArray(); using OutputArray outputArray = dst.GetOutputArray(); XPhotoInvoke.cveWhiteBalancerBalanceWhite(_whiteBalancerPtr, inputArray, outputArray); } protected override void DisposeObject() { _whiteBalancerPtr = IntPtr.Zero; } } public enum TransformTypes { Haar } public enum Bm3dSteps { All, Step1, Step2 } } namespace Emgu.CV.XImgproc { public class DisparityWLSFilter : SharedPtrObject, IAlgorithm, IDisparityFilter { private IntPtr _algorithm; private IntPtr _disparityFilterPtr; public IntPtr AlgorithmPtr => _algorithm; public IntPtr DisparityFilterPtr => _disparityFilterPtr; public DisparityWLSFilter(IStereoMatcher matcherLeft) { _ptr = XImgprocInvoke.cveCreateDisparityWLSFilter(matcherLeft.StereoMatcherPtr, ref _disparityFilterPtr, ref _algorithm, ref _sharedPtr); } public DisparityWLSFilter(bool useConfidence) { _ptr = XImgprocInvoke.cveCreateDisparityWLSFilterGeneric(useConfidence, ref _disparityFilterPtr, ref _algorithm, ref _sharedPtr); } protected override void DisposeObject() { if (_sharedPtr != IntPtr.Zero) { XImgprocInvoke.cveDisparityWLSFilterRelease(ref _sharedPtr); _ptr = IntPtr.Zero; _algorithm = IntPtr.Zero; _disparityFilterPtr = IntPtr.Zero; } } } public class RightMatcher : SharedPtrObject, IStereoMatcher { public IntPtr StereoMatcherPtr => _ptr; public RightMatcher(IStereoMatcher matcherLeft) { _ptr = XImgprocInvoke.cveCreateRightMatcher(matcherLeft.StereoMatcherPtr, ref _sharedPtr); } protected override void DisposeObject() { if (_sharedPtr != IntPtr.Zero) { CvInvoke.cveStereoMatcherRelease(ref _sharedPtr); _ptr = IntPtr.Zero; } } } public static class XImgprocInvoke { [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveCreateDisparityWLSFilter(IntPtr matcherLeft, ref IntPtr disparityFilter, ref IntPtr algorithm, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveCreateRightMatcher(IntPtr matcherLeft, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveCreateDisparityWLSFilterGeneric([MarshalAs(UnmanagedType.U1)] bool useConfidence, ref IntPtr disparityFilter, ref IntPtr algorithm, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveDisparityWLSFilterRelease(ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveDTFilterCreate(IntPtr guide, double sigmaSpatial, double sigmaColor, DTFilter.Mode mode, int numIters, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveDTFilterFilter(IntPtr filter, IntPtr src, IntPtr dst, DepthType dDepth); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveDTFilterRelease(ref IntPtr filter, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveEdgeBoxesCreate(float alpha, float beta, float eta, float minScore, int maxBoxes, float edgeMinMag, float edgeMergeThr, float clusterMinMag, float maxAspectRatio, float minBoxArea, float gamma, float kappa, ref IntPtr algorithm, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveEdgeBoxesGetBoundingBoxes(IntPtr edgeBoxes, IntPtr edgeMap, IntPtr orientationMap, IntPtr boxes); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveEdgeBoxesRelease(ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveEdgeDrawingCreate(ref IntPtr algorithm, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveEdgeDrawingDetectEdges(IntPtr edgeDrawing, IntPtr src); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveEdgeDrawingGetEdgeImage(IntPtr edgeDrawing, IntPtr dst); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveEdgeDrawingGetGradientImage(IntPtr edgeDrawing, IntPtr dst); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveEdgeDrawingDetectLines(IntPtr edgeDrawing, IntPtr lines); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveEdgeDrawingDetectEllipses(IntPtr edgeDrawing, IntPtr ellipses); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveEdgeDrawingRelease(ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveFastLineDetectorCreate(int lengthThreshold, float distanceThreshold, double cannyThreshold1, double cannyThreshold2, int cannyApertureSize, [MarshalAs(UnmanagedType.U1)] bool doMerge, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveFastLineDetectorDetect(IntPtr fld, IntPtr image, IntPtr lines); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveFastLineDetectorDrawSegments(IntPtr fld, IntPtr image, IntPtr lines, [MarshalAs(UnmanagedType.U1)] bool drawArrow); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveFastLineDetectorRelease(ref IntPtr fld); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveGraphSegmentationCreate(double sigma, float k, int minSize, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveGraphSegmentationProcessImage(IntPtr segmentation, IntPtr src, IntPtr dst); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveGraphSegmentationRelease(ref IntPtr segmentation, ref IntPtr sharedPtr); public static void Filter(this IDisparityFilter filter, IInputArray disparityMapLeft, IInputArray leftView, IOutputArray filteredDisparityMap, IInputArray disparityMapRight = null, Rectangle roi = default(Rectangle), IInputArray rightView = null) { using InputArray inputArray = disparityMapLeft.GetInputArray(); using InputArray inputArray2 = leftView.GetInputArray(); using OutputArray outputArray = filteredDisparityMap.GetOutputArray(); using InputArray inputArray3 = ((disparityMapRight == null) ? InputArray.GetEmpty() : disparityMapRight.GetInputArray()); using InputArray inputArray4 = ((rightView == null) ? InputArray.GetEmpty() : rightView.GetInputArray()); cveDisparityFilterFilter(filter.DisparityFilterPtr, inputArray, inputArray2, outputArray, inputArray3, ref roi, inputArray4); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveDisparityFilterFilter(IntPtr disparityFilter, IntPtr disparityMapLeft, IntPtr leftView, IntPtr filteredDisparityMap, IntPtr disparityMapRight, ref Rectangle ROI, IntPtr rightView); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveRidgeDetectionFilterCreate(int ddepth, int dx, int dy, int ksize, int outDtype, double scale, double delta, BorderType borderType, ref IntPtr algorithm, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveRidgeDetectionFilterGetRidgeFilteredImage(IntPtr ridgeDetection, IntPtr img, IntPtr output); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveRidgeDetectionFilterRelease(ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveScanSegmentCreate(int imageWidth, int imageHeight, int numSuperpixels, int slices, [MarshalAs(UnmanagedType.U1)] bool mergeSmall, ref IntPtr algorithm, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveScanSegmentIterate(IntPtr scanSegment, IntPtr img); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveScanSegmentGetLabels(IntPtr scanSegment, IntPtr labelsOut); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveScanSegmentGetLabelContourMask(IntPtr scanSegment, IntPtr image, [MarshalAs(UnmanagedType.U1)] bool thickLine); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveScanSegmentRelease(ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int cveScanSegmentGetNumberOfSuperpixels(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveSelectiveSearchSegmentationCreate(ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveSelectiveSearchSegmentationSetBaseImage(IntPtr segmentation, IntPtr image); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveSelectiveSearchSegmentationSwitchToSingleStrategy(IntPtr segmentation, int k, float sigma); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveSelectiveSearchSegmentationSwitchToSelectiveSearchFast(IntPtr segmentation, int baseK, int incK, float sigma); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveSelectiveSearchSegmentationSwitchToSelectiveSearchQuality(IntPtr segmentation, int baseK, int incK, float sigma); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveSelectiveSearchSegmentationAddImage(IntPtr segmentation, IntPtr img); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveSelectiveSearchSegmentationProcess(IntPtr segmentation, IntPtr rects); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveSelectiveSearchSegmentationRelease(ref IntPtr segmentation, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveStructuredEdgeDetectionCreate(IntPtr model, IntPtr howToGetFeatures, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveStructuredEdgeDetectionDetectEdges(IntPtr detection, IntPtr src, IntPtr dst); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveStructuredEdgeDetectionRelease(ref IntPtr detection, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveRFFeatureGetterCreate(ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveRFFeatureGetterRelease(ref IntPtr getter, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveStructuredEdgeDetectionComputeOrientation(IntPtr detection, IntPtr src, IntPtr dst); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveStructuredEdgeDetectionEdgesNms(IntPtr detection, IntPtr edgeImage, IntPtr orientationImage, IntPtr dst, int r, int s, float m, [MarshalAs(UnmanagedType.U1)] bool isParallel); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveSuperpixelLSCCreate(IntPtr image, int regionSize, float ratio, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int cveSuperpixelLSCGetNumberOfSuperpixels(IntPtr lsc); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveSuperpixelLSCGetLabels(IntPtr lsc, IntPtr labelsOut); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveSuperpixelLSCGetLabelContourMask(IntPtr slic, IntPtr image, [MarshalAs(UnmanagedType.U1)] bool thickLine); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveSuperpixelLSCRelease(ref IntPtr lsc, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveSuperpixelLSCIterate(IntPtr lsc, int numIterations); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveSuperpixelSEEDSCreate(int imageWidth, int imageHeight, int imageChannels, int numSuperpixels, int numLevels, int prior, int histogramBins, [MarshalAs(UnmanagedType.U1)] bool doubleStep, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int cveSuperpixelSEEDSGetNumberOfSuperpixels(IntPtr seeds); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveSuperpixelSEEDSGetLabels(IntPtr seeds, IntPtr labelsOut); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveSuperpixelSEEDSGetLabelContourMask(IntPtr seeds, IntPtr image, [MarshalAs(UnmanagedType.U1)] bool thickLine); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveSuperpixelSEEDSRelease(ref IntPtr seeds, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveSuperpixelSEEDSIterate(IntPtr seeds, IntPtr img, int numIterations); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveSuperpixelSLICEnforceLabelConnectivity(IntPtr slic, int minElementSize); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveSuperpixelSLICCreate(IntPtr image, SupperpixelSLIC.Algorithm algorithm, int regionSize, float ruler, ref IntPtr sharePtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int cveSuperpixelSLICGetNumberOfSuperpixels(IntPtr slic); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveSuperpixelSLICGetLabels(IntPtr slic, IntPtr labelsOut); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveSuperpixelSLICGetLabelContourMask(IntPtr slic, IntPtr image, [MarshalAs(UnmanagedType.U1)] bool thickLine); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveSuperpixelSLICRelease(ref IntPtr slic, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveSuperpixelSLICIterate(IntPtr slic, int numIterations); static XImgprocInvoke() { CvInvoke.Init(); } public static void JointBilateralFilter(IInputArray joint, IInputArray src, IOutputArray dst, int d, double sigmaColor, double sigmaSpace, BorderType borderType = BorderType.Reflect101) { using InputArray inputArray = joint.GetInputArray(); using InputArray inputArray2 = src.GetInputArray(); using OutputArray outputArray = dst.GetOutputArray(); cveJointBilateralFilter(inputArray, inputArray2, outputArray, d, sigmaColor, sigmaSpace, borderType); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveJointBilateralFilter(IntPtr joint, IntPtr src, IntPtr dst, int d, double sigmaColor, double sigmaSpace, BorderType borderType); public static void BilateralTextureFilter(IInputArray src, IOutputArray dst, int fr = 3, int numIter = 1, double sigmaAlpha = -1.0, double sigmaAvg = -1.0) { using InputArray inputArray = src.GetInputArray(); using OutputArray outputArray = dst.GetOutputArray(); cveBilateralTextureFilter(inputArray, outputArray, fr, numIter, sigmaAlpha, sigmaAvg); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveBilateralTextureFilter(IntPtr src, IntPtr dst, int fr, int numIter, double sigmaAlpha, double sigmaAvg); public static void RollingGuidanceFilter(IInputArray src, IOutputArray dst, int d = -1, double sigmaColor = 25.0, double sigmaSpace = 3.0, int numOfIter = 4, BorderType borderType = BorderType.Reflect101) { using InputArray inputArray = src.GetInputArray(); using OutputArray outputArray = dst.GetOutputArray(); cveRollingGuidanceFilter(inputArray, outputArray, d, sigmaColor, sigmaSpace, numOfIter, borderType); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveRollingGuidanceFilter(IntPtr src, IntPtr dst, int d, double sigmaColor, double sigmaSpace, int numOfIter, BorderType borderType); public static void FastGlobalSmootherFilter(IInputArray guide, IInputArray src, IOutputArray dst, double lambda, double sigmaColor, double lambdaAttenuation = 0.25, int numIter = 3) { using InputArray inputArray = guide.GetInputArray(); using InputArray inputArray2 = src.GetInputArray(); using OutputArray outputArray = dst.GetOutputArray(); cveFastGlobalSmootherFilter(inputArray, inputArray2, outputArray, lambda, sigmaColor, lambdaAttenuation, numIter); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveFastGlobalSmootherFilter(IntPtr guide, IntPtr src, IntPtr dst, double lambda, double sigmaColor, double lambdaAttenuation, int numIter); public static void L0Smooth(IInputArray src, IOutputArray dst, double lambda = 0.02, double kappa = 2.0) { using InputArray inputArray = src.GetInputArray(); using OutputArray outputArray = dst.GetOutputArray(); cveL0Smooth(inputArray, outputArray, lambda, kappa); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveL0Smooth(IntPtr src, IntPtr dst, double lambda, double kappa); public static void AmFilter(IInputArray joint, IInputArray src, IOutputArray dst, double sigmaS, double sigmaR, bool adjustOutliers = false) { using InputArray inputArray = joint.GetInputArray(); using InputArray inputArray2 = src.GetInputArray(); using OutputArray outputArray = dst.GetOutputArray(); cveAmFilter(inputArray, inputArray2, outputArray, sigmaS, sigmaR, adjustOutliers); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveAmFilter(IntPtr joint, IntPtr src, IntPtr dst, double sigmaS, double sigmaR, [MarshalAs(UnmanagedType.U1)] bool adjustOutliers); public static void GuidedFilter(IInputArray guide, IInputArray src, IOutputArray dst, int radius, double eps, DepthType dDepth = DepthType.Default) { using InputArray inputArray = guide.GetInputArray(); using InputArray inputArray2 = src.GetInputArray(); using OutputArray outputArray = dst.GetOutputArray(); cveGuidedFilter(inputArray, inputArray2, outputArray, radius, eps, dDepth); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveGuidedFilter(IntPtr guide, IntPtr src, IntPtr dst, int radius, double eps, DepthType dDepth); public static void DtFilter(IInputArray guide, IInputArray src, IOutputArray dst, double sigmaSpatial, double sigmaColor, DtFilterType mode, int numIters = 3) { using InputArray inputArray = guide.GetInputArray(); using InputArray inputArray2 = src.GetInputArray(); using OutputArray outputArray = dst.GetOutputArray(); cveDtFilter(inputArray, inputArray2, outputArray, sigmaSpatial, sigmaColor, mode, numIters); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveDtFilter(IntPtr guide, IntPtr src, IntPtr dst, double sigmaSpatial, double sigmaColor, DtFilterType mode, int numIters); public static void NiBlackThreshold(IInputArray src, IOutputArray dst, double maxValue, LocalBinarizationMethods type, int blockSize, double delta) { using InputArray inputArray = src.GetInputArray(); using OutputArray outputArray = dst.GetOutputArray(); cveNiBlackThreshold(inputArray, outputArray, maxValue, type, blockSize, delta); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveNiBlackThreshold(IntPtr src, IntPtr dst, double maxValue, LocalBinarizationMethods type, int blockSize, double delta); public static void CovarianceEstimation(IInputArray src, IOutputArray dst, int windowRows, int windowCols) { using InputArray inputArray = src.GetInputArray(); using OutputArray outputArray = dst.GetOutputArray(); cveCovarianceEstimation(inputArray, outputArray, windowRows, windowCols); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveCovarianceEstimation(IntPtr src, IntPtr dst, int windowRows, int windowCols); public static void WeightedMedianFilter(IInputArray joint, IInputArray src, IOutputArray dst, int r, double sigma = 25.5, WMFWeightType weightType = WMFWeightType.Exp, Mat mask = null) { using InputArray inputArray = joint.GetInputArray(); using InputArray inputArray2 = src.GetInputArray(); using OutputArray outputArray = dst.GetOutputArray(); cveWeightedMedianFilter(inputArray, inputArray2, outputArray, r, sigma, weightType, (mask == null) ? IntPtr.Zero : ((IntPtr)mask)); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveWeightedMedianFilter(IntPtr joint, IntPtr src, IntPtr dst, int r, double sigma, WMFWeightType weightType, IntPtr mask); public static void GradientPaillouY(IInputArray op, IOutputArray dst, double alpha, double omega) { using InputArray inputArray = op.GetInputArray(); using OutputArray outputArray = dst.GetOutputArray(); cveGradientPaillouY(inputArray, outputArray, alpha, omega); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveGradientPaillouY(IntPtr op, IntPtr dst, double alpha, double omega); public static void GradientPaillouX(IInputArray op, IOutputArray dst, double alpha, double omega) { using InputArray inputArray = op.GetInputArray(); using OutputArray outputArray = dst.GetOutputArray(); cveGradientPaillouX(inputArray, outputArray, alpha, omega); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveGradientPaillouX(IntPtr op, IntPtr dst, double alpha, double omega); public static void GradientDericheY(IInputArray op, IOutputArray dst, double alphaDerive, double alphaMean) { using InputArray inputArray = op.GetInputArray(); using OutputArray outputArray = dst.GetOutputArray(); cveGradientDericheY(inputArray, outputArray, alphaDerive, alphaMean); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveGradientDericheY(IntPtr op, IntPtr dst, double alphaDerive, double alphaMean); public static void GradientDericheX(IInputArray op, IOutputArray dst, double alphaDerive, double alphaMean) { using InputArray inputArray = op.GetInputArray(); using OutputArray outputArray = dst.GetOutputArray(); cveGradientDericheX(inputArray, outputArray, alphaDerive, alphaMean); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveGradientDericheX(IntPtr op, IntPtr dst, double alphaDerive, double alphaMean); public static void Thinning(IInputArray src, IOutputArray dst, ThinningTypes thinningType) { using InputArray inputArray = src.GetInputArray(); using OutputArray outputArray = dst.GetOutputArray(); cveThinning(inputArray, outputArray, thinningType); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveThinning(IntPtr src, IntPtr dst, ThinningTypes thinningType); public static void AnisotropicDiffusion(IInputArray src, IOutputArray dst, float alpha, float K, int niters) { using InputArray inputArray = src.GetInputArray(); using OutputArray outputArray = dst.GetOutputArray(); cveAnisotropicDiffusion(inputArray, outputArray, alpha, K, niters); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveAnisotropicDiffusion(IntPtr src, IntPtr dst, float alpha, float K, int niters); public static void BrightEdges(Mat original, Mat edgeview, int contrast, int shortrange, int longrange) { cveBrightEdges(original, edgeview, contrast, shortrange, longrange); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveBrightEdges(IntPtr original, IntPtr edgeview, int contrast, int shortrange, int longrange); public static void RadonTransform(IInputArray src, IOutputArray dst, double theta = 1.0, double startAngle = 0.0, double endAngle = 180.0, bool crop = false, bool norm = false) { using InputArray inputArray = src.GetInputArray(); using OutputArray outputArray = dst.GetOutputArray(); cveRadonTransform(inputArray, outputArray, theta, startAngle, endAngle, crop, norm); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveRadonTransform(IntPtr src, IntPtr dst, double theta, double startAngle, double endAngle, [MarshalAs(UnmanagedType.U1)] bool crop, [MarshalAs(UnmanagedType.U1)] bool norm); } public class DTFilter : UnmanagedObject { public enum Mode { NC, IC, RF } private IntPtr _sharedPtr; public DTFilter(IInputArray guide, double sigmaSpatial, double sigmaColor, Mode mode = Mode.NC, int numIters = 3) { using InputArray inputArray = guide.GetInputArray(); _ptr = XImgprocInvoke.cveDTFilterCreate(inputArray, sigmaSpatial, sigmaColor, mode, numIters, ref _sharedPtr); } public void Filter(IInputArray src, IOutputArray dst, DepthType dDepth = DepthType.Default) { using InputArray inputArray = src.GetInputArray(); using OutputArray outputArray = dst.GetOutputArray(); XImgprocInvoke.cveDTFilterFilter(_ptr, inputArray, outputArray, dDepth); } protected override void DisposeObject() { if (_ptr != IntPtr.Zero) { XImgprocInvoke.cveDTFilterRelease(ref _ptr, ref _sharedPtr); } } } public enum DtFilterType { NC, IC, RF } public class EdgeBoxes : SharedPtrObject, IAlgorithm { private IntPtr _algorithm; public IntPtr AlgorithmPtr => _algorithm; public EdgeBoxes(float alpha = 0.65f, float beta = 0.75f, float eta = 1f, float minScore = 0.01f, int maxBoxes = 10000, float edgeMinMag = 1f, float edgeMergeThr = 0.5f, float clusterMinMag = 0.5f, float maxAspectRatio = 3f, float minBoxArea = 1000f, float gamma = 2f, float kappa = 1.5f) { _ptr = XImgprocInvoke.cveEdgeBoxesCreate(alpha, beta, eta, minScore, maxBoxes, edgeMinMag, edgeMergeThr, clusterMinMag, maxAspectRatio, minBoxArea, gamma, kappa, ref _algorithm, ref _sharedPtr); } public Rectangle[] GetBoundingBoxes(IInputArray edgeMap, IInputArray orientationMap) { using InputArray inputArray = edgeMap.GetInputArray(); using InputArray inputArray2 = orientationMap.GetInputArray(); using VectorOfRect vectorOfRect = new VectorOfRect(); XImgprocInvoke.cveEdgeBoxesGetBoundingBoxes(_ptr, inputArray, inputArray2, vectorOfRect); return vectorOfRect.ToArray(); } protected override void DisposeObject() { if (_sharedPtr != IntPtr.Zero) { XImgprocInvoke.cveEdgeBoxesRelease(ref _sharedPtr); _ptr = IntPtr.Zero; _algorithm = IntPtr.Zero; } } } public class EdgeDrawing : SharedPtrObject, IAlgorithm { private IntPtr _algorithm; public IntPtr AlgorithmPtr => _algorithm; public EdgeDrawing() { _ptr = XImgprocInvoke.cveEdgeDrawingCreate(ref _algorithm, ref _sharedPtr); } protected override void DisposeObject() { if (_sharedPtr != IntPtr.Zero) { XImgprocInvoke.cveEdgeDrawingRelease(ref _sharedPtr); _ptr = IntPtr.Zero; _algorithm = IntPtr.Zero; } } public void DetectEdges(IInputArray src) { using InputArray inputArray = src.GetInputArray(); XImgprocInvoke.cveEdgeDrawingDetectEdges(_ptr, inputArray); } public void GetEdgeImage(IOutputArray dst) { using OutputArray outputArray = dst.GetOutputArray(); XImgprocInvoke.cveEdgeDrawingGetEdgeImage(_ptr, outputArray); } public void GetGradientImage(IOutputArray dst) { using OutputArray outputArray = dst.GetOutputArray(); XImgprocInvoke.cveEdgeDrawingGetGradientImage(_ptr, outputArray); } public void DetectLines(IOutputArray dst) { using OutputArray outputArray = dst.GetOutputArray(); XImgprocInvoke.cveEdgeDrawingDetectLines(_ptr, outputArray); } public void DetectEllipses(IOutputArray dst) { using OutputArray outputArray = dst.GetOutputArray(); XImgprocInvoke.cveEdgeDrawingDetectEllipses(_ptr, outputArray); } } public class FastLineDetector : SharedPtrObject { public FastLineDetector(int lengthThreshold = 10, float distanceThreshold = 1.4142135f, double cannyThreshold1 = 50.0, double cannyThreshold2 = 50.0, int cannyApertureSize = 3, bool doMerge = false) { _ptr = XImgprocInvoke.cveFastLineDetectorCreate(lengthThreshold, distanceThreshold, cannyThreshold1, cannyThreshold2, cannyApertureSize, doMerge, ref _sharedPtr); } public LineSegment2DF[] Detect(IInputArray image) { using InputArray inputArray = image.GetInputArray(); using Mat mat = new Mat(); using OutputArray outputArray = mat.GetOutputArray(); XImgprocInvoke.cveFastLineDetectorDetect(_ptr, inputArray, outputArray); float[] array = new float[mat.Total.ToInt32() * mat.ElementSize / 4]; LineSegment2DF[] array2 = new LineSegment2DF[array.Length / 4]; mat.CopyTo(array); for (int i = 0; i < array.Length / 4; i++) { array2[i] = new LineSegment2DF(new PointF(array[i * 4], array[i * 4 + 1]), new PointF(array[i * 4 + 2], array[i * 4 + 3])); } return array2; } public void DrawSegments(IInputOutputArray image, LineSegment2DF[] lines, bool drawArrows = false) { using InputOutputArray inputOutputArray = image.GetInputOutputArray(); using Mat mat = new Mat(lines.Length, 1, DepthType.Cv32F, 4); float[] array = new float[lines.Length * 4]; for (int i = 0; i < lines.Length; i++) { array[i * 4] = lines[i].P1.X; array[i * 4 + 1] = lines[i].P1.Y; array[i * 4 + 2] = lines[i].P2.X; array[i * 4 + 3] = lines[i].P2.Y; } mat.SetTo(array); using InputArray inputArray = mat.GetInputArray(); XImgprocInvoke.cveFastLineDetectorDrawSegments(_ptr, inputOutputArray, inputArray, drawArrows); } protected override void DisposeObject() { if (_sharedPtr != IntPtr.Zero) { XImgprocInvoke.cveFastLineDetectorRelease(ref _sharedPtr); _ptr = IntPtr.Zero; } } } public class GraphSegmentation : UnmanagedObject { private IntPtr _sharedPtr; public GraphSegmentation(double sigma = 0.5, float k = 300f, int minSize = 100) { _ptr = XImgprocInvoke.cveGraphSegmentationCreate(sigma, k, minSize, ref _sharedPtr); } public void ProcessImage(IInputArray src, IOutputArray dst) { using InputArray inputArray = src.GetInputArray(); using OutputArray outputArray = dst.GetOutputArray(); XImgprocInvoke.cveGraphSegmentationProcessImage(_ptr, inputArray, outputArray); } protected override void DisposeObject() { if (_ptr != IntPtr.Zero) { XImgprocInvoke.cveGraphSegmentationRelease(ref _ptr, ref _sharedPtr); } } } public interface IDisparityFilter { IntPtr DisparityFilterPtr { get; } } public enum LocalBinarizationMethods { Niblack, Sauvola, Wolf, NICK } public class RidgeDetectionFilter : SharedPtrObject, IAlgorithm { private IntPtr _algorithm; public IntPtr AlgorithmPtr => _algorithm; public RidgeDetectionFilter(DepthType dDepthType = DepthType.Cv32F, int dChannels = 1, int dx = 1, int dy = 1, int ksize = 3, DepthType outDepthType = DepthType.Cv8U, int outChannels = 1, double scale = 1.0, double delta = 0.0, BorderType borderType = BorderType.Reflect101) { _ptr = XImgprocInvoke.cveRidgeDetectionFilterCreate(CvInvoke.MakeType(dDepthType, dChannels), dx, dy, ksize, CvInvoke.MakeType(outDepthType, outChannels), scale, delta, borderType, ref _algorithm, ref _sharedPtr); } public void GetRidgeFilteredImage(IInputArray img, IOutputArray output) { using InputArray inputArray = img.GetInputArray(); using OutputArray outputArray = output.GetOutputArray(); XImgprocInvoke.cveRidgeDetectionFilterGetRidgeFilteredImage(_ptr, inputArray, outputArray); } protected override void DisposeObject() { if (_sharedPtr != IntPtr.Zero) { XImgprocInvoke.cveRidgeDetectionFilterRelease(ref _sharedPtr); _ptr = IntPtr.Zero; _algorithm = IntPtr.Zero; } } } public class ScanSegment : SharedPtrObject, IAlgorithm { private IntPtr _algorithm; public IntPtr AlgorithmPtr => _algorithm; public int NumberOfSuperpixels => XImgprocInvoke.cveScanSegmentGetNumberOfSuperpixels(_ptr); public ScanSegment(int imageWidth, int imageHeight, int numSuperpixels, int slices = 8, bool mergeSmall = true) { _ptr = XImgprocInvoke.cveScanSegmentCreate(imageWidth, imageHeight, numSuperpixels, slices, mergeSmall, ref _algorithm, ref _sharedPtr); } public void Iterate(IInputArray img) { using InputArray inputArray = img.GetInputArray(); XImgprocInvoke.cveScanSegmentIterate(_ptr, inputArray); } public void GetLabels(IOutputArray labelsOut) { using OutputArray outputArray = labelsOut.GetOutputArray(); XImgprocInvoke.cveScanSegmentGetLabels(_ptr, outputArray); } public void GetLabelContourMask(IOutputArray image, bool thickLine = false) { using OutputArray outputArray = image.GetOutputArray(); XImgprocInvoke.cveScanSegmentGetLabelContourMask(_ptr, outputArray, thickLine); } protected override void DisposeObject() { if (_sharedPtr != IntPtr.Zero) { XImgprocInvoke.cveScanSegmentRelease(ref _sharedPtr); _algorithm = IntPtr.Zero; _ptr = IntPtr.Zero; } } } public class SelectiveSearchSegmentation : UnmanagedObject { private IntPtr _sharedPtr; public SelectiveSearchSegmentation() { _ptr = XImgprocInvoke.cveSelectiveSearchSegmentationCreate(ref _sharedPtr); } public void SetBaseImage(IInputArray image) { using InputArray inputArray = image.GetInputArray(); XImgprocInvoke.cveSelectiveSearchSegmentationSetBaseImage(_ptr, inputArray); } public void SwitchToSingleStrategy(int k, float sigma) { XImgprocInvoke.cveSelectiveSearchSegmentationSwitchToSingleStrategy(_ptr, k, sigma); } public void SwitchToSelectiveSearchFast(int baseK = 150, int incK = 150, float sigma = 0.8f) { XImgprocInvoke.cveSelectiveSearchSegmentationSwitchToSelectiveSearchFast(_ptr, baseK, incK, sigma); } public void SwitchToSelectiveSearchQuality(int baseK = 150, int incK = 150, float sigma = 0.8f) { XImgprocInvoke.cveSelectiveSearchSegmentationSwitchToSelectiveSearchQuality(_ptr, baseK, incK, sigma); } public void AddImage(IInputArray img) { using InputArray inputArray = img.GetInputArray(); XImgprocInvoke.cveSelectiveSearchSegmentationAddImage(_ptr, inputArray); } public Rectangle[] Process() { using VectorOfRect vectorOfRect = new VectorOfRect(); XImgprocInvoke.cveSelectiveSearchSegmentationProcess(_ptr, vectorOfRect); return vectorOfRect.ToArray(); } protected override void DisposeObject() { if (_ptr != IntPtr.Zero) { XImgprocInvoke.cveSelectiveSearchSegmentationRelease(ref _ptr, ref _sharedPtr); } } } public class StructuredEdgeDetection : UnmanagedObject { private IntPtr _sharedPtr; public StructuredEdgeDetection(string model, RFFeatureGetter howToGetFeatures) { using CvString cvString = new CvString(model); _ptr = XImgprocInvoke.cveStructuredEdgeDetectionCreate(cvString, howToGetFeatures, ref _sharedPtr); } public void DetectEdges(IInputArray src, IOutputArray dst) { using InputArray inputArray = src.GetInputArray(); using OutputArray outputArray = dst.GetOutputArray(); XImgprocInvoke.cveStructuredEdgeDetectionDetectEdges(_ptr, inputArray, outputArray); } public void ComputeOrientation(IInputArray src, IOutputArray dst) { using InputArray inputArray = src.GetInputArray(); using OutputArray outputArray = dst.GetOutputArray(); XImgprocInvoke.cveStructuredEdgeDetectionComputeOrientation(_ptr, inputArray, outputArray); } public void EdgesNms(IInputArray edgeImage, IInputArray orientationImage, IOutputArray dst, int r = 2, int s = 0, float m = 1f, bool isParallel = true) { using InputArray inputArray = edgeImage.GetInputArray(); using InputArray inputArray2 = orientationImage.GetInputArray(); using OutputArray outputArray = dst.GetOutputArray(); XImgprocInvoke.cveStructuredEdgeDetectionEdgesNms(_ptr, inputArray, inputArray2, outputArray, r, s, m, isParallel); } protected override void DisposeObject() { if (_ptr != IntPtr.Zero) { XImgprocInvoke.cveStructuredEdgeDetectionRelease(ref _ptr, ref _sharedPtr); } } } public class RFFeatureGetter : UnmanagedObject { private IntPtr _sharedPtr; public RFFeatureGetter() { _ptr = XImgprocInvoke.cveRFFeatureGetterCreate(ref _sharedPtr); } protected override void DisposeObject() { if (_ptr != IntPtr.Zero) { XImgprocInvoke.cveRFFeatureGetterRelease(ref _ptr, ref _sharedPtr); } } } public class SuperpixelLSC : UnmanagedObject { private IntPtr _sharedPtr; public int NumberOfSuperpixels => XImgprocInvoke.cveSuperpixelLSCGetNumberOfSuperpixels(_ptr); public SuperpixelLSC(IInputArray image, int regionSize, float ratio) { using InputArray inputArray = image.GetInputArray(); _ptr = XImgprocInvoke.cveSuperpixelLSCCreate(inputArray, regionSize, ratio, ref _sharedPtr); } public void GetLabels(IOutputArray labels) { using OutputArray outputArray = labels.GetOutputArray(); XImgprocInvoke.cveSuperpixelLSCGetLabels(_ptr, outputArray); } public void GetLabelContourMask(IOutputArray image, bool thickLine = true) { using OutputArray outputArray = image.GetOutputArray(); XImgprocInvoke.cveSuperpixelLSCGetLabelContourMask(_ptr, outputArray, thickLine); } public void Iterate(int numIterations = 10) { XImgprocInvoke.cveSuperpixelLSCIterate(_ptr, numIterations); } protected override void DisposeObject() { if (_ptr != IntPtr.Zero) { XImgprocInvoke.cveSuperpixelLSCRelease(ref _ptr, ref _sharedPtr); } } } public class SupperpixelSEEDS : UnmanagedObject { private IntPtr _sharedPtr; public int NumberOfSuperpixels => XImgprocInvoke.cveSuperpixelSEEDSGetNumberOfSuperpixels(_ptr); public SupperpixelSEEDS(int imageWidth, int imageHeight, int imageChannels, int numSuperpixels, int numLevels, int prior, int histogramBins, bool doubleStep) { _ptr = XImgprocInvoke.cveSuperpixelSEEDSCreate(imageWidth, imageHeight, imageChannels, numSuperpixels, numLevels, prior, histogramBins, doubleStep, ref _sharedPtr); } public void GetLabels(IOutputArray labels) { using OutputArray outputArray = labels.GetOutputArray(); XImgprocInvoke.cveSuperpixelSEEDSGetLabels(_ptr, outputArray); } public void GetLabelContourMask(IOutputArray image, bool thickLine = false) { using OutputArray outputArray = image.GetOutputArray(); XImgprocInvoke.cveSuperpixelSEEDSGetLabelContourMask(_ptr, outputArray, thickLine); } public void Iterate(IInputArray img, int numIterations = 4) { using InputArray inputArray = img.GetInputArray(); XImgprocInvoke.cveSuperpixelSEEDSIterate(_ptr, inputArray, numIterations); } protected override void DisposeObject() { if (_ptr != IntPtr.Zero) { XImgprocInvoke.cveSuperpixelSEEDSRelease(ref _ptr, ref _sharedPtr); } } } public class SupperpixelSLIC : UnmanagedObject { public enum Algorithm { SLIC = 100, SLICO } private IntPtr _sharedPtr; public int NumberOfSuperpixels => XImgprocInvoke.cveSuperpixelSLICGetNumberOfSuperpixels(_ptr); public SupperpixelSLIC(IInputArray image, Algorithm algorithm, int regionSize, float ruler) { using InputArray inputArray = image.GetInputArray(); _ptr = XImgprocInvoke.cveSuperpixelSLICCreate(inputArray, algorithm, regionSize, ruler, ref _sharedPtr); } public void GetLabels(IOutputArray labels) { using OutputArray outputArray = labels.GetOutputArray(); XImgprocInvoke.cveSuperpixelSLICGetLabels(_ptr, outputArray); } public void GetLabelContourMask(IOutputArray image, bool thickLine = true) { using OutputArray outputArray = image.GetOutputArray(); XImgprocInvoke.cveSuperpixelSLICGetLabelContourMask(_ptr, outputArray, thickLine); } public void Iterate(int numIterations = 10) { XImgprocInvoke.cveSuperpixelSLICIterate(_ptr, numIterations); } public void EnforceLabelConnectivity(int minElementSize = 25) { XImgprocInvoke.cveSuperpixelSLICEnforceLabelConnectivity(_ptr, minElementSize); } protected override void DisposeObject() { if (_ptr != IntPtr.Zero) { XImgprocInvoke.cveSuperpixelSLICRelease(ref _ptr, ref _sharedPtr); } } } public enum ThinningTypes { ZhangSuen, GuoHall } public enum WMFWeightType { Exp, Iv1, Iv2, Cos, Jac, Off } } namespace Emgu.CV.BgSegm { public class BackgroundSubtractorCNT : UnmanagedObject, IBackgroundSubtractor, IAlgorithm { private IntPtr _sharedPtr; private IntPtr _algorithmPtr; private IntPtr _backgroundSubtractorPtr; public IntPtr AlgorithmPtr => _algorithmPtr; public IntPtr BackgroundSubtractorPtr => _backgroundSubtractorPtr; public BackgroundSubtractorCNT(int minPixelStability = 15, bool useHistory = true, int maxPixelStability = 900, bool isParallel = true) { _ptr = BgSegmInvoke.cveBackgroundSubtractorCNTCreate(minPixelStability, useHistory, maxPixelStability, isParallel, ref _backgroundSubtractorPtr, ref _algorithmPtr, ref _sharedPtr); } protected override void DisposeObject() { if (IntPtr.Zero != _ptr) { BgSegmInvoke.cveBackgroundSubtractorCNTRelease(ref _ptr, ref _sharedPtr); _backgroundSubtractorPtr = IntPtr.Zero; _algorithmPtr = IntPtr.Zero; } } } public static class BgSegmInvoke { static BgSegmInvoke() { CvInvoke.Init(); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveBackgroundSubtractorCNTCreate(int minPixelStability, [MarshalAs(UnmanagedType.U1)] bool useHistory, int maxPixelStability, [MarshalAs(UnmanagedType.U1)] bool isParallel, ref IntPtr bgSubtractor, ref IntPtr algorithm, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveBackgroundSubtractorCNTRelease(ref IntPtr bgSubtractor, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveBackgroundSubtractorGMGCreate(int initializationFrames, double decisionThreshold, ref IntPtr bgSubtractor, ref IntPtr algorithm, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveBackgroundSubtractorGMGRelease(ref IntPtr bgSubstractor, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveBackgroundSubtractorGSOCCreate(BackgroundSubtractorLSBP.CameraMotionCompensation mc, int nSamples, float replaceRate, float propagationRate, int hitsThreshold, float alpha, float beta, float blinkingSupressionDecay, float blinkingSupressionMultiplier, float noiseRemovalThresholdFacBG, float noiseRemovalThresholdFacFG, ref IntPtr bgSubtractor, ref IntPtr algorithm, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveBackgroundSubtractorGSOCRelease(ref IntPtr bgSubtractor, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveBackgroundSubtractorLSBPCreate(BackgroundSubtractorLSBP.CameraMotionCompensation mc, int nSamples, int LSBPRadius, float tlower, float tupper, float tinc, float tdec, float rscale, float rincdec, float noiseRemovalThresholdFacBG, float noiseRemovalThresholdFacFG, int LSBPthreshold, int minCount, ref IntPtr bgSubtractor, ref IntPtr algorithm, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveBackgroundSubtractorLSBPRelease(ref IntPtr bgSubstractor, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveBackgroundSubtractorMOGCreate(int history, int nmixtures, double backgroundRatio, double noiseSigma, ref IntPtr bgSubtractor, ref IntPtr algorithm, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveBackgroundSubtractorMOGRelease(ref IntPtr bgSubstractor, ref IntPtr sharedPtr); } public class BackgroundSubtractorGMG : UnmanagedObject, IBackgroundSubtractor, IAlgorithm { private IntPtr _sharedPtr; private IntPtr _algorithmPtr; private IntPtr _backgroundSubtractorPtr; public IntPtr AlgorithmPtr => _algorithmPtr; public IntPtr BackgroundSubtractorPtr => _backgroundSubtractorPtr; public BackgroundSubtractorGMG(int initializationFrames, double decisionThreshold) { _ptr = BgSegmInvoke.cveBackgroundSubtractorGMGCreate(initializationFrames, decisionThreshold, ref _backgroundSubtractorPtr, ref _algorithmPtr, ref _sharedPtr); } protected override void DisposeObject() { if (IntPtr.Zero != _ptr) { BgSegmInvoke.cveBackgroundSubtractorGMGRelease(ref _ptr, ref _sharedPtr); _backgroundSubtractorPtr = IntPtr.Zero; _algorithmPtr = IntPtr.Zero; } } } public class BackgroundSubtractorGSOC : UnmanagedObject, IBackgroundSubtractor, IAlgorithm { private IntPtr _sharedPtr; private IntPtr _algorithmPtr; private IntPtr _backgroundSubtractorPtr; public IntPtr AlgorithmPtr => _algorithmPtr; public IntPtr BackgroundSubtractorPtr => _backgroundSubtractorPtr; public BackgroundSubtractorGSOC(BackgroundSubtractorLSBP.CameraMotionCompensation mc = BackgroundSubtractorLSBP.CameraMotionCompensation.None, int nSamples = 20, float replaceRate = 0.003f, float propagationRate = 0.01f, int hitsThreshold = 32, float alpha = 0.01f, float beta = 0.0022f, float blinkingSupressionDecay = 0.1f, float blinkingSupressionMultiplier = 0.1f, float noiseRemovalThresholdFacBG = 0.0004f, float noiseRemovalThresholdFacFG = 0.0008f) { _ptr = BgSegmInvoke.cveBackgroundSubtractorGSOCCreate(mc, nSamples, replaceRate, propagationRate, hitsThreshold, alpha, beta, blinkingSupressionDecay, blinkingSupressionMultiplier, noiseRemovalThresholdFacBG, noiseRemovalThresholdFacFG, ref _backgroundSubtractorPtr, ref _algorithmPtr, ref _sharedPtr); } protected override void DisposeObject() { if (IntPtr.Zero != _ptr) { BgSegmInvoke.cveBackgroundSubtractorGSOCRelease(ref _ptr, ref _sharedPtr); _backgroundSubtractorPtr = IntPtr.Zero; _algorithmPtr = IntPtr.Zero; } } } public class BackgroundSubtractorLSBP : UnmanagedObject, IBackgroundSubtractor, IAlgorithm { public enum CameraMotionCompensation { None, LK } private IntPtr _sharedPtr; private IntPtr _algorithmPtr; private IntPtr _backgroundSubtractorPtr; public IntPtr AlgorithmPtr => _algorithmPtr; public IntPtr BackgroundSubtractorPtr => _backgroundSubtractorPtr; public BackgroundSubtractorLSBP(CameraMotionCompensation mc = CameraMotionCompensation.None, int nSamples = 20, int LSBPRadius = 16, float tlower = 2f, float tupper = 32f, float tinc = 1f, float tdec = 0.05f, float rscale = 10f, float rincdec = 0.005f, float noiseRemovalThresholdFacBG = 0.0004f, float noiseRemovalThresholdFacFG = 0.0008f, int LSBPthreshold = 8, int minCount = 2) { _ptr = BgSegmInvoke.cveBackgroundSubtractorLSBPCreate(mc, nSamples, LSBPRadius, tlower, tupper, tinc, tdec, rscale, rincdec, noiseRemovalThresholdFacBG, noiseRemovalThresholdFacFG, LSBPthreshold, minCount, ref _backgroundSubtractorPtr, ref _algorithmPtr, ref _sharedPtr); } protected override void DisposeObject() { if (IntPtr.Zero != _ptr) { BgSegmInvoke.cveBackgroundSubtractorLSBPRelease(ref _ptr, ref _sharedPtr); _backgroundSubtractorPtr = IntPtr.Zero; _algorithmPtr = IntPtr.Zero; } } } public class BackgroundSubtractorMOG : UnmanagedObject, IBackgroundSubtractor, IAlgorithm { private IntPtr _sharedPtr; private IntPtr _algorithmPtr; private IntPtr _backgroundSubtractorPtr; public IntPtr AlgorithmPtr => _algorithmPtr; public IntPtr BackgroundSubtractorPtr => _backgroundSubtractorPtr; public BackgroundSubtractorMOG(int history = 200, int nMixtures = 5, double backgroundRatio = 0.7, double noiseSigma = 0.0) { _ptr = BgSegmInvoke.cveBackgroundSubtractorMOGCreate(history, nMixtures, backgroundRatio, noiseSigma, ref _backgroundSubtractorPtr, ref _algorithmPtr, ref _sharedPtr); } protected override void DisposeObject() { if (IntPtr.Zero != _ptr) { BgSegmInvoke.cveBackgroundSubtractorMOGRelease(ref _ptr, ref _sharedPtr); _backgroundSubtractorPtr = IntPtr.Zero; _algorithmPtr = IntPtr.Zero; } } } } namespace Emgu.CV.Freetype { public class Freetype2 : SharedPtrObject, IAlgorithm { private IntPtr _algorithmPtr; public IntPtr AlgorithmPtr => _algorithmPtr; public Freetype2() { _ptr = FreetypeInvoke.cveFreeType2Create(ref _algorithmPtr, ref _sharedPtr); } public void LoadFontData(string fontFileName, int id) { using CvString cvString = new CvString(fontFileName); FreetypeInvoke.cveFreeType2LoadFontData(_ptr, cvString, id); } public void SetSplitNumber(int num) { FreetypeInvoke.cveFreeType2SetSplitNumber(_ptr, num); } public void PutText(IInputOutputArray img, string text, Point org, int fontHeight, MCvScalar color, int thickness, LineType lineType, bool bottomLeftOrigin) { using InputOutputArray inputOutputArray = img.GetInputOutputArray(); using CvString cvString = new CvString(text); FreetypeInvoke.cveFreeType2PutText(_ptr, inputOutputArray, cvString, ref org, fontHeight, ref color, thickness, lineType, bottomLeftOrigin); } public Size GetTextSize(string text, int fontHeight, int thickness, ref int baseLine) { Size size = default(Size); using CvString cvString = new CvString(text); FreetypeInvoke.cveFreeType2GetTextSize(_ptr, cvString, fontHeight, thickness, ref baseLine, ref size); return size; } protected override void DisposeObject() { if (_sharedPtr != IntPtr.Zero) { FreetypeInvoke.cveFreeType2Release(ref _sharedPtr); _algorithmPtr = IntPtr.Zero; _ptr = IntPtr.Zero; } } } public static class FreetypeInvoke { static FreetypeInvoke() { CvInvoke.Init(); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveFreeType2Create(ref IntPtr algorithmPtr, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveFreeType2Release(ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveFreeType2LoadFontData(IntPtr freetype, IntPtr fontFileName, int id); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveFreeType2SetSplitNumber(IntPtr freetype, int num); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveFreeType2PutText(IntPtr freetype, IntPtr img, IntPtr text, ref Point org, int fontHeight, ref MCvScalar color, int thickness, LineType lineType, [MarshalAs(UnmanagedType.U1)] bool bottomLeftOrigin); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveFreeType2GetTextSize(IntPtr freetype, IntPtr text, int fontHeight, int thickness, ref int baseLine, ref Size size); } } namespace Emgu.CV.Text { public abstract class ERFilter : SharedPtrObject { public enum GroupingMethod { OrientationHoriz, OrientationAny } protected override void DisposeObject() { if (_sharedPtr != IntPtr.Zero) { TextInvoke.cveERFilterRelease(ref _sharedPtr); _ptr = IntPtr.Zero; } } public void Run(IInputArray image, VectorOfERStat regions) { using InputArray inputArray = image.GetInputArray(); TextInvoke.cveERFilterRun(_ptr, inputArray, regions); } public static Rectangle[] ERGrouping(IInputArray image, IInputArrayOfArrays channels, VectorOfERStat[] erstats, GroupingMethod groupMethods = GroupingMethod.OrientationHoriz, string groupingTrainedFileName = null, float minProbability = 0.5f) { IntPtr[] array = new IntPtr[erstats.Length]; for (int i = 0; i < array.Length; i++) { array[i] = erstats[i].Ptr; } using VectorOfVectorOfPoint vectorOfVectorOfPoint = new VectorOfVectorOfPoint(); using VectorOfRect vectorOfRect = new VectorOfRect(); using InputArray inputArray = image.GetInputArray(); using InputArray inputArray2 = channels.GetInputArray(); using CvString cvString = ((groupingTrainedFileName == null) ? new CvString() : new CvString(groupingTrainedFileName)); GCHandle gCHandle = GCHandle.Alloc(array, GCHandleType.Pinned); TextInvoke.cveERGrouping(inputArray, inputArray2, gCHandle.AddrOfPinnedObject(), array.Length, vectorOfVectorOfPoint, vectorOfRect, groupMethods, cvString, minProbability); gCHandle.Free(); return vectorOfRect.ToArray(); } } public class ERFilterNM1 : ERFilter { public ERFilterNM1(string classifierFileName, int thresholdDelta = 1, float minArea = 0.00025f, float maxArea = 0.13f, float minProbability = 0.4f, bool nonMaxSuppression = true, float minProbabilityDiff = 0.1f) { using CvString cvString = new CvString(classifierFileName); _ptr = TextInvoke.cveERFilterNM1Create(cvString, thresholdDelta, minArea, maxArea, minProbability, nonMaxSuppression, minProbabilityDiff, ref _sharedPtr); } } public class ERFilterNM2 : ERFilter { public ERFilterNM2(string classifierFileName, float minProbability = 0.3f) { using CvString cvString = new CvString(classifierFileName); _ptr = TextInvoke.cveERFilterNM2Create(cvString, minProbability, ref _sharedPtr); } } public enum ERFilterNMMode { RGBLGrad, IHSGrad } public static class TextInvoke { static TextInvoke() { CvInvoke.Init(); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveERFilterRelease(ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveERFilterRun(IntPtr filter, IntPtr image, IntPtr regions); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveERGrouping(IntPtr image, IntPtr channels, IntPtr regions, int count, IntPtr groups, IntPtr groupRects, ERFilter.GroupingMethod method, IntPtr fileName, float minProbability); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveERFilterNM1Create(IntPtr classifier, int thresholdDelta, float minArea, float maxArea, float minProbability, [MarshalAs(UnmanagedType.U1)] bool nonMaxSuppression, float minProbabilityDiff, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveERFilterNM2Create(IntPtr classifier, float minProbability, ref IntPtr sharedPtr); public static void MSERsToERStats(IInputArray image, VectorOfVectorOfPoint contours, VectorOfVectorOfERStat regions) { using InputArray inputArray = image.GetInputArray(); cveMSERsToERStats(inputArray, contours, regions); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveMSERsToERStats(IntPtr image, IntPtr contours, IntPtr regions); public static void ComputeNMChannels(IInputArray src, IOutputArrayOfArrays channels, ERFilterNMMode mode = ERFilterNMMode.RGBLGrad) { using InputArray inputArray = src.GetInputArray(); using OutputArray outputArray = channels.GetOutputArray(); cveComputeNMChannels(inputArray, outputArray, mode); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveComputeNMChannels(IntPtr src, IntPtr channels, ERFilterNMMode mode); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveTextDetectorCNNCreate(IntPtr modelArchFilename, IntPtr modelWeightsFilename, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveTextDetectorCNNCreate2(IntPtr modelArchFilename, IntPtr modelWeightsFilename, IntPtr detectionSizes, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveTextDetectorCNNDetect(IntPtr detector, IntPtr inputImage, IntPtr bbox, IntPtr confidence); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveTextDetectorCNNRelease(ref IntPtr sharedPtr); } [Serializable] public struct MCvERStat { public int Pixel; public int Level; public int Area; public int Perimeter; public int Euler; public Rectangle Rect; public double RawMoments0; public double RawMoments1; public double CentralMoments0; public double CentralMoments1; public double CentralMoments2; public IntPtr CrossingsOwner; public IntPtr CrossingsStored; public float MedCrossings; public float HoleAreaRatio; public float ConvexHullRatio; public float NumInflexionPoints; private IntPtr _pixels; public double probability; public IntPtr ParentPtr; public IntPtr ChildPtr; public IntPtr NextPtr; public IntPtr PrevPtr; private byte _localMaxima; public IntPtr MaxProbabilityAncestor; public IntPtr MinProbabilityAncestor; public VectorOfInt Pixels { get { if (IntPtr.Zero == _pixels) { return null; } return new VectorOfInt(_pixels, needDispose: false); } } public bool LocalMaxima { get { return _localMaxima != 0; } set { _localMaxima = (byte)(value ? 1 : 0); } } public Point GetCenter(int imageWidth) { return new Point(Pixel % imageWidth, Pixel / imageWidth); } } public class TextDetectorCNN : SharedPtrObject { public class TextRegion { public Rectangle BBox; public float Confident; } public TextDetectorCNN(string modelArchFilename, string modelWeightsFilename, Size[] detectionSizes = null) { using CvString cvString = new CvString(modelArchFilename); using CvString cvString2 = new CvString(modelWeightsFilename); if (detectionSizes == null) { _ptr = TextInvoke.cveTextDetectorCNNCreate(cvString, cvString2, ref _sharedPtr); return; } using VectorOfSize vectorOfSize = new VectorOfSize(detectionSizes); _ptr = TextInvoke.cveTextDetectorCNNCreate2(cvString, cvString2, vectorOfSize, ref _sharedPtr); } public TextRegion[] Detect(IInputArray inputImage) { using InputArray inputArray = inputImage.GetInputArray(); using VectorOfRect vectorOfRect = new VectorOfRect(); using VectorOfFloat vectorOfFloat = new VectorOfFloat(); TextInvoke.cveTextDetectorCNNDetect(_ptr, inputArray, vectorOfRect, vectorOfFloat); Rectangle[] array = vectorOfRect.ToArray(); float[] array2 = vectorOfFloat.ToArray(); TextRegion[] array3 = new TextRegion[array.Length]; for (int i = 0; i < array3.Length; i++) { TextRegion textRegion = new TextRegion(); textRegion.BBox = array[i]; textRegion.Confident = array2[i]; array3[i] = textRegion; } return array3; } protected override void DisposeObject() { if (_sharedPtr != IntPtr.Zero) { TextInvoke.cveTextDetectorCNNRelease(ref _sharedPtr); _ptr = IntPtr.Zero; } } } [Serializable] [DebuggerTypeProxy(typeof(DebuggerProxy))] public class VectorOfERStat : UnmanagedVector, ISerializable, IInputOutputArray, IInputArray, IDisposable, IOutputArray, IInputArrayOfArrays, IOutputArrayOfArrays { internal class DebuggerProxy { private VectorOfERStat _v; public MCvERStat[] Values => _v.ToArray(); public DebuggerProxy(VectorOfERStat v) { _v = v; } } private readonly bool _needDispose; public override int Size => VectorOfERStatGetSize(_ptr); public override IntPtr StartAddress => VectorOfERStatGetStartAddress(_ptr); public override long Length => VectorOfERStatGetMemorySize(_ptr); public MCvERStat this[int index] { get { MCvERStat element = default(MCvERStat); VectorOfERStatGetItem(_ptr, index, ref element); return element; } } public static int SizeOfItemInBytes => VectorOfERStatSizeOfItemInBytes(); static VectorOfERStat() { CvInvoke.Init(); } public VectorOfERStat(SerializationInfo info, StreamingContext context) : this() { Push((MCvERStat[])info.GetValue("ERStatArray", typeof(MCvERStat[]))); } public void GetObjectData(SerializationInfo info, StreamingContext context) { info.AddValue("ERStatArray", ToArray()); } public VectorOfERStat() : this(VectorOfERStatCreate(), needDispose: true) { } internal VectorOfERStat(IntPtr ptr, bool needDispose) { _ptr = ptr; _needDispose = needDispose; } public VectorOfERStat(int size) : this(VectorOfERStatCreateSize(size), needDispose: true) { } public VectorOfERStat(MCvERStat[] values) : this() { Push(values); } public void Push(MCvERStat[] value) { if (value.Length != 0) { GCHandle gCHandle = GCHandle.Alloc(value, GCHandleType.Pinned); VectorOfERStatPushMulti(_ptr, gCHandle.AddrOfPinnedObject(), value.Length); gCHandle.Free(); } } public void Push(VectorOfERStat other) { VectorOfERStatPushVector(_ptr, other); } public MCvERStat[] ToArray() { MCvERStat[] array = new MCvERStat[Size]; if (array.Length != 0) { GCHandle gCHandle = GCHandle.Alloc(array, GCHandleType.Pinned); VectorOfERStatCopyData(_ptr, gCHandle.AddrOfPinnedObject()); gCHandle.Free(); } return array; } public void Clear() { VectorOfERStatClear(_ptr); } protected override void DisposeObject() { if (_needDispose && _ptr != IntPtr.Zero) { VectorOfERStatRelease(ref _ptr); } } public InputArray GetInputArray() { return new InputArray(cveInputArrayFromVectorOfERStat(_ptr), this); } public OutputArray GetOutputArray() { return new OutputArray(cveOutputArrayFromVectorOfERStat(_ptr), this); } public InputOutputArray GetInputOutputArray() { return new InputOutputArray(cveInputOutputArrayFromVectorOfERStat(_ptr), this); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr VectorOfERStatCreate(); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr VectorOfERStatCreateSize(int size); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfERStatRelease(ref IntPtr v); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int VectorOfERStatGetSize(IntPtr v); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfERStatCopyData(IntPtr v, IntPtr data); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr VectorOfERStatGetStartAddress(IntPtr v); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern long VectorOfERStatGetMemorySize(IntPtr v); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfERStatPushMulti(IntPtr v, IntPtr values, int count); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfERStatPushVector(IntPtr ptr, IntPtr otherPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfERStatClear(IntPtr v); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfERStatGetItem(IntPtr vec, int index, ref MCvERStat element); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int VectorOfERStatSizeOfItemInBytes(); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveInputArrayFromVectorOfERStat(IntPtr vec); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveOutputArrayFromVectorOfERStat(IntPtr vec); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveInputOutputArrayFromVectorOfERStat(IntPtr vec); void IDisposable.Dispose() { Dispose(); } } [Serializable] [DebuggerTypeProxy(typeof(DebuggerProxy))] public class VectorOfVectorOfERStat : UnmanagedVector, IInputOutputArray, IInputArray, IDisposable, IOutputArray, IInputArrayOfArrays, IOutputArrayOfArrays { internal class DebuggerProxy { private VectorOfVectorOfERStat _v; public MCvERStat[][] Values => _v.ToArrayOfArray(); public DebuggerProxy(VectorOfVectorOfERStat v) { _v = v; } } private readonly bool _needDispose; public override int Size => VectorOfVectorOfERStatGetSize(_ptr); public override IntPtr StartAddress => VectorOfVectorOfERStatGetStartAddress(_ptr); public override long Length => VectorOfVectorOfERStatGetMemorySize(_ptr); public VectorOfERStat this[int index] { get { IntPtr element = IntPtr.Zero; VectorOfVectorOfERStatGetItemPtr(_ptr, index, ref element); return new VectorOfERStat(element, needDispose: false); } } public static int SizeOfItemInBytes => VectorOfVectorOfERStatSizeOfItemInBytes(); static VectorOfVectorOfERStat() { CvInvoke.Init(); } public VectorOfVectorOfERStat() : this(VectorOfVectorOfERStatCreate(), needDispose: true) { } internal VectorOfVectorOfERStat(IntPtr ptr, bool needDispose) { _ptr = ptr; _needDispose = needDispose; } public VectorOfVectorOfERStat(int size) : this(VectorOfVectorOfERStatCreateSize(size), needDispose: true) { } public VectorOfVectorOfERStat(params VectorOfERStat[] values) : this() { Push(values); } public void Clear() { VectorOfVectorOfERStatClear(_ptr); } public void Push(VectorOfERStat value) { VectorOfVectorOfERStatPush(_ptr, value.Ptr); } public void Push(VectorOfERStat[] values) { foreach (VectorOfERStat value in values) { Push(value); } } public void Push(VectorOfVectorOfERStat other) { VectorOfVectorOfERStatPushVector(_ptr, other); } protected override void DisposeObject() { if (_needDispose && _ptr != IntPtr.Zero) { VectorOfVectorOfERStatRelease(ref _ptr); } } public InputArray GetInputArray() { return new InputArray(cveInputArrayFromVectorOfVectorOfERStat(_ptr), this); } public OutputArray GetOutputArray() { return new OutputArray(cveOutputArrayFromVectorOfVectorOfERStat(_ptr), this); } public InputOutputArray GetInputOutputArray() { return new InputOutputArray(cveInputOutputArrayFromVectorOfVectorOfERStat(_ptr), this); } public VectorOfVectorOfERStat(MCvERStat[][] values) : this() { using VectorOfERStat vectorOfERStat = new VectorOfERStat(); for (int i = 0; i < values.Length; i++) { vectorOfERStat.Push(values[i]); Push(vectorOfERStat); vectorOfERStat.Clear(); } } public MCvERStat[][] ToArrayOfArray() { int size = Size; MCvERStat[][] array = new MCvERStat[size][]; for (int i = 0; i < size; i++) { using VectorOfERStat vectorOfERStat = this[i]; array[i] = vectorOfERStat.ToArray(); } return array; } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr VectorOfVectorOfERStatCreate(); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr VectorOfVectorOfERStatCreateSize(int size); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfVectorOfERStatRelease(ref IntPtr v); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int VectorOfVectorOfERStatGetSize(IntPtr v); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr VectorOfVectorOfERStatGetStartAddress(IntPtr v); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern long VectorOfVectorOfERStatGetMemorySize(IntPtr v); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfVectorOfERStatPush(IntPtr v, IntPtr value); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfVectorOfERStatPushVector(IntPtr ptr, IntPtr otherPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfVectorOfERStatClear(IntPtr v); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfVectorOfERStatGetItemPtr(IntPtr vec, int index, ref IntPtr element); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int VectorOfVectorOfERStatSizeOfItemInBytes(); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveInputArrayFromVectorOfVectorOfERStat(IntPtr vec); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveOutputArrayFromVectorOfVectorOfERStat(IntPtr vec); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveInputOutputArrayFromVectorOfVectorOfERStat(IntPtr vec); void IDisposable.Dispose() { Dispose(); } } } namespace Emgu.CV.Face { public abstract class BasicFaceRecognizer : FaceRecognizer { protected IntPtr _basicFaceRecognizerPtr; protected override void DisposeObject() { _basicFaceRecognizerPtr = IntPtr.Zero; base.DisposeObject(); } } public class BIF : SharedPtrObject { public BIF(int numBands, int numRotations) { _ptr = FaceInvoke.cveBIFCreate(numBands, numRotations, ref _sharedPtr); } public void Compute(IInputArray image, IOutputArray features) { using InputArray inputArray = image.GetInputArray(); using OutputArray outputArray = features.GetOutputArray(); FaceInvoke.cveBIFCompute(_ptr, inputArray, outputArray); } protected override void DisposeObject() { if (_sharedPtr != IntPtr.Zero) { FaceInvoke.cveBIFRelease(ref _sharedPtr); _ptr = IntPtr.Zero; } } } public static class FaceInvoke { [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveBIFCreate(int numBands, int numRotations, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveBIFCompute(IntPtr bif, IntPtr image, IntPtr features); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveBIFRelease(ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveEigenFaceRecognizerCreate(int numComponents, double threshold, ref IntPtr faceRecognizerPtr, ref IntPtr basicFaceRecognizerPtr, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveEigenFaceRecognizerRelease(ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveFacemarkAAMCreate(IntPtr parameters, ref IntPtr facemark, ref IntPtr algorithm, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveFacemarkAAMRelease(ref IntPtr facemark, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveFacemarkAAMParamsCreate(); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveFacemarkAAMParamsRelease(ref IntPtr parameters); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveFacemarkAAMParamsGetModelFile(IntPtr obj, IntPtr str); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveFacemarkAAMParamsSetModelFile(IntPtr obj, IntPtr str); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int cveFacemarkAAMParamsGetM(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveFacemarkAAMParamsSetM(IntPtr obj, int val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int cveFacemarkAAMParamsGetN(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveFacemarkAAMParamsSetN(IntPtr obj, int val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int cveFacemarkAAMParamsGetNIter(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveFacemarkAAMParamsSetNIter(IntPtr obj, int val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.U1)] internal static extern bool cveFacemarkAAMParamsGetVerbose(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveFacemarkAAMParamsSetVerbose(IntPtr obj, [MarshalAs(UnmanagedType.U1)] bool val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.U1)] internal static extern bool cveFacemarkAAMParamsGetSaveModel(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveFacemarkAAMParamsSetSaveModel(IntPtr obj, [MarshalAs(UnmanagedType.U1)] bool val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int cveFacemarkAAMParamsGetMaxM(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveFacemarkAAMParamsSetMaxM(IntPtr obj, int val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int cveFacemarkAAMParamsGetMaxN(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveFacemarkAAMParamsSetMaxN(IntPtr obj, int val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveFacemarkLBFCreate(IntPtr parameters, ref IntPtr facemark, ref IntPtr algorithm, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveFacemarkLBFRelease(ref IntPtr facemark, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveFacemarkLBFParamsCreate(); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveFacemarkLBFParamsRelease(ref IntPtr parameters); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern double cveFacemarkLBFParamsGetShapeOffset(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveFacemarkLBFParamsSetShapeOffset(IntPtr obj, double val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.U1)] internal static extern bool cveFacemarkLBFParamsGetVerbose(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveFacemarkLBFParamsSetVerbose(IntPtr obj, [MarshalAs(UnmanagedType.U1)] bool val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int cveFacemarkLBFParamsGetNLandmarks(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveFacemarkLBFParamsSetNLandmarks(IntPtr obj, int val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int cveFacemarkLBFParamsGetInitShapeN(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveFacemarkLBFParamsSetInitShapeN(IntPtr obj, int val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int cveFacemarkLBFParamsGetStagesN(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveFacemarkLBFParamsSetStagesN(IntPtr obj, int val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int cveFacemarkLBFParamsGetTreeN(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveFacemarkLBFParamsSetTreeN(IntPtr obj, int val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int cveFacemarkLBFParamsGetTreeDepth(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveFacemarkLBFParamsSetTreeDepth(IntPtr obj, int val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern double cveFacemarkLBFParamsGetBaggingOverlap(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveFacemarkLBFParamsSetBaggingOverlap(IntPtr obj, double val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.U1)] internal static extern bool cveFacemarkLBFParamsGetSaveModel(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveFacemarkLBFParamsSetSaveModel(IntPtr obj, [MarshalAs(UnmanagedType.U1)] bool val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveFacemarkLBFParamsGetCascadeFace(IntPtr obj, IntPtr str); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveFacemarkLBFParamsSetCascadeFace(IntPtr obj, IntPtr str); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveFacemarkLBFParamsGetModelFile(IntPtr obj, IntPtr str); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveFacemarkLBFParamsSetModelFile(IntPtr obj, IntPtr str); static FaceInvoke() { CvInvoke.Init(); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveFaceRecognizerTrain(IntPtr recognizer, IntPtr images, IntPtr labels); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveFaceRecognizerPredict(IntPtr recognizer, IntPtr image, ref int label, ref double distance); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveFaceRecognizerWrite(IntPtr recognizer, IntPtr fileName); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveFaceRecognizerRead(IntPtr recognizer, IntPtr fileName); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveFaceRecognizerUpdate(IntPtr recognizer, IntPtr images, IntPtr labels); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveFaceRecognizerSetLabelInfo(IntPtr recognizer, int label, IntPtr strInfo); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveFaceRecognizerGetLabelInfo(IntPtr recognizer, int label, IntPtr strInfo); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveFisherFaceRecognizerCreate(int numComponents, double threshold, ref IntPtr faceRecognizerPtr, ref IntPtr basicFaceRecognizerPtr, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveFisherFaceRecognizerRelease(ref IntPtr sharedPtr); public static void LoadModel(this IFacemark facemark, string model) { using CvString cvString = new CvString(model); cveFacemarkLoadModel(facemark.FacemarkPtr, cvString); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveFacemarkLoadModel(IntPtr facemark, IntPtr model); public static bool Fit(this IFacemark facemark, IInputArray image, IInputArray faces, IInputOutputArray landmarks) { using InputArray inputArray = image.GetInputArray(); using InputArray inputArray2 = faces.GetInputArray(); using InputOutputArray inputOutputArray = landmarks.GetInputOutputArray(); return cveFacemarkFit(facemark.FacemarkPtr, inputArray, inputArray2, inputOutputArray); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.U1)] internal static extern bool cveFacemarkFit(IntPtr facemark, IntPtr image, IntPtr faces, IntPtr landmarks); public static void DrawFacemarks(IInputOutputArray image, IInputArray points, MCvScalar color) { using InputOutputArray inputOutputArray = image.GetInputOutputArray(); using InputArray inputArray = points.GetInputArray(); cveDrawFacemarks(inputOutputArray, inputArray, ref color); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveDrawFacemarks(IntPtr image, IntPtr points, ref MCvScalar color); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveLBPHFaceRecognizerCreate(int radius, int neighbors, int gridX, int gridY, double threshold, ref IntPtr faceRecognizerPtr, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveLBPHFaceRecognizerRelease(ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveLBPHFaceRecognizerGetHistograms(IntPtr recognizer, IntPtr histograms); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveMaceCreate(int imgSize, ref IntPtr sharedPtr, ref IntPtr algorithmPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveMaceCreate2(IntPtr fileName, IntPtr objName, ref IntPtr sharedPtr, ref IntPtr algorithmPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveMaceSalt(IntPtr mace, IntPtr passphrase); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveMaceTrain(IntPtr mace, IntPtr images); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.U1)] internal static extern bool cveMaceSame(IntPtr mace, IntPtr query); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveMaceRelease(ref IntPtr sharedPtr); } public class EigenFaceRecognizer : BasicFaceRecognizer { public EigenFaceRecognizer(int numComponents = 0, double threshold = double.MaxValue) { _ptr = FaceInvoke.cveEigenFaceRecognizerCreate(numComponents, threshold, ref _faceRecognizerPtr, ref _basicFaceRecognizerPtr, ref _sharedPtr); } protected override void DisposeObject() { if (_sharedPtr != IntPtr.Zero) { FaceInvoke.cveEigenFaceRecognizerRelease(ref _sharedPtr); _ptr = IntPtr.Zero; } base.DisposeObject(); } } public class FacemarkAAMParams : UnmanagedObject { public string ModelFile { get { using CvString cvString = new CvString(); FaceInvoke.cveFacemarkAAMParamsGetModelFile(_ptr, cvString); return cvString.ToString(); } set { using CvString cvString = new CvString(value); FaceInvoke.cveFacemarkAAMParamsSetModelFile(_ptr, cvString); } } public int M { get { return FaceInvoke.cveFacemarkAAMParamsGetM(_ptr); } set { FaceInvoke.cveFacemarkAAMParamsSetM(_ptr, value); } } public int N { get { return FaceInvoke.cveFacemarkAAMParamsGetN(_ptr); } set { FaceInvoke.cveFacemarkAAMParamsSetN(_ptr, value); } } public int NIter { get { return FaceInvoke.cveFacemarkAAMParamsGetNIter(_ptr); } set { FaceInvoke.cveFacemarkAAMParamsSetNIter(_ptr, value); } } public bool Verbose { get { return FaceInvoke.cveFacemarkAAMParamsGetVerbose(_ptr); } set { FaceInvoke.cveFacemarkAAMParamsSetVerbose(_ptr, value); } } public bool SaveModel { get { return FaceInvoke.cveFacemarkAAMParamsGetSaveModel(_ptr); } set { FaceInvoke.cveFacemarkAAMParamsSetSaveModel(_ptr, value); } } public int MaxM { get { return FaceInvoke.cveFacemarkAAMParamsGetMaxM(_ptr); } set { FaceInvoke.cveFacemarkAAMParamsSetMaxM(_ptr, value); } } public int MaxN { get { return FaceInvoke.cveFacemarkAAMParamsGetMaxN(_ptr); } set { FaceInvoke.cveFacemarkAAMParamsSetMaxN(_ptr, value); } } public FacemarkAAMParams() { _ptr = FaceInvoke.cveFacemarkAAMParamsCreate(); } protected override void DisposeObject() { if (_ptr != IntPtr.Zero) { FaceInvoke.cveFacemarkAAMParamsRelease(ref _ptr); } } } public class FacemarkAAM : UnmanagedObject, IFacemark, IAlgorithm { private IntPtr _sharedPtr; private IntPtr _facemarkPtr; private IntPtr _algorithmPtr; public IntPtr FacemarkPtr => _facemarkPtr; public IntPtr AlgorithmPtr => _algorithmPtr; public FacemarkAAM(FacemarkAAMParams parameters) { _ptr = FaceInvoke.cveFacemarkAAMCreate(parameters, ref _facemarkPtr, ref _algorithmPtr, ref _sharedPtr); } protected override void DisposeObject() { if (_ptr != IntPtr.Zero) { FaceInvoke.cveFacemarkAAMRelease(ref _ptr, ref _sharedPtr); } } } public class FacemarkLBFParams : UnmanagedObject { public double ShapeOffset { get { return FaceInvoke.cveFacemarkLBFParamsGetShapeOffset(_ptr); } set { FaceInvoke.cveFacemarkLBFParamsSetShapeOffset(_ptr, value); } } public bool Verbose { get { return FaceInvoke.cveFacemarkLBFParamsGetVerbose(_ptr); } set { FaceInvoke.cveFacemarkLBFParamsSetVerbose(_ptr, value); } } public int NLandmarks { get { return FaceInvoke.cveFacemarkLBFParamsGetNLandmarks(_ptr); } set { FaceInvoke.cveFacemarkLBFParamsSetNLandmarks(_ptr, value); } } public int InitShapeN { get { return FaceInvoke.cveFacemarkLBFParamsGetInitShapeN(_ptr); } set { FaceInvoke.cveFacemarkLBFParamsSetInitShapeN(_ptr, value); } } public int StagesN { get { return FaceInvoke.cveFacemarkLBFParamsGetStagesN(_ptr); } set { FaceInvoke.cveFacemarkLBFParamsSetStagesN(_ptr, value); } } public int TreeN { get { return FaceInvoke.cveFacemarkLBFParamsGetTreeN(_ptr); } set { FaceInvoke.cveFacemarkLBFParamsSetTreeN(_ptr, value); } } public int TreeDepth { get { return FaceInvoke.cveFacemarkLBFParamsGetTreeDepth(_ptr); } set { FaceInvoke.cveFacemarkLBFParamsSetTreeDepth(_ptr, value); } } public double BaggingOverlap { get { return FaceInvoke.cveFacemarkLBFParamsGetBaggingOverlap(_ptr); } set { FaceInvoke.cveFacemarkLBFParamsSetBaggingOverlap(_ptr, value); } } public bool SaveModel { get { return FaceInvoke.cveFacemarkLBFParamsGetSaveModel(_ptr); } set { FaceInvoke.cveFacemarkLBFParamsSetSaveModel(_ptr, value); } } public string CascadeFace { get { using CvString cvString = new CvString(); FaceInvoke.cveFacemarkLBFParamsGetCascadeFace(_ptr, cvString); return cvString.ToString(); } set { using CvString cvString = new CvString(value); FaceInvoke.cveFacemarkLBFParamsSetCascadeFace(_ptr, cvString); } } public string ModelFile { get { using CvString cvString = new CvString(); FaceInvoke.cveFacemarkLBFParamsGetModelFile(_ptr, cvString); return cvString.ToString(); } set { using CvString cvString = new CvString(value); FaceInvoke.cveFacemarkLBFParamsSetModelFile(_ptr, cvString); } } public FacemarkLBFParams() { _ptr = FaceInvoke.cveFacemarkLBFParamsCreate(); } protected override void DisposeObject() { if (_ptr != IntPtr.Zero) { FaceInvoke.cveFacemarkLBFParamsRelease(ref _ptr); } } } public class FacemarkLBF : UnmanagedObject, IFacemark, IAlgorithm { private IntPtr _sharedPtr; private IntPtr _facemarkPtr; private IntPtr _algorithmPtr; public IntPtr FacemarkPtr => _facemarkPtr; public IntPtr AlgorithmPtr => _algorithmPtr; public FacemarkLBF(FacemarkLBFParams parameters) { _ptr = FaceInvoke.cveFacemarkLBFCreate(parameters, ref _facemarkPtr, ref _algorithmPtr, ref _sharedPtr); } protected override void DisposeObject() { if (_ptr != IntPtr.Zero) { FaceInvoke.cveFacemarkLBFRelease(ref _ptr, ref _sharedPtr); } } } public abstract class FaceRecognizer : SharedPtrObject { public struct PredictionResult { public int Label; public double Distance; } protected IntPtr _faceRecognizerPtr; public void Train(IInputArrayOfArrays images, IInputArray labels) { using InputArray inputArray = images.GetInputArray(); using InputArray inputArray2 = labels.GetInputArray(); FaceInvoke.cveFaceRecognizerTrain(_faceRecognizerPtr, inputArray, inputArray2); } public void Train(Mat[] images, int[] labels) { using VectorOfMat vectorOfMat = new VectorOfMat(); using VectorOfInt labels2 = new VectorOfInt(labels); vectorOfMat.Push(images); Train(vectorOfMat, labels2); } public PredictionResult Predict(IInputArray image) { int label = -1; double distance = -1.0; using (InputArray inputArray = image.GetInputArray()) { FaceInvoke.cveFaceRecognizerPredict(_faceRecognizerPtr, inputArray, ref label, ref distance); } PredictionResult result = default(PredictionResult); result.Label = label; result.Distance = distance; return result; } public void Write(string fileName) { using CvString cvString = new CvString(fileName); FaceInvoke.cveFaceRecognizerWrite(_faceRecognizerPtr, cvString); } public void Read(string fileName) { using CvString cvString = new CvString(fileName); FaceInvoke.cveFaceRecognizerRead(_faceRecognizerPtr, cvString); } public void SetLabelInfo(int label, string strInfo) { using CvString cvString = new CvString(strInfo); FaceInvoke.cveFaceRecognizerSetLabelInfo(_faceRecognizerPtr, label, cvString); } public string GetLabelInfo(int label) { using CvString cvString = new CvString(); FaceInvoke.cveFaceRecognizerGetLabelInfo(_faceRecognizerPtr, label, cvString); return cvString.ToString(); } protected override void DisposeObject() { _faceRecognizerPtr = IntPtr.Zero; } } public class FisherFaceRecognizer : BasicFaceRecognizer { public FisherFaceRecognizer(int numComponents = 0, double threshold = double.MaxValue) { _ptr = FaceInvoke.cveFisherFaceRecognizerCreate(numComponents, threshold, ref _faceRecognizerPtr, ref _basicFaceRecognizerPtr, ref _sharedPtr); } protected override void DisposeObject() { if (_sharedPtr != IntPtr.Zero) { FaceInvoke.cveFisherFaceRecognizerRelease(ref _sharedPtr); _ptr = IntPtr.Zero; } base.DisposeObject(); } } public interface IFacemark : IAlgorithm { IntPtr FacemarkPtr { get; } } public class LBPHFaceRecognizer : FaceRecognizer { public VectorOfMat Histograms { get { VectorOfMat vectorOfMat = new VectorOfMat(); FaceInvoke.cveLBPHFaceRecognizerGetHistograms(_ptr, vectorOfMat); return vectorOfMat; } } public LBPHFaceRecognizer(int radius = 1, int neighbors = 8, int gridX = 8, int gridY = 8, double threshold = double.MaxValue) { _ptr = FaceInvoke.cveLBPHFaceRecognizerCreate(radius, neighbors, gridX, gridY, threshold, ref _faceRecognizerPtr, ref _sharedPtr); } public void Update(IInputArray images, IInputArray labels) { using InputArray inputArray = images.GetInputArray(); using InputArray inputArray2 = labels.GetInputArray(); FaceInvoke.cveFaceRecognizerUpdate(_faceRecognizerPtr, inputArray, inputArray2); } public void Update(Mat[] images, int[] labels) { using VectorOfMat vectorOfMat = new VectorOfMat(); using VectorOfInt labels2 = new VectorOfInt(labels); vectorOfMat.Push(images); Update(vectorOfMat, labels2); } protected override void DisposeObject() { if (_sharedPtr != IntPtr.Zero) { FaceInvoke.cveLBPHFaceRecognizerRelease(ref _sharedPtr); _ptr = IntPtr.Zero; } base.DisposeObject(); } } public class MACE : SharedPtrObject, IAlgorithm { private IntPtr _algorithmPtr; public IntPtr AlgorithmPtr => _algorithmPtr; public MACE(int imgSize) { _ptr = FaceInvoke.cveMaceCreate(imgSize, ref _sharedPtr, ref _algorithmPtr); } public MACE(string fileName, string objName = "") { using CvString cvString = new CvString(fileName); using CvString cvString2 = new CvString(objName); _ptr = FaceInvoke.cveMaceCreate2(cvString, cvString2, ref _sharedPtr, ref _algorithmPtr); } public void Salt(string passphrase) { using CvString cvString = new CvString(passphrase); FaceInvoke.cveMaceSalt(_ptr, cvString); } public void Train(IInputArrayOfArrays images) { using InputArray inputArray = images.GetInputArray(); FaceInvoke.cveMaceTrain(_ptr, inputArray); } public bool Same(IInputArray query) { using InputArray inputArray = query.GetInputArray(); return FaceInvoke.cveMaceSame(_ptr, inputArray); } protected override void DisposeObject() { if (_sharedPtr != IntPtr.Zero) { FaceInvoke.cveMaceRelease(ref _sharedPtr); _ptr = IntPtr.Zero; _algorithmPtr = IntPtr.Zero; } } } } namespace Emgu.CV.XFeatures2D { public class BEBLID : Feature2D { public enum BeblidSize { BitSize512 = 100, BitSize256 } public BEBLID(float scaleFactor, BeblidSize size) { _ptr = XFeatures2DInvoke.cveBEBLIDCreate(scaleFactor, size, ref _feature2D, ref _sharedPtr); } protected override void DisposeObject() { if (_sharedPtr != IntPtr.Zero) { XFeatures2DInvoke.cveBEBLIDRelease(ref _sharedPtr); } base.DisposeObject(); } } public static class XFeatures2DInvoke { [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveBEBLIDCreate(float scaleFactor, BEBLID.BeblidSize size, ref IntPtr beblid, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveBEBLIDRelease(ref IntPtr shared); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveBoostDescCreate(BoostDesc.DescriptorType desc, [MarshalAs(UnmanagedType.U1)] bool useScaleOrientation, float scalefactor, ref IntPtr feature2D, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveBoostDescRelease(ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveBriefDescriptorExtractorCreate(int descriptorSize, ref IntPtr feature2D, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveBriefDescriptorExtractorRelease(ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveDAISYCreate(float radius, int qRadius, int qTheta, int qHist, DAISY.NormalizationType norm, IntPtr H, [MarshalAs(UnmanagedType.U1)] bool interpolation, [MarshalAs(UnmanagedType.U1)] bool useOrientation, ref IntPtr daisy, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveDAISYRelease(ref IntPtr shared); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveFreakCreate([MarshalAs(UnmanagedType.U1)] bool orientationNormalized, [MarshalAs(UnmanagedType.U1)] bool scaleNormalized, float patternScale, int nOctaves, ref IntPtr feature2D, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveFreakRelease(ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveHarrisLaplaceFeatureDetectorCreate(int numOctaves, float cornThresh, float DOGThresh, int maxCorners, int numLayers, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveHarrisLaplaceFeatureDetectorRelease(ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveLATCHCreate(int bytes, [MarshalAs(UnmanagedType.U1)] bool rotationInvariance, int halfSsdSize, ref IntPtr extractor, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveLATCHRelease(ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveLUCIDCreate(int lucidKernel, int blurKernel, ref IntPtr feature2D, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveLUCIDRelease(ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveMSDDetectorCreate(int patchRadius, int searchAreaRadius, int nmsRadius, int nmsScaleRadius, float thSaliency, int kNN, float scaleFactor, int nScales, [MarshalAs(UnmanagedType.U1)] bool computeOrientation, ref IntPtr feature2D, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveMSDDetectorRelease(ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int cvePCTSignaturesGetGrayscaleBits(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cvePCTSignaturesSetGrayscaleBits(IntPtr obj, int val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int cvePCTSignaturesGetWindowRadius(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cvePCTSignaturesSetWindowRadius(IntPtr obj, int val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern float cvePCTSignaturesGetWeightX(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cvePCTSignaturesSetWeightX(IntPtr obj, float val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern float cvePCTSignaturesGetWeightY(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cvePCTSignaturesSetWeightY(IntPtr obj, float val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern float cvePCTSignaturesGetWeightL(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cvePCTSignaturesSetWeightL(IntPtr obj, float val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern float cvePCTSignaturesGetWeightA(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cvePCTSignaturesSetWeightA(IntPtr obj, float val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern float cvePCTSignaturesGetWeightB(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cvePCTSignaturesSetWeightB(IntPtr obj, float val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern float cvePCTSignaturesGetWeightEntropy(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cvePCTSignaturesSetWeightEntropy(IntPtr obj, float val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int cvePCTSignaturesGetIterationCount(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cvePCTSignaturesSetIterationCount(IntPtr obj, int val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int cvePCTSignaturesGetMaxClustersCount(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cvePCTSignaturesSetMaxClustersCount(IntPtr obj, int val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int cvePCTSignaturesGetClusterMinSize(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cvePCTSignaturesSetClusterMinSize(IntPtr obj, int val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern float cvePCTSignaturesGetJoiningDistance(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cvePCTSignaturesSetJoiningDistance(IntPtr obj, float val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern float cvePCTSignaturesGetDropThreshold(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cvePCTSignaturesSetDropThreshold(IntPtr obj, float val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern PCTSignatures.PointDistributionType cvePCTSignaturesGetDistanceFunction(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cvePCTSignaturesSetDistanceFunction(IntPtr obj, PCTSignatures.PointDistributionType val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cvePCTSignaturesCreate(int initSampleCount, int initSeedCount, PCTSignatures.PointDistributionType pointDistribution, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cvePCTSignaturesCreate2(IntPtr initSamplingPoints, int initSeedCount, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cvePCTSignaturesCreate3(IntPtr initSamplingPoints, IntPtr initClusterSeedIndexes, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cvePCTSignaturesRelease(ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cvePCTSignaturesComputeSignature(IntPtr pct, IntPtr image, IntPtr signature); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cvePCTSignaturesDrawSignature(IntPtr source, IntPtr signature, IntPtr result, float radiusToShorterSideRatio, int borderThickness); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cvePCTSignaturesSQFDCreate(PCTSignaturesSQFD.DistanceFunction distanceFunction, PCTSignaturesSQFD.SimilarityFunction similarityFunction, float similarityParameter, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern float cvePCTSignaturesSQFDComputeQuadraticFormDistance(IntPtr sqfd, IntPtr signature0, IntPtr signature1); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cvePCTSignaturesSQFDComputeQuadraticFormDistances(IntPtr sqfd, IntPtr sourceSignature, IntPtr imageSignatures, IntPtr distances); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cvePCTSignaturesSQFDRelease(ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveStarDetectorCreate(int maxSize, int responseThreshold, int lineThresholdProjected, int lineThresholdBinarized, int suppressNonmaxSize, ref IntPtr feature2D, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveStarDetectorRelease(ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveTBMRCreate(int minArea, float maxAreaRelative, float scaleFactor, int nScales, ref IntPtr tmbr, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveTBMRRelease(ref IntPtr shared); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveVGGCreate(VGG.DescriptorType desc, float isigma, [MarshalAs(UnmanagedType.U1)] bool imgNormalize, [MarshalAs(UnmanagedType.U1)] bool useScaleOrientation, float scaleFactor, [MarshalAs(UnmanagedType.U1)] bool dscNormalize, ref IntPtr feature2D, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveVGGRelease(ref IntPtr sharedPtr); static XFeatures2DInvoke() { CvInvoke.Init(); } public static void MatchGMS(Size size1, Size size2, VectorOfKeyPoint keypoints1, VectorOfKeyPoint keypoints2, VectorOfDMatch matches1to2, VectorOfDMatch matchesGMS, bool withRotation = false, bool withScale = false, double thresholdFactor = 6.0) { cveMatchGMS(ref size1, ref size2, keypoints1, keypoints2, matches1to2, matchesGMS, withRotation, withScale, thresholdFactor); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveMatchGMS(ref Size size1, ref Size size2, IntPtr keypoints1, IntPtr keypoints2, IntPtr matches1to2, IntPtr matchesGMS, [MarshalAs(UnmanagedType.U1)] bool withRotation, [MarshalAs(UnmanagedType.U1)] bool withScale, double thresholdFactor); public static void MatchLOGOS(VectorOfKeyPoint keypoints1, VectorOfKeyPoint keypoints2, VectorOfInt nn1, VectorOfInt nn2, VectorOfDMatch matches1to2) { cveMatchLOGOS(keypoints1, keypoints2, nn1, nn2, matches1to2); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveMatchLOGOS(IntPtr keypoints1, IntPtr keypoints2, IntPtr nn1, IntPtr nn2, IntPtr matches1to2); } public class BoostDesc : Feature2D { public enum DescriptorType { Bgm = 100, BgmHard = 101, BgmBilinear = 102, Lbgm = 200, Binboost64 = 300, Binboost128 = 301, Binboost256 = 302 } public BoostDesc(DescriptorType desc = DescriptorType.Binboost256, bool useScaleOrientation = true, float scalefactor = 6.25f) { _ptr = XFeatures2DInvoke.cveBoostDescCreate(desc, useScaleOrientation, scalefactor, ref _feature2D, ref _sharedPtr); } protected override void DisposeObject() { if (_sharedPtr != IntPtr.Zero) { XFeatures2DInvoke.cveBoostDescRelease(ref _sharedPtr); } base.DisposeObject(); } } public class BriefDescriptorExtractor : Feature2D { public BriefDescriptorExtractor(int descriptorSize = 32) { _ptr = XFeatures2DInvoke.cveBriefDescriptorExtractorCreate(descriptorSize, ref _feature2D, ref _sharedPtr); } protected override void DisposeObject() { if (_sharedPtr != IntPtr.Zero) { XFeatures2DInvoke.cveBriefDescriptorExtractorRelease(ref _sharedPtr); } base.DisposeObject(); } } public class DAISY : Feature2D { public enum NormalizationType { None = 100, Partial, Full, SIFT } public DAISY(float radius = 15f, int qRadius = 3, int qTheta = 8, int qHist = 8, NormalizationType norm = NormalizationType.None, IInputArray H = null, bool interpolation = true, bool useOrientation = false) { using InputArray inputArray = ((H == null) ? InputArray.GetEmpty() : H.GetInputArray()); _ptr = XFeatures2DInvoke.cveDAISYCreate(radius, qRadius, qTheta, qHist, norm, inputArray, interpolation, useOrientation, ref _feature2D, ref _sharedPtr); } protected override void DisposeObject() { if (_sharedPtr != IntPtr.Zero) { XFeatures2DInvoke.cveDAISYRelease(ref _sharedPtr); } base.DisposeObject(); } } public class Freak : Feature2D { public Freak(bool orientationNormalized = true, bool scaleNormalized = true, float patternScale = 22f, int nOctaves = 4) { _ptr = XFeatures2DInvoke.cveFreakCreate(orientationNormalized, scaleNormalized, patternScale, nOctaves, ref _feature2D, ref _sharedPtr); } protected override void DisposeObject() { if (_sharedPtr != IntPtr.Zero) { XFeatures2DInvoke.cveFreakRelease(ref _sharedPtr); } base.DisposeObject(); } } public class HarrisLaplaceFeatureDetector : Feature2D { public HarrisLaplaceFeatureDetector(int numOctaves, float cornThresh, float DOGThresh, int maxCorners, int numLayers) { _ptr = XFeatures2DInvoke.cveHarrisLaplaceFeatureDetectorCreate(numOctaves, cornThresh, DOGThresh, maxCorners, numLayers, ref _sharedPtr); } protected override void DisposeObject() { if (_sharedPtr != IntPtr.Zero) { XFeatures2DInvoke.cveHarrisLaplaceFeatureDetectorRelease(ref _sharedPtr); } base.DisposeObject(); } } public class LATCH : Feature2D { public LATCH(int bytes = 32, bool rotationInvariance = true, int halfSsdSize = 3) { _ptr = XFeatures2DInvoke.cveLATCHCreate(bytes, rotationInvariance, halfSsdSize, ref _feature2D, ref _sharedPtr); } protected override void DisposeObject() { if (_sharedPtr != IntPtr.Zero) { XFeatures2DInvoke.cveLATCHRelease(ref _sharedPtr); } base.DisposeObject(); } } public class LUCID : Feature2D { public LUCID(int lucidKernel = 1, int blurKernel = 2) { _ptr = XFeatures2DInvoke.cveLUCIDCreate(lucidKernel, blurKernel, ref _feature2D, ref _sharedPtr); } protected override void DisposeObject() { if (_sharedPtr != IntPtr.Zero) { XFeatures2DInvoke.cveLUCIDRelease(ref _sharedPtr); } base.DisposeObject(); } } public class MSDDetector : Feature2D { public MSDDetector(int patchRadius, int searchAreaRadius, int nmsRadius, int nmsScaleRadius, float thSaliency, int kNN, float scaleFactor, int nScales, bool computeOrientation) { _ptr = XFeatures2DInvoke.cveMSDDetectorCreate(patchRadius, searchAreaRadius, nmsRadius, nmsScaleRadius, thSaliency, kNN, scaleFactor, nScales, computeOrientation, ref _feature2D, ref _sharedPtr); } protected override void DisposeObject() { if (_sharedPtr != IntPtr.Zero) { XFeatures2DInvoke.cveMSDDetectorRelease(ref _sharedPtr); } base.DisposeObject(); } } public class PCTSignatures : SharedPtrObject { public enum PointDistributionType { Uniform, Regular, Normal } public int GrayscaleBits { get { return XFeatures2DInvoke.cvePCTSignaturesGetGrayscaleBits(_ptr); } set { XFeatures2DInvoke.cvePCTSignaturesSetGrayscaleBits(_ptr, value); } } public int WindowRadius { get { return XFeatures2DInvoke.cvePCTSignaturesGetWindowRadius(_ptr); } set { XFeatures2DInvoke.cvePCTSignaturesSetWindowRadius(_ptr, value); } } public float WeightX { get { return XFeatures2DInvoke.cvePCTSignaturesGetWeightX(_ptr); } set { XFeatures2DInvoke.cvePCTSignaturesSetWeightX(_ptr, value); } } public float WeightY { get { return XFeatures2DInvoke.cvePCTSignaturesGetWeightY(_ptr); } set { XFeatures2DInvoke.cvePCTSignaturesSetWeightY(_ptr, value); } } public float WeightL { get { return XFeatures2DInvoke.cvePCTSignaturesGetWeightL(_ptr); } set { XFeatures2DInvoke.cvePCTSignaturesSetWeightL(_ptr, value); } } public float WeightA { get { return XFeatures2DInvoke.cvePCTSignaturesGetWeightA(_ptr); } set { XFeatures2DInvoke.cvePCTSignaturesSetWeightA(_ptr, value); } } public float WeightB { get { return XFeatures2DInvoke.cvePCTSignaturesGetWeightB(_ptr); } set { XFeatures2DInvoke.cvePCTSignaturesSetWeightB(_ptr, value); } } public float WeightEntropy { get { return XFeatures2DInvoke.cvePCTSignaturesGetWeightEntropy(_ptr); } set { XFeatures2DInvoke.cvePCTSignaturesSetWeightEntropy(_ptr, value); } } public int IterationCount { get { return XFeatures2DInvoke.cvePCTSignaturesGetIterationCount(_ptr); } set { XFeatures2DInvoke.cvePCTSignaturesSetIterationCount(_ptr, value); } } public int MaxClustersCount { get { return XFeatures2DInvoke.cvePCTSignaturesGetMaxClustersCount(_ptr); } set { XFeatures2DInvoke.cvePCTSignaturesSetMaxClustersCount(_ptr, value); } } public int ClusterMinSize { get { return XFeatures2DInvoke.cvePCTSignaturesGetClusterMinSize(_ptr); } set { XFeatures2DInvoke.cvePCTSignaturesSetClusterMinSize(_ptr, value); } } public float JoiningDistance { get { return XFeatures2DInvoke.cvePCTSignaturesGetJoiningDistance(_ptr); } set { XFeatures2DInvoke.cvePCTSignaturesSetJoiningDistance(_ptr, value); } } public float DropThreshold { get { return XFeatures2DInvoke.cvePCTSignaturesGetDropThreshold(_ptr); } set { XFeatures2DInvoke.cvePCTSignaturesSetDropThreshold(_ptr, value); } } public PointDistributionType DistanceFunction { get { return XFeatures2DInvoke.cvePCTSignaturesGetDistanceFunction(_ptr); } set { XFeatures2DInvoke.cvePCTSignaturesSetDistanceFunction(_ptr, value); } } public PCTSignatures(int initSampleCount = 2000, int initSeedCount = 400, PointDistributionType pointDistribution = PointDistributionType.Uniform) { _ptr = XFeatures2DInvoke.cvePCTSignaturesCreate(initSampleCount, initSeedCount, pointDistribution, ref _sharedPtr); } public PCTSignatures(VectorOfPointF initSamplingPoints, int initSeedCount) { _ptr = XFeatures2DInvoke.cvePCTSignaturesCreate2(initSamplingPoints, initSeedCount, ref _sharedPtr); } public PCTSignatures(VectorOfPointF initSamplingPoints, VectorOfInt initClusterSeedIndexes) { _ptr = XFeatures2DInvoke.cvePCTSignaturesCreate3(initSamplingPoints, initClusterSeedIndexes, ref _sharedPtr); } protected override void DisposeObject() { if (_sharedPtr != IntPtr.Zero) { XFeatures2DInvoke.cvePCTSignaturesRelease(ref _sharedPtr); _ptr = IntPtr.Zero; } } public void ComputeSignature(IInputArray image, IOutputArray signature) { using InputArray inputArray = image.GetInputArray(); using OutputArray outputArray = signature.GetOutputArray(); XFeatures2DInvoke.cvePCTSignaturesComputeSignature(_ptr, inputArray, outputArray); } public static void DrawSignature(IInputArray source, IInputArray signature, IOutputArray result, float radiusToShorterSideRatio = 0.125f, int borderThickness = 1) { using InputArray inputArray = source.GetInputArray(); using InputArray inputArray2 = signature.GetInputArray(); using OutputArray outputArray = result.GetOutputArray(); XFeatures2DInvoke.cvePCTSignaturesDrawSignature(inputArray, inputArray2, outputArray, radiusToShorterSideRatio, borderThickness); } } public class PCTSignaturesSQFD : SharedPtrObject { public enum DistanceFunction { L0_25, L0_5, L1, L2, L2Squared, L5, LInfinity } public enum SimilarityFunction { Minus, Gaussian, Heuristic } public PCTSignaturesSQFD(DistanceFunction distanceFunction = DistanceFunction.L2, SimilarityFunction similarityFunction = SimilarityFunction.Heuristic, float similarityParameter = 1f) { _ptr = XFeatures2DInvoke.cvePCTSignaturesSQFDCreate(distanceFunction, similarityFunction, similarityParameter, ref _sharedPtr); } public float ComputeQuadraticFormDistance(IInputArray signature0, IInputArray signature1) { using InputArray inputArray = signature0.GetInputArray(); using InputArray inputArray2 = signature1.GetInputArray(); return XFeatures2DInvoke.cvePCTSignaturesSQFDComputeQuadraticFormDistance(_ptr, inputArray, inputArray2); } public void ComputeQuadraticFormDistances(Mat sourceSignature, VectorOfMat imageSignatures, VectorOfFloat distances) { XFeatures2DInvoke.cvePCTSignaturesSQFDComputeQuadraticFormDistances(_ptr, sourceSignature, imageSignatures, distances); } protected override void DisposeObject() { if (_sharedPtr != IntPtr.Zero) { XFeatures2DInvoke.cvePCTSignaturesSQFDRelease(ref _sharedPtr); _ptr = IntPtr.Zero; } } } public class StarDetector : Feature2D { public StarDetector(int maxSize = 45, int responseThreshold = 30, int lineThresholdProjected = 10, int lineThresholdBinarized = 8, int suppressNonmaxSize = 5) { _ptr = XFeatures2DInvoke.cveStarDetectorCreate(maxSize, responseThreshold, lineThresholdProjected, lineThresholdBinarized, suppressNonmaxSize, ref _feature2D, ref _sharedPtr); } protected override void DisposeObject() { if (_sharedPtr != IntPtr.Zero) { XFeatures2DInvoke.cveStarDetectorRelease(ref _sharedPtr); } base.DisposeObject(); } } public class TBMR : Feature2D { public TBMR(int minArea = 60, float maxAreaRelative = 0.01f, float scaleFactor = 1.25f, int nScales = -1) { _ptr = XFeatures2DInvoke.cveTBMRCreate(minArea, maxAreaRelative, scaleFactor, nScales, ref _feature2D, ref _sharedPtr); } protected override void DisposeObject() { if (_sharedPtr != IntPtr.Zero) { XFeatures2DInvoke.cveTBMRRelease(ref _sharedPtr); } base.DisposeObject(); } } public class VGG : Feature2D { public enum DescriptorType { Vgg120 = 100, Vgg80, Vgg64, Vgg48 } public VGG(DescriptorType desc = DescriptorType.Vgg120, float isigma = 1.4f, bool imgNormalize = true, bool useScaleOrientation = true, float scaleFactor = 6.25f, bool dscNormalize = false) { _ptr = XFeatures2DInvoke.cveVGGCreate(desc, isigma, imgNormalize, useScaleOrientation, scaleFactor, dscNormalize, ref _feature2D, ref _sharedPtr); } protected override void DisposeObject() { if (_sharedPtr != IntPtr.Zero) { XFeatures2DInvoke.cveVGGRelease(ref _sharedPtr); } base.DisposeObject(); } } } namespace Emgu.CV.Saliency { public static class SaliencyInvoke { [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int cveMotionSaliencyBinWangApr2014GetImageWidth(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveMotionSaliencyBinWangApr2014SetImageWidth(IntPtr obj, int val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int cveMotionSaliencyBinWangApr2014GetImageHeight(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveMotionSaliencyBinWangApr2014SetImageHeight(IntPtr obj, int val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.U1)] internal static extern bool cveMotionSaliencyBinWangApr2014Init(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int cveObjectnessBINGGetW(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveObjectnessBINGSetW(IntPtr obj, int val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int cveObjectnessBINGGetNSS(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveObjectnessBINGSetNSS(IntPtr obj, int val); static SaliencyInvoke() { CvInvoke.Init(); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveStaticSaliencySpectralResidualCreate(ref IntPtr staticSaliency, ref IntPtr saliency, ref IntPtr algorithm, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveStaticSaliencySpectralResidualRelease(ref IntPtr saliency, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveStaticSaliencyFineGrainedCreate(ref IntPtr staticSaliency, ref IntPtr saliency, ref IntPtr algorithm, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveStaticSaliencyFineGrainedRelease(ref IntPtr saliency, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveMotionSaliencyBinWangApr2014Create(ref IntPtr motionSaliency, ref IntPtr saliency, ref IntPtr algorithm, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveMotionSaliencyBinWangApr2014Release(ref IntPtr saliency, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveObjectnessBINGCreate(ref IntPtr objectnessSaliency, ref IntPtr saliency, ref IntPtr algorithm, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveObjectnessBINGRelease(ref IntPtr saliency, ref IntPtr sharedPtr); public static bool Compute(this ISaliency saliency, IInputArray image, IOutputArray saliencyMap) { using InputArray inputArray = image.GetInputArray(); using OutputArray outputArray = saliencyMap.GetOutputArray(); return cveSaliencyComputeSaliency(saliency.SaliencyPtr, inputArray, outputArray); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.U1)] internal static extern bool cveSaliencyComputeSaliency(IntPtr saliency, IntPtr image, IntPtr saliencyMap); public static bool ComputeBinaryMap(this IStaticSaliency saliency, IInputArray saliencyMap, IOutputArray binaryMap) { using InputArray inputArray = saliencyMap.GetInputArray(); using OutputArray outputArray = binaryMap.GetOutputArray(); return cveStaticSaliencyComputeBinaryMap(saliency.StaticSaliencyPtr, inputArray, outputArray); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.U1)] internal static extern bool cveStaticSaliencyComputeBinaryMap(IntPtr staticSaliency, IntPtr saliencyMap, IntPtr binaryMap); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveObjectnessBINGGetObjectnessValues(IntPtr bing, IntPtr vectorOfFloat); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveObjectnessBINGSetTrainingPath(IntPtr bing, IntPtr trainingPath); } public class MotionSaliencyBinWangApr2014 : UnmanagedObject, IMotionSaliency, ISaliency, IAlgorithm { private IntPtr _motionSaliencyPtr; private IntPtr _saliencyPtr; private IntPtr _algorithmPtr; private IntPtr _sharedPtr; public int ImageWidth { get { return SaliencyInvoke.cveMotionSaliencyBinWangApr2014GetImageWidth(_ptr); } set { SaliencyInvoke.cveMotionSaliencyBinWangApr2014SetImageWidth(_ptr, value); } } public int ImageHeight { get { return SaliencyInvoke.cveMotionSaliencyBinWangApr2014GetImageHeight(_ptr); } set { SaliencyInvoke.cveMotionSaliencyBinWangApr2014SetImageHeight(_ptr, value); } } public IntPtr MotionSaliencyPtr => _motionSaliencyPtr; public IntPtr SaliencyPtr => _saliencyPtr; public IntPtr AlgorithmPtr => _algorithmPtr; public bool Init() { return SaliencyInvoke.cveMotionSaliencyBinWangApr2014Init(_ptr); } public MotionSaliencyBinWangApr2014() { _ptr = SaliencyInvoke.cveMotionSaliencyBinWangApr2014Create(ref _motionSaliencyPtr, ref _saliencyPtr, ref _algorithmPtr, ref _sharedPtr); } protected override void DisposeObject() { if (_ptr != IntPtr.Zero) { SaliencyInvoke.cveMotionSaliencyBinWangApr2014Release(ref _ptr, ref _sharedPtr); } _motionSaliencyPtr = IntPtr.Zero; _saliencyPtr = IntPtr.Zero; _algorithmPtr = IntPtr.Zero; } } public class ObjectnessBING : UnmanagedObject, IObjectness, ISaliency, IAlgorithm { private IntPtr _objectnessPtr; private IntPtr _saliencyPtr; private IntPtr _algorithmPtr; private IntPtr _sharedPtr; public int W { get { return SaliencyInvoke.cveObjectnessBINGGetW(_ptr); } set { SaliencyInvoke.cveObjectnessBINGSetW(_ptr, value); } } public int NSS { get { return SaliencyInvoke.cveObjectnessBINGGetNSS(_ptr); } set { SaliencyInvoke.cveObjectnessBINGSetNSS(_ptr, value); } } public IntPtr ObjectnessPtr => _objectnessPtr; public IntPtr SaliencyPtr => _saliencyPtr; public IntPtr AlgorithmPtr => _algorithmPtr; public ObjectnessBING() { _ptr = SaliencyInvoke.cveObjectnessBINGCreate(ref _objectnessPtr, ref _saliencyPtr, ref _algorithmPtr, ref _sharedPtr); } protected override void DisposeObject() { if (_ptr != IntPtr.Zero) { SaliencyInvoke.cveObjectnessBINGRelease(ref _ptr, ref _sharedPtr); } _objectnessPtr = IntPtr.Zero; _saliencyPtr = IntPtr.Zero; _algorithmPtr = IntPtr.Zero; } public float[] GetObjectnessValues() { using VectorOfFloat vectorOfFloat = new VectorOfFloat(); SaliencyInvoke.cveObjectnessBINGGetObjectnessValues(_ptr, vectorOfFloat); return vectorOfFloat.ToArray(); } public void SetTrainingPath(string trainingPath) { using CvString cvString = new CvString(trainingPath); SaliencyInvoke.cveObjectnessBINGSetTrainingPath(_ptr, cvString); } } public interface ISaliency : IAlgorithm { IntPtr SaliencyPtr { get; } } public interface IStaticSaliency : ISaliency, IAlgorithm { IntPtr StaticSaliencyPtr { get; } } public interface IMotionSaliency : ISaliency, IAlgorithm { IntPtr MotionSaliencyPtr { get; } } public interface IObjectness : ISaliency, IAlgorithm { IntPtr ObjectnessPtr { get; } } public class StaticSaliencySpectralResidual : UnmanagedObject, IStaticSaliency, ISaliency, IAlgorithm { private IntPtr _staticSaliencyPtr; private IntPtr _saliencyPtr; private IntPtr _algorithmPtr; private IntPtr _sharedPtr; public IntPtr StaticSaliencyPtr => _staticSaliencyPtr; public IntPtr SaliencyPtr => _saliencyPtr; public IntPtr AlgorithmPtr => _algorithmPtr; public StaticSaliencySpectralResidual() { _ptr = SaliencyInvoke.cveStaticSaliencySpectralResidualCreate(ref _staticSaliencyPtr, ref _saliencyPtr, ref _algorithmPtr, ref _sharedPtr); } protected override void DisposeObject() { if (_ptr != IntPtr.Zero) { SaliencyInvoke.cveStaticSaliencySpectralResidualRelease(ref _ptr, ref _sharedPtr); } _staticSaliencyPtr = IntPtr.Zero; _saliencyPtr = IntPtr.Zero; _algorithmPtr = IntPtr.Zero; } } public class StaticSaliencyFineGrained : UnmanagedObject, IStaticSaliency, ISaliency, IAlgorithm { private IntPtr _staticSaliencyPtr; private IntPtr _saliencyPtr; private IntPtr _algorithmPtr; private IntPtr _sharedPtr; public IntPtr StaticSaliencyPtr => _staticSaliencyPtr; public IntPtr SaliencyPtr => _saliencyPtr; public IntPtr AlgorithmPtr => _algorithmPtr; public StaticSaliencyFineGrained() { _ptr = SaliencyInvoke.cveStaticSaliencyFineGrainedCreate(ref _staticSaliencyPtr, ref _saliencyPtr, ref _algorithmPtr, ref _sharedPtr); } protected override void DisposeObject() { if (_ptr != IntPtr.Zero) { SaliencyInvoke.cveStaticSaliencyFineGrainedRelease(ref _ptr, ref _sharedPtr); } _staticSaliencyPtr = IntPtr.Zero; _saliencyPtr = IntPtr.Zero; _algorithmPtr = IntPtr.Zero; } } } namespace Emgu.CV.Dpm { public class DpmDetector : SharedPtrObject { public bool IsEmpty => DpmInvoke.cveDPMDetectorIsEmpty(_ptr); public string[] ClassNames { get { using VectorOfCvString vectorOfCvString = new VectorOfCvString(); DpmInvoke.cveDPMDetectorGetClassNames(_ptr, vectorOfCvString); return vectorOfCvString.ToArray(); } } public int ClassCount => (int)DpmInvoke.cveDPMDetectorGetClassCount(_ptr).ToUInt32(); public DpmDetector(string[] files, string[] classes = null) { CvString[] array = new CvString[files.Length]; for (int i = 0; i < files.Length; i++) { array[i] = new CvString(files[i]); } CvString[] array2; if (classes == null) { array2 = new CvString[0]; } else { array2 = new CvString[classes.Length]; for (int j = 0; j < classes.Length; j++) { array2[j] = new CvString(classes[j]); } } try { using VectorOfCvString vectorOfCvString = new VectorOfCvString(array); using VectorOfCvString vectorOfCvString2 = new VectorOfCvString(array2); _ptr = DpmInvoke.cveDPMDetectorCreate(vectorOfCvString, vectorOfCvString2, ref _sharedPtr); } finally { CvString[] array3 = array; for (int k = 0; k < array3.Length; k++) { array3[k].Dispose(); } array3 = array2; for (int k = 0; k < array3.Length; k++) { array3[k].Dispose(); } } } public ObjectDetection[] Detect(Mat mat) { using VectorOfRect vectorOfRect = new VectorOfRect(); using VectorOfFloat vectorOfFloat = new VectorOfFloat(); using VectorOfInt vectorOfInt = new VectorOfInt(); DpmInvoke.cveDPMDetectorDetect(_ptr, mat, vectorOfRect, vectorOfFloat, vectorOfInt); ObjectDetection[] array = new ObjectDetection[vectorOfRect.Size]; for (int i = 0; i < array.Length; i++) { array[i] = new ObjectDetection(vectorOfRect[i], vectorOfFloat[i], vectorOfInt[i]); } return array; } protected override void DisposeObject() { if (_sharedPtr != IntPtr.Zero) { DpmInvoke.cveDPMDetectorRelease(ref _sharedPtr); _ptr = IntPtr.Zero; } } } public static class DpmInvoke { [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveDPMDetectorCreate(IntPtr files, IntPtr classes, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveDPMDetectorDetect(IntPtr dpm, IntPtr mat, IntPtr rects, IntPtr scores, IntPtr classIds); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern UIntPtr cveDPMDetectorGetClassCount(IntPtr dpm); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveDPMDetectorGetClassNames(IntPtr dpm, IntPtr vector); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.U1)] internal static extern bool cveDPMDetectorIsEmpty(IntPtr dpm); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveDPMDetectorRelease(ref IntPtr sharedPtr); static DpmInvoke() { CvInvoke.Init(); } } public struct ObjectDetection { public readonly Rectangle Rect; public readonly float Score; public readonly int ClassId; public ObjectDetection(Rectangle rect, float score, int classId) { Rect = rect; Score = score; ClassId = classId; } } } namespace Emgu.CV.Alphamat { public static class AlphamatInvoke { static AlphamatInvoke() { CvInvoke.Init(); } public static void InfoFlow(IInputArray image, IInputArray tmap, IOutputArray result) { using InputArray inputArray = image.GetInputArray(); using InputArray inputArray2 = tmap.GetInputArray(); using OutputArray outputArray = result.GetOutputArray(); cveAlphamatInfoFlow(inputArray, inputArray2, outputArray); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveAlphamatInfoFlow(IntPtr image, IntPtr tmap, IntPtr result); } } namespace Emgu.CV.Cuda { public class CudaConvolution : SharedPtrObject { public CudaConvolution(Size userBlockSize = default(Size)) { _ptr = CudaInvoke.cudaConvolutionCreate(ref userBlockSize, ref _sharedPtr); } public void Convolve(IInputArray image, IInputArray templ, IOutputArray result, bool ccorr, Stream stream = null) { using InputArray inputArray = image.GetInputArray(); using InputArray inputArray2 = templ.GetInputArray(); using OutputArray outputArray = result.GetOutputArray(); CudaInvoke.cudaConvolutionConvolve(_ptr, inputArray, inputArray2, outputArray, ccorr, stream); } protected override void DisposeObject() { if (_sharedPtr != IntPtr.Zero) { CudaInvoke.cudaConvolutionRelease(ref _sharedPtr); _ptr = IntPtr.Zero; } } } public static class CudaInvoke { private static bool _testedCuda; private static bool _hasCuda; public static bool HasCuda { get { if (_testedCuda) { return _hasCuda; } _testedCuda = true; try { _hasCuda = GetCudaEnabledDeviceCount() > 0; } catch (Exception) { } return _hasCuda; } } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cudaConvolutionCreate(ref Size userBlockSize, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cudaConvolutionConvolve(IntPtr convolution, IntPtr image, IntPtr templ, IntPtr result, [MarshalAs(UnmanagedType.U1)] bool ccorr, IntPtr stream); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cudaConvolutionRelease(ref IntPtr convolution); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cudaDeviceInfoCreate(ref int deviceId); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cudaDeviceInfoRelease(ref IntPtr di); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cudaDeviceInfoComputeCapability(IntPtr device, ref int major, ref int minor); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int cudaDeviceInfoMultiProcessorCount(IntPtr device); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cudaDeviceInfoFreeMemInfo(IntPtr device, ref UIntPtr free); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cudaDeviceInfoTotalMemInfo(IntPtr device, ref UIntPtr total); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cudaDeviceInfoDeviceName(IntPtr device, [MarshalAs(UnmanagedType.LPStr)] StringBuilder buffer, int maxSizeInBytes); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.U1)] internal static extern bool cudaDeviceInfoSupports(IntPtr device, CudaDeviceInfo.GpuFeature feature); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.U1)] internal static extern bool cudaDeviceInfoIsCompatible(IntPtr device); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl, EntryPoint = "cudaPrintCudaDeviceInfo")] public static extern void PrintCudaDeviceInfo(int device); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl, EntryPoint = "cudaPrintShortCudaDeviceInfo")] public static extern void PrintShortCudaDeviceInfo(int device); static CudaInvoke() { CvInvoke.Init(); } public static string GetCudaDevicesSummary() { StringBuilder stringBuilder = new StringBuilder(); if (HasCuda) { stringBuilder.Append($"Has cuda: true{Environment.NewLine}"); int cudaEnabledDeviceCount = GetCudaEnabledDeviceCount(); stringBuilder.Append($"Cuda devices count: {cudaEnabledDeviceCount}{Environment.NewLine}"); for (int i = 0; i < cudaEnabledDeviceCount; i++) { using CudaDeviceInfo cudaDeviceInfo = new CudaDeviceInfo(i); stringBuilder.Append(string.Format("Device {0}:{1} Name: {2}{1} Cuda Compute Capability: {3}{1} Multi-Processor count: {4}{1} Total Memory: {5}{1} Free Memory: {6}{1}", i, Environment.NewLine, cudaDeviceInfo.Name, cudaDeviceInfo.CudaComputeCapability, cudaDeviceInfo.MultiProcessorCount, cudaDeviceInfo.TotalMemory, cudaDeviceInfo.FreeMemory)); } return stringBuilder.ToString(); } return "Has cuda: false"; } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl, EntryPoint = "cudaGetCudaEnabledDeviceCount")] public static extern int GetCudaEnabledDeviceCount(); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl, EntryPoint = "cudaSetDevice")] public static extern void SetDevice(int deviceId); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl, EntryPoint = "cudaGetDevice")] public static extern int GetDevice(); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl, EntryPoint = "cudaResetDevice")] public static extern void ResetDevice(); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl, EntryPoint = "gpuMatGetRegion")] public static extern IntPtr GetRegion(IntPtr gpuMat, ref Emgu.CV.Structure.Range rowRange, ref Emgu.CV.Structure.Range colRange); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl, EntryPoint = "gpuMatReshape")] public static extern void GpuMatReshape(IntPtr src, IntPtr dst, int cn, int rows); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl, EntryPoint = "gpuMatGetSubRect")] public static extern IntPtr GetSubRect(IntPtr mat, ref Rectangle rect); public static void LShift(IInputArray a, MCvScalar scalar, IOutputArray c, Stream stream = null) { using InputArray inputArray = a.GetInputArray(); using OutputArray outputArray = c.GetOutputArray(); cudaLShift(inputArray, ref scalar, outputArray, stream); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cudaLShift(IntPtr a, ref MCvScalar scalar, IntPtr c, IntPtr stream); public static void RShift(IInputArray a, MCvScalar scalar, IOutputArray c, Stream stream = null) { using InputArray inputArray = a.GetInputArray(); using OutputArray outputArray = c.GetOutputArray(); cudaRShift(inputArray, ref scalar, outputArray, stream); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cudaRShift(IntPtr a, ref MCvScalar scalar, IntPtr c, IntPtr stream); public static void Add(IInputArray a, IInputArray b, IOutputArray c, IInputArray mask = null, DepthType depthType = DepthType.Default, Stream stream = null) { using InputArray inputArray = a.GetInputArray(); using InputArray inputArray2 = b.GetInputArray(); using OutputArray outputArray = c.GetOutputArray(); using InputArray inputArray3 = ((mask == null) ? InputArray.GetEmpty() : mask.GetInputArray()); cudaAdd(inputArray, inputArray2, outputArray, inputArray3, depthType, stream); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cudaAdd(IntPtr a, IntPtr b, IntPtr c, IntPtr mask, DepthType depthType, IntPtr stream); public static void Subtract(IInputArray a, IInputArray b, IOutputArray c, IInputArray mask = null, DepthType depthType = DepthType.Default, Stream stream = null) { using InputArray inputArray = a.GetInputArray(); using InputArray inputArray2 = b.GetInputArray(); using OutputArray outputArray = c.GetOutputArray(); using InputArray inputArray3 = ((mask == null) ? InputArray.GetEmpty() : mask.GetInputArray()); cudaSubtract(inputArray, inputArray2, outputArray, inputArray3, depthType, stream); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cudaSubtract(IntPtr a, IntPtr b, IntPtr c, IntPtr mask, DepthType depthType, IntPtr stream); public static void Multiply(IInputArray a, IInputArray b, IOutputArray c, double scale = 1.0, DepthType depthType = DepthType.Default, Stream stream = null) { using InputArray inputArray = a.GetInputArray(); using InputArray inputArray2 = b.GetInputArray(); using OutputArray outputArray = c.GetOutputArray(); cudaMultiply(inputArray, inputArray2, outputArray, scale, depthType, stream); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cudaMultiply(IntPtr a, IntPtr b, IntPtr c, double scale, DepthType depthType, IntPtr stream); public static void Divide(IInputArray a, IInputArray b, IOutputArray c, double scale = 1.0, DepthType depthType = DepthType.Default, Stream stream = null) { using InputArray inputArray = a.GetInputArray(); using InputArray inputArray2 = b.GetInputArray(); using OutputArray outputArray = c.GetOutputArray(); cudaDivide(inputArray, inputArray2, outputArray, scale, depthType, stream); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cudaDivide(IntPtr a, IntPtr b, IntPtr c, double scale, DepthType depthType, IntPtr stream); public static void AddWeighted(IInputArray src1, double alpha, IInputArray src2, double beta, double gamma, IOutputArray dst, DepthType depthType = DepthType.Default, Stream stream = null) { using InputArray inputArray = src1.GetInputArray(); using InputArray inputArray2 = src2.GetInputArray(); using OutputArray outputArray = dst.GetOutputArray(); cudaAddWeighted(inputArray, alpha, inputArray2, beta, gamma, outputArray, depthType, stream); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cudaAddWeighted(IntPtr src1, double alpha, IntPtr src2, double beta, double gamma, IntPtr dst, DepthType depthType, IntPtr stream); public static void Absdiff(IInputArray a, IInputArray b, IOutputArray c, Stream stream = null) { using InputArray inputArray = a.GetInputArray(); using InputArray inputArray2 = b.GetInputArray(); using OutputArray outputArray = c.GetOutputArray(); cudaAbsdiff(inputArray, inputArray2, outputArray, stream); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cudaAbsdiff(IntPtr a, IntPtr b, IntPtr c, IntPtr stream); public static void Abs(IInputArray src, IOutputArray dst, Stream stream = null) { using InputArray inputArray = src.GetInputArray(); using OutputArray outputArray = dst.GetOutputArray(); cudaAbs(inputArray, outputArray, stream); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cudaAbs(IntPtr src, IntPtr dst, IntPtr stream); public static void Sqr(IInputArray src, IOutputArray dst, Stream stream = null) { using InputArray inputArray = src.GetInputArray(); using OutputArray outputArray = dst.GetOutputArray(); cudaSqr(inputArray, outputArray, stream); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cudaSqr(IntPtr src, IntPtr dst, IntPtr stream); public static void Sqrt(IInputArray src, IOutputArray dst, Stream stream = null) { using InputArray inputArray = src.GetInputArray(); using OutputArray outputArray = dst.GetOutputArray(); cudaSqrt(inputArray, outputArray, stream); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cudaSqrt(IntPtr src, IntPtr dst, IntPtr stream); public static void Transpose(IInputArray src, IOutputArray dst, Stream stream = null) { using InputArray inputArray = src.GetInputArray(); using OutputArray outputArray = dst.GetOutputArray(); cudaTranspose(inputArray, outputArray, stream); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cudaTranspose(IntPtr src, IntPtr dst, IntPtr stream); public static void Compare(IInputArray a, IInputArray b, IOutputArray c, CmpType cmpop, Stream stream = null) { using InputArray inputArray = a.GetInputArray(); using InputArray inputArray2 = b.GetInputArray(); using OutputArray outputArray = c.GetOutputArray(); cudaCompare(inputArray, inputArray2, outputArray, cmpop, stream); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cudaCompare(IntPtr a, IntPtr b, IntPtr c, CmpType cmpop, IntPtr stream); public static void Resize(IInputArray src, IOutputArray dst, Size dsize, double fx = 0.0, double fy = 0.0, Inter interpolation = Inter.Linear, Stream stream = null) { using InputArray inputArray = src.GetInputArray(); using OutputArray outputArray = dst.GetOutputArray(); cudaResize(inputArray, outputArray, ref dsize, fx, fy, interpolation, stream); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cudaResize(IntPtr src, IntPtr dst, ref Size dsize, double fx, double fy, Inter interpolation, IntPtr stream); public static void Split(IInputArray src, VectorOfGpuMat dstArray, Stream stream = null) { using InputArray inputArray = src.GetInputArray(); cudaSplit(inputArray, dstArray, stream); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cudaSplit(IntPtr src, IntPtr dstArray, IntPtr stream); public static void Merge(VectorOfGpuMat srcArr, IOutputArray dst, Stream stream = null) { using OutputArray outputArray = dst.GetOutputArray(); cudaMerge(srcArr, outputArray, stream); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cudaMerge(IntPtr srcArr, IntPtr dst, IntPtr stream); public static void Exp(IInputArray src, IOutputArray dst, Stream stream = null) { using InputArray inputArray = src.GetInputArray(); using OutputArray outputArray = dst.GetOutputArray(); cudaExp(inputArray, outputArray, stream); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cudaExp(IntPtr src, IntPtr dst, IntPtr stream); public static void Pow(IInputArray src, double power, IOutputArray dst, Stream stream = null) { using InputArray inputArray = src.GetInputArray(); using OutputArray outputArray = dst.GetOutputArray(); cudaPow(inputArray, power, outputArray, stream); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cudaPow(IntPtr src, double power, IntPtr dst, IntPtr stream); public static void Log(IInputArray src, IOutputArray dst, Stream stream = null) { using InputArray inputArray = src.GetInputArray(); using OutputArray outputArray = dst.GetOutputArray(); cudaLog(inputArray, outputArray, stream); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cudaLog(IntPtr src, IntPtr dst, IntPtr stream); public static void Magnitude(IInputArray x, IInputArray y, IOutputArray magnitude, Stream stream = null) { using InputArray inputArray = x.GetInputArray(); using InputArray inputArray2 = y.GetInputArray(); using OutputArray outputArray = magnitude.GetOutputArray(); cudaMagnitude(inputArray, inputArray2, outputArray, stream); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cudaMagnitude(IntPtr x, IntPtr y, IntPtr magnitude, IntPtr stream); public static void MagnitudeSqr(IInputArray x, IInputArray y, IOutputArray magnitude, Stream stream = null) { using InputArray inputArray = x.GetInputArray(); using InputArray inputArray2 = y.GetInputArray(); using OutputArray outputArray = magnitude.GetOutputArray(); cudaMagnitudeSqr(inputArray, inputArray2, outputArray, stream); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cudaMagnitudeSqr(IntPtr x, IntPtr y, IntPtr magnitude, IntPtr stream); public static void Phase(IInputArray x, IInputArray y, IOutputArray angle, bool angleInDegrees = false, Stream stream = null) { using InputArray inputArray = x.GetInputArray(); using InputArray inputArray2 = y.GetInputArray(); using OutputArray outputArray = angle.GetOutputArray(); cudaPhase(inputArray, inputArray2, outputArray, angleInDegrees, stream); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cudaPhase(IntPtr x, IntPtr y, IntPtr angle, [MarshalAs(UnmanagedType.U1)] bool angleInDegrees, IntPtr stream); public static void CartToPolar(IInputArray x, IInputArray y, IOutputArray magnitude, IOutputArray angle, bool angleInDegrees = false, Stream stream = null) { using InputArray inputArray = x.GetInputArray(); using InputArray inputArray2 = y.GetInputArray(); using OutputArray outputArray = magnitude.GetOutputArray(); using OutputArray outputArray2 = angle.GetOutputArray(); cudaCartToPolar(inputArray, inputArray2, outputArray, outputArray2, angleInDegrees, stream); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cudaCartToPolar(IntPtr x, IntPtr y, IntPtr magnitude, IntPtr angle, [MarshalAs(UnmanagedType.U1)] bool angleInDegrees, IntPtr stream); public static void PolarToCart(IInputArray magnitude, IInputArray angle, IOutputArray x, IOutputArray y, bool angleInDegrees = false, Stream stream = null) { using InputArray inputArray = magnitude.GetInputArray(); using InputArray inputArray2 = angle.GetInputArray(); using OutputArray outputArray = x.GetOutputArray(); using OutputArray outputArray2 = y.GetOutputArray(); cudaPolarToCart(inputArray, inputArray2, outputArray, outputArray2, angleInDegrees, stream); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cudaPolarToCart(IntPtr magnitude, IntPtr angle, IntPtr x, IntPtr y, [MarshalAs(UnmanagedType.U1)] bool angleInDegrees, IntPtr stream); public static void MinMaxLoc(IInputArray gpuMat, ref double minVal, ref double maxVal, ref Point minLoc, ref Point maxLoc, IInputArray mask = null) { using InputArray inputArray = gpuMat.GetInputArray(); using InputArray inputArray2 = ((mask == null) ? InputArray.GetEmpty() : mask.GetInputArray()); cudaMinMaxLoc(inputArray, ref minVal, ref maxVal, ref minLoc, ref maxLoc, inputArray2); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cudaMinMaxLoc(IntPtr gpuMat, ref double minVal, ref double maxVal, ref Point minLoc, ref Point maxLoc, IntPtr mask); public static void FindMinMaxLoc(IInputArray src, IOutputArray minMaxVals, IOutputArray loc, IInputArray mask = null, Stream stream = null) { using InputArray inputArray = src.GetInputArray(); using OutputArray outputArray = minMaxVals.GetOutputArray(); using OutputArray outputArray2 = loc.GetOutputArray(); using InputArray inputArray2 = ((mask == null) ? InputArray.GetEmpty() : mask.GetInputArray()); cudaFindMinMaxLoc(inputArray, outputArray, outputArray2, inputArray2, stream); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cudaFindMinMaxLoc(IntPtr src, IntPtr minMaxVals, IntPtr loc, IntPtr mask, IntPtr stream); public static void PyrDown(IInputArray src, IOutputArray dst, Stream stream = null) { using InputArray inputArray = src.GetInputArray(); using OutputArray outputArray = dst.GetOutputArray(); cudaPyrDown(inputArray, outputArray, stream); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cudaPyrDown(IntPtr src, IntPtr dst, IntPtr stream); public static void PyrUp(IInputArray src, IOutputArray dst, Stream stream = null) { using InputArray inputArray = src.GetInputArray(); using OutputArray outputArray = dst.GetOutputArray(); cudaPyrUp(inputArray, outputArray, stream); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cudaPyrUp(IntPtr src, IntPtr dst, IntPtr stream); public static void MeanStdDev(IInputArray mtx, ref MCvScalar mean, ref MCvScalar stddev) { using InputArray inputArray = mtx.GetInputArray(); cudaMeanStdDev(inputArray, ref mean, ref stddev); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cudaMeanStdDev(IntPtr mtx, ref MCvScalar mean, ref MCvScalar stddev); public static double Norm(IInputArray src1, IInputArray src2, NormType normType = NormType.L2) { using InputArray inputArray = src1.GetInputArray(); using InputArray inputArray2 = ((src2 == null) ? InputArray.GetEmpty() : src2.GetInputArray()); return cudaNorm2(inputArray, inputArray2, normType); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern double cudaNorm2(IntPtr src1, IntPtr src2, NormType normType); public static double Norm(IInputArray src, NormType normType, IInputArray mask = null) { using InputArray inputArray = src.GetInputArray(); using InputArray inputArray2 = ((mask == null) ? InputArray.GetEmpty() : mask.GetInputArray()); return cudaNorm1(inputArray, normType, inputArray2); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern double cudaNorm1(IntPtr src1, NormType normType, IntPtr mask); public static void CalcNorm(IInputArray src, IOutputArray dst, NormType normType = NormType.L2, IInputArray mask = null, Stream stream = null) { using InputArray inputArray = src.GetInputArray(); using OutputArray outputArray = dst.GetOutputArray(); using InputArray inputArray2 = ((mask == null) ? InputArray.GetEmpty() : mask.GetInputArray()); cudaCalcNorm(inputArray, outputArray, normType, inputArray2, stream); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cudaCalcNorm(IntPtr src, IntPtr dst, NormType normType, IntPtr mask, IntPtr stream); public static void CalcNormDiff(IInputArray src1, IInputArray src2, IOutputArray dst, NormType normType = NormType.L2, Stream stream = null) { using InputArray inputArray = src1.GetInputArray(); using InputArray inputArray2 = src2.GetInputArray(); using OutputArray outputArray = dst.GetOutputArray(); cudaCalcNormDiff(inputArray, inputArray2, outputArray, normType, stream); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cudaCalcNormDiff(IntPtr src1, IntPtr src2, IntPtr dst, NormType normType, IntPtr stream); public static MCvScalar AbsSum(IInputArray src, IInputArray mask = null) { MCvScalar sum = default(MCvScalar); using InputArray inputArray = src.GetInputArray(); using InputArray inputArray2 = ((mask == null) ? InputArray.GetEmpty() : mask.GetInputArray()); cudaAbsSum(inputArray, ref sum, inputArray2); return sum; } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cudaAbsSum(IntPtr src, ref MCvScalar sum, IntPtr mask); public static void CalcAbsSum(IInputArray src, IOutputArray dst, IInputArray mask = null, Stream stream = null) { using InputArray inputArray = src.GetInputArray(); using OutputArray outputArray = dst.GetOutputArray(); using InputArray inputArray2 = ((mask == null) ? InputArray.GetEmpty() : mask.GetInputArray()); cudaCalcAbsSum(inputArray, outputArray, inputArray2, stream); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cudaCalcAbsSum(IntPtr src, IntPtr dst, IntPtr mask, IntPtr stream); public static MCvScalar SqrSum(IInputArray src, IInputArray mask = null) { MCvScalar sqrSum = default(MCvScalar); using InputArray inputArray = src.GetInputArray(); using InputArray inputArray2 = ((mask == null) ? InputArray.GetEmpty() : mask.GetInputArray()); cudaSqrSum(inputArray, ref sqrSum, inputArray2); return sqrSum; } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cudaSqrSum(IntPtr src, ref MCvScalar sqrSum, IntPtr mask); public static void CalcSqrSum(IInputArray src, IOutputArray dst, IInputArray mask = null, Stream stream = null) { using InputArray inputArray = src.GetInputArray(); using OutputArray outputArray = dst.GetOutputArray(); using InputArray inputArray2 = ((mask == null) ? InputArray.GetEmpty() : mask.GetInputArray()); cudaCalcSqrSum(inputArray, outputArray, inputArray2, stream); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cudaCalcSqrSum(IntPtr src, IntPtr dst, IntPtr mask, IntPtr stream); public static int CountNonZero(IInputArray src) { using InputArray inputArray = src.GetInputArray(); return cudaCountNonZero1(inputArray); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern int cudaCountNonZero1(IntPtr src); public static void CountNonZero(IInputArray src, IOutputArray dst, Stream stream = null) { using InputArray inputArray = src.GetInputArray(); using OutputArray outputArray = dst.GetOutputArray(); cudaCountNonZero2(inputArray, outputArray, stream); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cudaCountNonZero2(IntPtr src, IntPtr dst, IntPtr stream); public static void Normalize(IInputArray src, IOutputArray dst, double alpha, double beta, NormType normType, DepthType depthType, IInputArray mask = null, Stream stream = null) { using InputArray inputArray = src.GetInputArray(); using OutputArray outputArray = dst.GetOutputArray(); using InputArray inputArray2 = ((mask == null) ? InputArray.GetEmpty() : mask.GetInputArray()); cudaNormalize(inputArray, outputArray, alpha, beta, normType, depthType, inputArray2, stream); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cudaNormalize(IntPtr src, IntPtr dst, double alpha, double beta, NormType normType, DepthType dtype, IntPtr mask, IntPtr stream); public static void Reduce(IInputArray mtx, IOutputArray vec, ReduceDimension dim, ReduceType reduceOp, DepthType dType = DepthType.Default, Stream stream = null) { using InputArray inputArray = mtx.GetInputArray(); using OutputArray outputArray = vec.GetOutputArray(); cudaReduce(inputArray, outputArray, dim, reduceOp, dType, stream); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cudaReduce(IntPtr mtx, IntPtr vec, ReduceDimension dim, ReduceType reduceOp, DepthType dType, IntPtr stream); public static void Flip(IInputArray src, IOutputArray dst, FlipType flipType, Stream stream = null) { using InputArray inputArray = src.GetInputArray(); using OutputArray outputArray = dst.GetOutputArray(); cudaFlip(inputArray, outputArray, flipType, stream); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cudaFlip(IntPtr src, IntPtr dst, FlipType flipMode, IntPtr stream); public static void BitwiseXor(IInputArray src1, IInputArray src2, IOutputArray dst, IInputArray mask = null, Stream stream = null) { using InputArray inputArray = src1.GetInputArray(); using InputArray inputArray2 = src2.GetInputArray(); using OutputArray outputArray = dst.GetOutputArray(); using InputArray inputArray3 = ((mask == null) ? InputArray.GetEmpty() : mask.GetInputArray()); cudaBitwiseXor(inputArray, inputArray2, outputArray, inputArray3, stream); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cudaBitwiseXor(IntPtr src1, IntPtr src2, IntPtr dst, IntPtr mask, IntPtr stream); public static void BitwiseOr(IInputArray src1, IInputArray src2, IOutputArray dst, IInputArray mask = null, Stream stream = null) { using InputArray inputArray = src1.GetInputArray(); using InputArray inputArray2 = src2.GetInputArray(); using OutputArray outputArray = dst.GetOutputArray(); using InputArray inputArray3 = ((mask == null) ? InputArray.GetEmpty() : mask.GetInputArray()); cudaBitwiseOr(inputArray, inputArray2, outputArray, inputArray3, stream); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cudaBitwiseOr(IntPtr src1, IntPtr src2, IntPtr dst, IntPtr mask, IntPtr stream); public static void BitwiseAnd(IInputArray src1, IInputArray src2, IOutputArray dst, IInputArray mask = null, Stream stream = null) { using InputArray inputArray = src1.GetInputArray(); using InputArray inputArray2 = src2.GetInputArray(); using OutputArray outputArray = dst.GetOutputArray(); using InputArray inputArray3 = ((mask == null) ? InputArray.GetEmpty() : mask.GetInputArray()); cudaBitwiseAnd(inputArray, inputArray2, outputArray, inputArray3, stream); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cudaBitwiseAnd(IntPtr src1, IntPtr src2, IntPtr dst, IntPtr mask, IntPtr stream); public static void BitwiseNot(IInputArray src, IOutputArray dst, IInputArray mask = null, Stream stream = null) { using InputArray inputArray = src.GetInputArray(); using OutputArray outputArray = dst.GetOutputArray(); using InputArray inputArray2 = ((mask == null) ? InputArray.GetEmpty() : mask.GetInputArray()); cudaBitwiseNot(inputArray, outputArray, inputArray2, stream); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cudaBitwiseNot(IntPtr src, IntPtr dst, IntPtr mask, IntPtr stream); public static void Min(IInputArray src1, IInputArray src2, IOutputArray dst, Stream stream = null) { using InputArray inputArray = src1.GetInputArray(); using InputArray inputArray2 = src2.GetInputArray(); using OutputArray outputArray = dst.GetOutputArray(); cudaMin(inputArray, inputArray2, outputArray, stream); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cudaMin(IntPtr src1, IntPtr src2, IntPtr dst, IntPtr stream); public static void Max(IInputArray src1, IInputArray src2, IOutputArray dst, Stream stream = null) { using InputArray inputArray = src1.GetInputArray(); using InputArray inputArray2 = src2.GetInputArray(); using OutputArray outputArray = dst.GetOutputArray(); cudaMax(inputArray, inputArray2, outputArray, stream); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cudaMax(IntPtr src1, IntPtr src2, IntPtr dst, IntPtr stream); public static double Threshold(IInputArray src, IOutputArray dst, double threshold, double maxValue, ThresholdType thresholdType, Stream stream = null) { using InputArray inputArray = src.GetInputArray(); using OutputArray outputArray = dst.GetOutputArray(); return cudaThreshold(inputArray, outputArray, threshold, maxValue, thresholdType, stream); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern double cudaThreshold(IntPtr src, IntPtr dst, double threshold, double maxValue, ThresholdType thresholdType, IntPtr stream); public static void Gemm(IInputArray src1, IInputArray src2, double alpha, IInputArray src3, double beta, IOutputArray dst, GemmType tABC = GemmType.Default, Stream stream = null) { using InputArray inputArray = src1.GetInputArray(); using InputArray inputArray2 = src2.GetInputArray(); using InputArray inputArray3 = ((src3 == null) ? InputArray.GetEmpty() : src3.GetInputArray()); using OutputArray outputArray = dst.GetOutputArray(); cudaGemm(inputArray, inputArray2, alpha, inputArray3, beta, outputArray, tABC, stream); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cudaGemm(IntPtr src1, IntPtr src2, double alpha, IntPtr src3, double beta, IntPtr dst, GemmType tABC, IntPtr stream); public static void WarpAffine(IInputArray src, IOutputArray dst, IInputArray M, Size dSize, Inter flags = Inter.Linear, BorderType borderMode = BorderType.Constant, MCvScalar borderValue = default(MCvScalar), Stream stream = null) { using InputArray inputArray = src.GetInputArray(); using OutputArray outputArray = dst.GetOutputArray(); using InputArray inputArray2 = M.GetInputArray(); cudaWarpAffine(inputArray, outputArray, inputArray2, ref dSize, flags, borderMode, ref borderValue, stream); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cudaWarpAffine(IntPtr src, IntPtr dst, IntPtr M, ref Size dSize, Inter flags, BorderType borderMode, ref MCvScalar borderValue, IntPtr stream); public static void WarpPerspective(IInputArray src, IOutputArray dst, IInputArray M, Size dSize, Inter flags = Inter.Linear, BorderType borderMode = BorderType.Constant, MCvScalar borderValue = default(MCvScalar), Stream stream = null) { using InputArray inputArray = src.GetInputArray(); using OutputArray outputArray = dst.GetOutputArray(); using InputArray inputArray2 = M.GetInputArray(); cudaWarpPerspective(inputArray, outputArray, inputArray2, ref dSize, flags, borderMode, ref borderValue, stream); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cudaWarpPerspective(IntPtr src, IntPtr dst, IntPtr M, ref Size dSize, Inter flags, BorderType borderMode, ref MCvScalar borderValue, IntPtr stream); public static void Remap(IInputArray src, IOutputArray dst, IInputArray xmap, IInputArray ymap, Inter interpolation, BorderType borderMode = BorderType.Constant, MCvScalar borderValue = default(MCvScalar), Stream stream = null) { using InputArray inputArray = src.GetInputArray(); using OutputArray outputArray = dst.GetOutputArray(); using InputArray inputArray2 = xmap.GetInputArray(); using InputArray inputArray3 = ymap.GetInputArray(); cudaRemap(inputArray, outputArray, inputArray2, inputArray3, interpolation, borderMode, ref borderValue, stream); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cudaRemap(IntPtr src, IntPtr dst, IntPtr xmap, IntPtr ymap, Inter interpolation, BorderType borderMode, ref MCvScalar borderValue, IntPtr stream); public static void Rotate(IInputArray src, IOutputArray dst, Size dSize, double angle, double xShift = 0.0, double yShift = 0.0, Inter interpolation = Inter.Linear, Stream stream = null) { using InputArray inputArray = src.GetInputArray(); using OutputArray outputArray = dst.GetOutputArray(); cudaRotate(inputArray, outputArray, ref dSize, angle, xShift, yShift, interpolation, stream); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cudaRotate(IntPtr src, IntPtr dst, ref Size dSize, double angle, double xShift, double yShift, Inter interpolation, IntPtr stream); public static void CopyMakeBorder(IInputArray src, IOutputArray dst, int top, int bottom, int left, int right, BorderType borderType, MCvScalar value = default(MCvScalar), Stream stream = null) { using InputArray inputArray = src.GetInputArray(); using OutputArray outputArray = dst.GetOutputArray(); cudaCopyMakeBorder(inputArray, outputArray, top, bottom, left, right, borderType, ref value, stream); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cudaCopyMakeBorder(IntPtr src, IntPtr dst, int top, int bottom, int left, int right, BorderType borderType, ref MCvScalar value, IntPtr stream); public static void Integral(IInputArray src, IOutputArray sum, Stream stream = null) { using InputArray inputArray = src.GetInputArray(); using OutputArray outputArray = sum.GetOutputArray(); cudaIntegral(inputArray, outputArray, stream); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cudaIntegral(IntPtr src, IntPtr sum, IntPtr stream); public static void SqrIntegral(IInputArray src, IOutputArray sqsum, Stream stream = null) { using InputArray inputArray = src.GetInputArray(); using OutputArray outputArray = sqsum.GetOutputArray(); cudaSqrIntegral(inputArray, outputArray, stream); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cudaSqrIntegral(IntPtr src, IntPtr sqsum, IntPtr stream); public static void Dft(IInputArray src, IOutputArray dst, Size dftSize, DxtType flags = DxtType.Forward, Stream stream = null) { using InputArray inputArray = src.GetInputArray(); using OutputArray outputArray = dst.GetOutputArray(); cudaDft(inputArray, outputArray, ref dftSize, flags, stream); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cudaDft(IntPtr src, IntPtr dst, ref Size dftSize, DxtType flags, IntPtr stream); public static void MulAndScaleSpectrums(IInputArray src1, IInputArray src2, IOutputArray dst, int flags, float scale, bool conjB = false, Stream stream = null) { using InputArray inputArray = src1.GetInputArray(); using InputArray inputArray2 = src2.GetInputArray(); using OutputArray outputArray = dst.GetOutputArray(); cudaMulAndScaleSpectrums(inputArray, inputArray2, outputArray, flags, scale, conjB, stream); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cudaMulAndScaleSpectrums(IntPtr src1, IntPtr src2, IntPtr dst, int flags, float scale, [MarshalAs(UnmanagedType.U1)] bool conjB, IntPtr stream); public static void MulSpectrums(IInputArray src1, IInputArray src2, IOutputArray dst, int flags, bool conjB = false, Stream stream = null) { using InputArray inputArray = src1.GetInputArray(); using InputArray inputArray2 = src2.GetInputArray(); using OutputArray outputArray = dst.GetOutputArray(); cudaMulSpectrums(inputArray, inputArray2, outputArray, flags, conjB, stream); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cudaMulSpectrums(IntPtr src1, IntPtr src2, IntPtr dst, int flags, [MarshalAs(UnmanagedType.U1)] bool conjB, IntPtr stream); public static void SetGlDevice(int device = 0) { cudaSetGlDevice(device); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cudaSetGlDevice(int device); public static void DrawColorDisp(IInputArray srcDisp, IOutputArray dstDisp, int ndisp, Stream stream = null) { using InputArray inputArray = srcDisp.GetInputArray(); using OutputArray outputArray = dstDisp.GetOutputArray(); cudaDrawColorDisp(inputArray, outputArray, ndisp, stream); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cudaDrawColorDisp(IntPtr srcDisp, IntPtr dstDisp, int ndisp, IntPtr stream); public static void ConvertFp16(IInputArray src, IOutputArray dst, Stream stream = null) { using InputArray inputArray = src.GetInputArray(); using OutputArray outputArray = dst.GetOutputArray(); cudaConvertFp16(inputArray, outputArray, stream); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cudaConvertFp16(IntPtr src, IntPtr dst, IntPtr stream); public static void InRange(IInputArray src, MCvScalar lowerb, MCvScalar upperb, IOutputArray dst, Stream stream = null) { using InputArray inputArray = src.GetInputArray(); using OutputArray outputArray = dst.GetOutputArray(); cudaInRange(inputArray, ref lowerb, ref upperb, outputArray, stream); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cudaInRange(IntPtr src, ref MCvScalar lowerb, ref MCvScalar upperb, IntPtr dst, IntPtr stream); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cudaLookUpTableCreate(IntPtr lut, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cudaLookUpTableTransform(IntPtr lut, IntPtr image, IntPtr dst, IntPtr stream); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cudaLookUpTableRelease(ref IntPtr lut); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveInputArrayFromGpuMat(IntPtr mat); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveOutputArrayFromGpuMat(IntPtr mat); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveInputOutputArrayFromGpuMat(IntPtr mat); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void gpuMatRelease(ref IntPtr mat); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr gpuMatCreateDefault(); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr gpuMatCreateFromInputArray(IntPtr arr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void gpuMatGetSize(IntPtr gpuMat, ref Size size); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int gpuMatGetType(IntPtr gpuMat); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void gpuMatCreate(IntPtr mat, int rows, int cols, int type); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr gpuMatCreateContinuous(int rows, int cols, int type); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void gpuMatSetTo(IntPtr mat, ref MCvScalar value, IntPtr mask, IntPtr stream); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void gpuMatUpload(IntPtr gpuMat, IntPtr arr, IntPtr stream); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void gpuMatDownload(IntPtr gpuMat, IntPtr arr, IntPtr stream); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void gpuMatCopyTo(IntPtr src, IntPtr dst, IntPtr mask, IntPtr stream); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void gpuMatConvertTo(IntPtr src, IntPtr dst, DepthType rtype, double scale, double shift, IntPtr stream); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void gpuMatReshape(IntPtr src, IntPtr dst, int newCn, int newRows); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.U1)] internal static extern bool cveGpuMatIsContinuous(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern DepthType cveGpuMatDepth(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.U1)] internal static extern bool cveGpuMatIsEmpty(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int cveGpuMatNumberOfChannels(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr streamCreate(); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr streamCreateWithFlag(int flag); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void streamRelease(ref IntPtr stream); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void streamWaitForCompletion(IntPtr stream); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.U1)] internal static extern bool streamQueryIfComplete(IntPtr stream); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cudaBackgroundSubtractorMOGCreate(int history, int nMixtures, double backgroundRatio, double noiseSigma, ref IntPtr bgSubtractor, ref IntPtr algorithm, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cudaBackgroundSubtractorMOGApply(IntPtr mog, IntPtr frame, IntPtr fgMask, double learningRate, IntPtr stream); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cudaBackgroundSubtractorMOGRelease(ref IntPtr mog); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cudaBackgroundSubtractorMOG2Create(int history, double varThreshold, [MarshalAs(UnmanagedType.U1)] bool detectShadows, ref IntPtr bgSubtractor, ref IntPtr algorithm, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cudaBackgroundSubtractorMOG2Apply(IntPtr mog, IntPtr frame, IntPtr fgMask, double learningRate, IntPtr stream); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cudaBackgroundSubtractorMOG2Release(ref IntPtr mog); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cudaCreateBoxFilter(int srcType, int dstType, ref Size ksize, ref Point anchor, BorderType borderMode, ref MCvScalar borderValue, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cudaCreateBoxMaxFilter(int srcType, ref Size ksize, ref Point anchor, BorderType borderMode, ref MCvScalar borderValue, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cudaCreateBoxMinFilter(int srcType, ref Size ksize, ref Point anchor, BorderType borderMode, ref MCvScalar borderValue, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cudaCreateColumnSumFilter(int srcType, int dstType, int ksize, int anchor, BorderType borderMode, ref MCvScalar borderVal, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cudaCreateDerivFilter(int srcType, int dstType, int dx, int dy, int ksize, [MarshalAs(UnmanagedType.U1)] bool normalize, double scale, BorderType rowBorderMode, BorderType columnBorderMode, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cudaFilterApply(IntPtr filter, IntPtr image, IntPtr dst, IntPtr stream); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cudaFilterRelease(ref IntPtr filter); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cudaCreateGaussianFilter(int srcType, int dstType, ref Size ksize, double sigma1, double sigma2, int rowBorderType, int columnBorderType, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cudaCreateLaplacianFilter(int srcType, int dstType, int ksize, double scale, BorderType borderMode, ref MCvScalar borderValue, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cudaCreateLinearFilter(int srcType, int dstType, IntPtr kernel, ref Point anchor, BorderType borderMode, ref MCvScalar borderValue, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cudaCreateMedianFilter(int srcType, int windowSize, int partition, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cudaCreateMorphologyFilter(MorphOp op, int srcType, IntPtr kernel, ref Point anchor, int iterations, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cudaCreateRowSumFilter(int srcType, int dstType, int ksize, int anchor, BorderType borderMode, ref MCvScalar borderVal, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cudaCreateScharrFilter(int srcType, int dstType, int dx, int dy, double scale, BorderType rowBorderMode, BorderType columnBorderMode, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cudaCreateSeparableLinearFilter(int srcType, int dstType, IntPtr rowKernel, IntPtr columnKernel, ref Point anchor, BorderType rowBorderMode, BorderType columnBorderMode, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cudaCreateSobelFilter(int srcType, int dstType, int dx, int dy, int ksize, double scale, BorderType rowBorderType, BorderType columnBorderType, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cudaCreateCannyEdgeDetector(double lowThreshold, double highThreshold, int apertureSize, [MarshalAs(UnmanagedType.U1)] bool L2gradient, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cudaCannyEdgeDetectorDetect(IntPtr detector, IntPtr src, IntPtr edges, IntPtr stream); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cudaCannyEdgeDetectorRelease(ref IntPtr detector); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cudaCLAHECreate(double clipLimit, ref Size tileGridSize, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cudaCLAHEApply(IntPtr clahe, IntPtr src, IntPtr dst, IntPtr stream); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cudaCLAHERelease(ref IntPtr clahe); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cudaCornernessCriteriaCompute(IntPtr detector, IntPtr src, IntPtr dst, IntPtr stream); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cudaCornernessCriteriaRelease(ref IntPtr detector); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cudaGoodFeaturesToTrackDetectorCreate(int srcType, int maxCorners, double qualityLevel, double minDistance, int blockSize, [MarshalAs(UnmanagedType.U1)] bool useHarrisDetector, double harrisK, ref IntPtr _sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cudaCornersDetectorDetect(IntPtr detector, IntPtr image, IntPtr corners, IntPtr mask, IntPtr stream); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cudaCornersDetectorRelease(ref IntPtr detector); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cudaCreateHarrisCorner(int srcType, int blockSize, int ksize, double k, BorderType borderType, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cudaHoughCirclesDetectorCreate(float dp, float minDist, int cannyThreshold, int votesThreshold, int minRadius, int maxRadius, int maxCircles, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cudaHoughCirclesDetectorDetect(IntPtr detector, IntPtr src, IntPtr circles, IntPtr stream); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cudaHoughCirclesDetectorRelease(ref IntPtr detector); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cudaHoughLinesDetectorCreate(float rho, float theta, int threshold, [MarshalAs(UnmanagedType.U1)] bool doSort, int maxLines, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cudaHoughLinesDetectorDetect(IntPtr detector, IntPtr src, IntPtr lines, IntPtr stream); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cudaHoughLinesDetectorRelease(ref IntPtr detector); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern float cveCudaHoughLinesDetectorGetRho(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveCudaHoughLinesDetectorSetRho(IntPtr obj, float val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern float cveCudaHoughLinesDetectorGetTheta(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveCudaHoughLinesDetectorSetTheta(IntPtr obj, float val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int cveCudaHoughLinesDetectorGetThreshold(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveCudaHoughLinesDetectorSetThreshold(IntPtr obj, int val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.U1)] internal static extern bool cveCudaHoughLinesDetectorGetDoSort(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveCudaHoughLinesDetectorSetDoSort(IntPtr obj, [MarshalAs(UnmanagedType.U1)] bool val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int cveCudaHoughLinesDetectorGetMaxLines(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveCudaHoughLinesDetectorSetMaxLines(IntPtr obj, int val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cudaHoughSegmentDetectorCreate(float rho, float theta, int minLineLength, int maxLineGap, int maxLines, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cudaHoughSegmentDetectorDetect(IntPtr detector, IntPtr src, IntPtr lines, IntPtr stream); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cudaHoughSegmentDetectorRelease(ref IntPtr detector); public static void CvtColor(IInputArray src, IOutputArray dst, ColorConversion code, int dcn = 0, Stream stream = null) { using InputArray inputArray = src.GetInputArray(); using OutputArray outputArray = dst.GetOutputArray(); cudaCvtColor(inputArray, outputArray, code, dcn, stream); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cudaCvtColor(IntPtr src, IntPtr dst, ColorConversion code, int dcn, IntPtr stream); public static void Demosaicing(IInputArray src, IOutputArray dst, DemosaicTypes code, int dcn = -1, Stream stream = null) { using InputArray inputArray = src.GetInputArray(); using OutputArray outputArray = dst.GetOutputArray(); cudaDemosaicing(inputArray, outputArray, code, dcn, stream); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cudaDemosaicing(IntPtr src, IntPtr dst, DemosaicTypes code, int dcn, IntPtr stream); public static void SwapChannels(IInputOutputArray src, int[] dstOrder, Stream stream) { if (dstOrder == null || dstOrder.Length < 4) { throw new ArgumentException("dstOrder must be an int array of size 4"); } GCHandle gCHandle = GCHandle.Alloc(dstOrder, GCHandleType.Pinned); using (InputOutputArray inputOutputArray = src.GetInputOutputArray()) { cudaSwapChannels(inputOutputArray, gCHandle.AddrOfPinnedObject(), stream); } gCHandle.Free(); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cudaSwapChannels(IntPtr src, IntPtr dstOrder, IntPtr stream); public static void GammaCorrection(IInputArray src, IOutputArray dst, bool forward = true, Stream stream = null) { using InputArray inputArray = src.GetInputArray(); using OutputArray outputArray = dst.GetOutputArray(); cudaGammaCorrection(inputArray, outputArray, forward, stream); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cudaGammaCorrection(IntPtr src, IntPtr dst, [MarshalAs(UnmanagedType.U1)] bool forward, IntPtr stream); public static void AlphaComp(IInputArray img1, IInputArray img2, IOutputArray dst, AlphaCompTypes alphaOp, Stream stream = null) { using InputArray inputArray = img1.GetInputArray(); using InputArray inputArray2 = img2.GetInputArray(); using OutputArray outputArray = dst.GetOutputArray(); cudaAlphaComp(inputArray, inputArray2, outputArray, alphaOp, stream); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cudaAlphaComp(IntPtr img1, IntPtr img2, IntPtr dst, AlphaCompTypes alphaOp, IntPtr stream); public static void CalcHist(IInputArray src, IOutputArray hist, Stream stream = null) { using InputArray inputArray = src.GetInputArray(); using OutputArray outputArray = hist.GetOutputArray(); cudaCalcHist(inputArray, outputArray, stream); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cudaCalcHist(IntPtr src, IntPtr hist, IntPtr stream); public static void EqualizeHist(IInputArray src, IOutputArray dst, Stream stream = null) { using InputArray inputArray = src.GetInputArray(); using OutputArray outputArray = dst.GetOutputArray(); cudaEqualizeHist(inputArray, outputArray, stream); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cudaEqualizeHist(IntPtr src, IntPtr dst, IntPtr stream); public static void HistEven(IInputArray src, IOutputArray hist, int histSize, int lowerLevel, int upperLevel, Stream stream = null) { using InputArray inputArray = src.GetInputArray(); using OutputArray outputArray = hist.GetOutputArray(); cudaHistEven(inputArray, outputArray, histSize, lowerLevel, upperLevel, stream); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cudaHistEven(IntPtr src, IntPtr hist, int histSize, int lowerLevel, int upperLevel, IntPtr stream); public static void HistRange(IInputArray src, IOutputArray hist, IInputArray levels, Stream stream = null) { using InputArray inputArray = src.GetInputArray(); using OutputArray outputArray = hist.GetOutputArray(); using InputArray inputArray2 = levels.GetInputArray(); cudaHistRange(inputArray, outputArray, inputArray2, stream); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cudaHistRange(IntPtr src, IntPtr hist, IntPtr levels, IntPtr stream); public static void BlendLinear(IInputArray img1, IInputArray img2, IInputArray weights1, IInputArray weights2, IOutputArray result, Stream stream = null) { using InputArray inputArray = img1.GetInputArray(); using InputArray inputArray2 = img2.GetInputArray(); using InputArray inputArray3 = weights1.GetInputArray(); using InputArray inputArray4 = weights2.GetInputArray(); using OutputArray outputArray = result.GetOutputArray(); cudaBlendLinear(inputArray, inputArray2, inputArray3, inputArray4, outputArray, stream); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cudaBlendLinear(IntPtr img1, IntPtr img2, IntPtr weights1, IntPtr weights2, IntPtr result, IntPtr stream); public static void BilateralFilter(IInputArray src, IOutputArray dst, int kernelSize, float sigmaColor, float sigmaSpatial, BorderType borderType = BorderType.Reflect101, Stream stream = null) { using InputArray inputArray = src.GetInputArray(); using OutputArray outputArray = dst.GetOutputArray(); cudaBilateralFilter(inputArray, outputArray, kernelSize, sigmaColor, sigmaSpatial, borderType, stream); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cudaBilateralFilter(IntPtr src, IntPtr dst, int kernelSize, float sigmaColor, float sigmaSpatial, BorderType borderType, IntPtr stream); public static void MeanShiftFiltering(IInputArray src, IOutputArray dst, int sp, int sr, MCvTermCriteria criteria, Stream stream = null) { using InputArray inputArray = src.GetInputArray(); using OutputArray outputArray = dst.GetOutputArray(); cudaMeanShiftFiltering(inputArray, outputArray, sp, sr, ref criteria, stream); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cudaMeanShiftFiltering(IntPtr src, IntPtr dst, int sp, int sr, ref MCvTermCriteria criteria, IntPtr stream); public static void MeanShiftProc(IInputArray src, IOutputArray dstr, IOutputArray dstsp, int sp, int sr, MCvTermCriteria criteria, Stream stream = null) { using InputArray inputArray = src.GetInputArray(); using OutputArray outputArray = dstr.GetOutputArray(); using OutputArray outputArray2 = dstsp.GetOutputArray(); cudaMeanShiftProc(inputArray, outputArray, outputArray2, sp, sr, ref criteria, stream); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cudaMeanShiftProc(IntPtr src, IntPtr dstr, IntPtr dstsp, int sp, int sr, ref MCvTermCriteria criteria, IntPtr stream); public static void MeanShiftSegmentation(IInputArray src, IOutputArray dst, int sp, int sr, int minSize, MCvTermCriteria criteria, Stream stream) { using InputArray inputArray = src.GetInputArray(); using OutputArray outputArray = dst.GetOutputArray(); cudaMeanShiftSegmentation(inputArray, outputArray, sp, sr, minSize, ref criteria, stream); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cudaMeanShiftSegmentation(IntPtr src, IntPtr dst, int sp, int sr, int minsize, ref MCvTermCriteria criteria, IntPtr stream); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cudaCreateMinEigenValCorner(int srcType, int blockSize, int ksize, BorderType borderType, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cudaTemplateMatchingCreate(int srcType, TemplateMatchingType method, ref Size blockSize, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cudaTemplateMatchingRelease(ref IntPtr buf); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cudaTemplateMatchingMatch(IntPtr tm, IntPtr image, IntPtr templ, IntPtr result, IntPtr stream); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cudaBroxOpticalFlowCreate(double alpha, double gamma, double scaleFactor, int innerIterations, int outerIterations, int solverIterations, ref IntPtr denseFlow, ref IntPtr algorithm, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cudaBroxOpticalFlowRelease(ref IntPtr flow); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cudaDensePyrLKOpticalFlowCreate(ref Size winSize, int maxLevel, int iters, [MarshalAs(UnmanagedType.U1)] bool useInitialFlow, ref IntPtr denseFlow, ref IntPtr algorithm, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cudaDensePyrLKOpticalFlowRelease(ref IntPtr flow); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cudaFarnebackOpticalFlowCreate(int numLevels, double pyrScale, [MarshalAs(UnmanagedType.U1)] bool fastPyramids, int winSize, int numIters, int polyN, double polySigma, OpticalflowFarnebackFlag flags, ref IntPtr denseFlow, ref IntPtr algorithm, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cudaFarnebackOpticalFlowRelease(ref IntPtr flow); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cudaOpticalFlowDualTvl1Create(double tau, double lambda, double theta, int nscales, int warps, double epsilon, int iterations, double scaleStep, double gamma, [MarshalAs(UnmanagedType.U1)] bool useInitialFlow, ref IntPtr denseFlow, ref IntPtr algorithm, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cudaOpticalFlowDualTvl1Release(ref IntPtr flow); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cudaSparsePyrLKOpticalFlowCreate(ref Size winSize, int maxLevel, int iters, [MarshalAs(UnmanagedType.U1)] bool useInitialFlow, ref IntPtr sparseFlow, ref IntPtr algorithm, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cudaSparsePyrLKOpticalFlowRelease(ref IntPtr flow); public static void Calc(this ICudaDenseOpticalFlow denseFlow, IInputArray i0, IInputArray i1, IInputOutputArray flow, Stream stream = null) { using InputArray inputArray = i0.GetInputArray(); using InputArray inputArray2 = i1.GetInputArray(); using InputOutputArray inputOutputArray = flow.GetInputOutputArray(); cudaDenseOpticalFlowCalc(denseFlow.DenseOpticalFlowPtr, inputArray, inputArray2, inputOutputArray, stream?.Ptr ?? IntPtr.Zero); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cudaDenseOpticalFlowCalc(IntPtr opticalFlow, IntPtr i0, IntPtr i1, IntPtr flow, IntPtr stream); public static void Calc(this ICudaSparseOpticalFlow sparseFlow, IInputArray prevImg, IInputArray nextImg, IInputArray prevPts, IInputOutputArray nextPts, IOutputArray status, IOutputArray err = null, Stream stream = null) { using InputArray inputArray = prevImg.GetInputArray(); using InputArray inputArray2 = nextImg.GetInputArray(); using InputArray inputArray3 = prevPts.GetInputArray(); using InputOutputArray inputOutputArray = nextPts.GetInputOutputArray(); using OutputArray outputArray = status.GetOutputArray(); using OutputArray outputArray2 = ((err == null) ? OutputArray.GetEmpty() : err.GetOutputArray()); cudaSparseOpticalFlowCalc(sparseFlow.SparseOpticalFlowPtr, inputArray, inputArray2, inputArray3, inputOutputArray, outputArray, outputArray2, stream?.Ptr ?? IntPtr.Zero); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cudaSparseOpticalFlowCalc(IntPtr opticalFlow, IntPtr prevImg, IntPtr nextImg, IntPtr prevPts, IntPtr nextPts, IntPtr status, IntPtr err, IntPtr stream); public static void Calc(this INvidiaOpticalFlow nvidiaOpticalFlow, IInputArray inputImage, IInputArray referenceImage, IInputOutputArray flow, Stream stream = null, IInputArray hint = null, IOutputArray cost = null) { using InputArray inputArray = inputImage.GetInputArray(); using InputArray inputArray2 = referenceImage.GetInputArray(); using InputOutputArray inputOutputArray = flow.GetInputOutputArray(); using InputArray inputArray3 = ((hint == null) ? InputArray.GetEmpty() : hint.GetInputArray()); using OutputArray outputArray = ((cost == null) ? OutputArray.GetEmpty() : cost.GetOutputArray()); cudaNvidiaOpticalFlowCalc(nvidiaOpticalFlow.NvidiaOpticalFlowPtr, inputArray, inputArray2, inputOutputArray, stream?.Ptr ?? IntPtr.Zero, inputArray3, outputArray); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cudaNvidiaOpticalFlowCalc(IntPtr nHWOpticalFlow, IntPtr inputImage, IntPtr referenceImage, IntPtr flow, IntPtr stream, IntPtr hint, IntPtr cost); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cudaNvidiaOpticalFlow_1_0_Create(ref Size imageSize, NvidiaOpticalFlow_1_0.PerfLevel perfPreset, [MarshalAs(UnmanagedType.U1)] bool enableTemporalHints, [MarshalAs(UnmanagedType.U1)] bool enableExternalHints, [MarshalAs(UnmanagedType.U1)] bool enableCostBuffer, int gpuId, IntPtr inputStream, IntPtr outputStream, ref IntPtr nHWOpticalFlow, ref IntPtr algorithm, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cudaNvidiaOpticalFlow_1_0_UpSampler(IntPtr nFlow, IntPtr flow, ref Size imageSize, int gridSize, IntPtr upsampledFlow); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cudaNvidiaOpticalFlow_1_0_Release(ref IntPtr flow); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cudaNvidiaOpticalFlow_2_0_Create(ref Size imageSize, NvidiaOpticalFlow_2_0.PerfLevel perfPreset, NvidiaOpticalFlow_2_0.OutputVectorGridSize outputVectorGridSize, NvidiaOpticalFlow_2_0.HintVectorGridSize hintVectorGridSize, [MarshalAs(UnmanagedType.U1)] bool enableTemporalHints, [MarshalAs(UnmanagedType.U1)] bool enableExternalHints, [MarshalAs(UnmanagedType.U1)] bool enableCostBuffer, int gpuId, IntPtr inputStream, IntPtr outputStream, ref IntPtr nHWOpticalFlow, ref IntPtr algorithm, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cudaNvidiaOpticalFlow_2_0_ConvertToFloat(IntPtr novf, IntPtr flow, IntPtr floatFlow); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cudaNvidiaOpticalFlow_2_0_Release(ref IntPtr flow); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveCudaDescriptorMatcherCreateBFMatcher(DistanceType distType, ref IntPtr algorithm, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveCudaDescriptorMatcherRelease(ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveCudaDescriptorMatcherAdd(IntPtr matcher, IntPtr trainDescs); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.U1)] internal static extern bool cveCudaDescriptorMatcherIsMaskSupported(IntPtr matcher); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveCudaDescriptorMatcherClear(IntPtr matcher); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.U1)] internal static extern bool cveCudaDescriptorMatcherEmpty(IntPtr matcher); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveCudaDescriptorMatcherTrain(IntPtr matcher); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveCudaDescriptorMatcherMatch1(IntPtr matcher, IntPtr queryDescriptors, IntPtr trainDescriptors, IntPtr matches, IntPtr mask); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveCudaDescriptorMatcherMatch2(IntPtr matcher, IntPtr queryDescriptors, IntPtr matches, IntPtr masks); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveCudaDescriptorMatcherMatchAsync1(IntPtr matcher, IntPtr queryDescriptors, IntPtr trainDescriptors, IntPtr matches, IntPtr mask, IntPtr stream); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveCudaDescriptorMatcherMatchAsync2(IntPtr matcher, IntPtr queryDescriptors, IntPtr matches, IntPtr masks, IntPtr stream); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveCudaDescriptorMatcherMatchConvert(IntPtr matcher, IntPtr gpuMatches, IntPtr matches); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveCudaDescriptorMatcherKnnMatch1(IntPtr matcher, IntPtr queryDescs, IntPtr trainDescs, IntPtr matches, int k, IntPtr masks, [MarshalAs(UnmanagedType.U1)] bool compactResult); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveCudaDescriptorMatcherKnnMatch2(IntPtr matcher, IntPtr queryDescriptors, IntPtr matches, int k, IntPtr masks, [MarshalAs(UnmanagedType.U1)] bool compactResult); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveCudaDescriptorMatcherKnnMatchAsync1(IntPtr matcher, IntPtr queryDescriptors, IntPtr trainDescriptors, IntPtr matches, int k, IntPtr mask, IntPtr stream); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveCudaDescriptorMatcherKnnMatchAsync2(IntPtr matcher, IntPtr queryDescriptors, IntPtr matches, int k, IntPtr masks, IntPtr stream); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveCudaDescriptorMatcherKnnMatchConvert(IntPtr matcher, IntPtr gpuMatches, IntPtr matches, [MarshalAs(UnmanagedType.U1)] bool compactResult); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveCudaDescriptorMatcherRadiusMatch1(IntPtr matcher, IntPtr queryDescriptors, IntPtr trainDescriptors, IntPtr matches, float maxDistance, IntPtr mask, [MarshalAs(UnmanagedType.U1)] bool compactResult); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveCudaDescriptorMatcherRadiusMatch2(IntPtr matcher, IntPtr queryDescriptors, IntPtr matches, float maxDistance, IntPtr masks, [MarshalAs(UnmanagedType.U1)] bool compactResult); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveCudaDescriptorMatcherRadiusMatchAsync1(IntPtr matcher, IntPtr queryDescriptors, IntPtr trainDescriptors, IntPtr matches, float maxDistance, IntPtr mask, IntPtr stream); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveCudaDescriptorMatcherRadiusMatchAsync2(IntPtr matcher, IntPtr queryDescriptors, IntPtr matches, float maxDistance, IntPtr masks, IntPtr stream); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveCudaDescriptorMatcherRadiusMatchConvert(IntPtr matcher, IntPtr gpuMatches, IntPtr matches, [MarshalAs(UnmanagedType.U1)] bool compactResult); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveCudaFastFeatureDetectorCreate(int threshold, [MarshalAs(UnmanagedType.U1)] bool nonmaxSupression, FastFeatureDetector.DetectorType type, int maxPoints, ref IntPtr feature2D, ref IntPtr feature2DAsync, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveCudaFastFeatureDetectorRelease(ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveCudaORBCreate(int numberOfFeatures, float scaleFactor, int nLevels, int edgeThreshold, int firstLevel, int WTA_K, ORB.ScoreType scoreType, int patchSize, int fastThreshold, [MarshalAs(UnmanagedType.U1)] bool blurForDescriptor, ref IntPtr feature2D, ref IntPtr feature2DAsync, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveCudaORBRelease(ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveCudaFeature2dAsyncDetectAsync(IntPtr feature2d, IntPtr image, IntPtr keypoints, IntPtr mask, IntPtr stream); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveCudaFeature2dAsyncComputeAsync(IntPtr feature2d, IntPtr image, IntPtr keypoints, IntPtr descriptors, IntPtr stream); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveCudaFeature2dAsyncDetectAndComputeAsync(IntPtr feature2d, IntPtr image, IntPtr mask, IntPtr keypoints, IntPtr descriptors, [MarshalAs(UnmanagedType.U1)] bool useProvidedKeypoints, IntPtr stream); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveCudaFeature2dAsyncConvert(IntPtr feature2d, IntPtr gpuKeypoints, IntPtr keypoints); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cudaDisparityBilateralFilterCreate(int ndisp, int radius, int iters, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cudaDisparityBilateralFilterApply(IntPtr filter, IntPtr disparity, IntPtr image, IntPtr dst, IntPtr stream); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cudaDisparityBilateralFilterRelease(ref IntPtr filter); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cudaStereoBMCreate(int ndisparities, int blockSize, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cudaStereoBMFindStereoCorrespondence(IntPtr stereoBM, IntPtr left, IntPtr right, IntPtr disparity, IntPtr stream); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cudaStereoBMRelease(ref IntPtr stereoBM); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cudaStereoConstantSpaceBPCreate(int ndisp, int iters, int levels, int nr_plane, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cudaStereoConstantSpaceBPFindStereoCorrespondence(IntPtr stereoBM, IntPtr left, IntPtr right, IntPtr disparity, IntPtr stream); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cudaStereoConstantSpaceBPRelease(ref IntPtr stereoBM); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cudaCascadeClassifierCreate(IntPtr filename, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cudaCascadeClassifierCreateFromFileStorage(IntPtr filestorage, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cudaCascadeClassifierRelease(ref IntPtr classified); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int cudaCascadeClassifierDetectMultiScale(IntPtr classifier, IntPtr image, IntPtr objects, IntPtr stream); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cudaCascadeClassifierConvert(IntPtr classifier, IntPtr gpuObjects, IntPtr objects); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern double cveCudaCascadeClassifierGetScaleFactor(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveCudaCascadeClassifierSetScaleFactor(IntPtr obj, double val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int cveCudaCascadeClassifierGetMinNeighbors(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveCudaCascadeClassifierSetMinNeighbors(IntPtr obj, int val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int cveCudaCascadeClassifierGetMaxNumObjects(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveCudaCascadeClassifierSetMaxNumObjects(IntPtr obj, int val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.U1)] internal static extern bool cveCudaCascadeClassifierGetFindLargestObject(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveCudaCascadeClassifierSetFindLargestObject(IntPtr obj, [MarshalAs(UnmanagedType.U1)] bool val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveCudaCascadeClassifierGetMaxObjectSize(IntPtr obj, ref Size val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveCudaCascadeClassifierSetMaxObjectSize(IntPtr obj, ref Size val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveCudaCascadeClassifierGetMinObjectSize(IntPtr obj, ref Size val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveCudaCascadeClassifierSetMinObjectSize(IntPtr obj, ref Size val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveCudaCascadeClassifierGetClassifierSize(IntPtr obj, ref Size val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cudaHOGGetDefaultPeopleDetector(IntPtr hog, IntPtr detector); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cudaHOGCreate(ref Size winSize, ref Size blockSize, ref Size blockStride, ref Size cellSize, int nbins, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cudaHOGRelease(ref IntPtr descriptor); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cudaHOGSetSVMDetector(IntPtr descriptor, IntPtr svmDetector); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cudaHOGDetectMultiScale(IntPtr descriptor, IntPtr img, IntPtr foundLocations, IntPtr confidents); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.U1)] internal static extern bool cveCudaHOGGetGammaCorrection(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveCudaHOGSetGammaCorrection(IntPtr obj, [MarshalAs(UnmanagedType.U1)] bool val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern double cveCudaHOGGetWinSigma(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveCudaHOGSetWinSigma(IntPtr obj, double val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int cveCudaHOGGetNumLevels(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveCudaHOGSetNumLevels(IntPtr obj, int val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int cveCudaHOGGetGroupThreshold(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveCudaHOGSetGroupThreshold(IntPtr obj, int val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern double cveCudaHOGGetHitThreshold(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveCudaHOGSetHitThreshold(IntPtr obj, double val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern double cveCudaHOGGetScaleFactor(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveCudaHOGSetScaleFactor(IntPtr obj, double val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern double cveCudaHOGGetL2HysThreshold(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveCudaHOGSetL2HysThreshold(IntPtr obj, double val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern CudaHOG.DescrFormat cveCudaHOGGetDescriptorFormat(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveCudaHOGGetDescriptorSize(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveCudaHOGGetWinStride(IntPtr obj, ref Size val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveCudaHOGSetWinStride(IntPtr obj, ref Size val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveCudaHOGGetBlockHistogramSize(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cudaVideoReaderCreate(IntPtr fileName, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cudaVideoReaderRelease(ref IntPtr reader); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.U1)] internal static extern bool cudaVideoReaderNextFrame(IntPtr reader, IntPtr frame, IntPtr stream); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cudaVideoReaderFormat(IntPtr reader, ref CudaVideoReader.FormatInfo formatInfo); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cudaVideoWriterCreate(IntPtr fileName, ref Size frameSize, double fps, CudaVideoWriter.SurfaceFormat format, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cudaVideoWriterRelease(ref IntPtr writer); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cudaVideoWriterWrite(IntPtr writer, IntPtr frame, [MarshalAs(UnmanagedType.U1)] bool lastFrame); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cudaBackgroundSubtractorFGDCreate(int Lc, int N1c, int N2c, int Lcc, int N1cc, int N2cc, [MarshalAs(UnmanagedType.U1)] bool isObjWithoutHoles, int performMorphing, float alpha1, float alpha2, float alpha3, float delta, float T, float minArea, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cudaBackgroundSubtractorFGDApply(IntPtr fgd, IntPtr frame, IntPtr fgMask, double learningRate); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cudaBackgroundSubtractorFGDRelease(ref IntPtr fgd); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cudaBackgroundSubtractorGMGCreate(int initializationFrames, double decisionThreshold, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cudaBackgroundSubtractorGMGApply(IntPtr gmg, IntPtr frame, IntPtr fgMask, double learningRate, IntPtr stream); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cudaBackgroundSubtractorGMGRelease(ref IntPtr gmg); public static void NonLocalMeans(IInputArray src, IOutputArray dst, float h, int searchWindow = 21, int blockSize = 7, BorderType borderMode = BorderType.Reflect101, Stream stream = null) { using InputArray inputArray = src.GetInputArray(); using OutputArray outputArray = dst.GetOutputArray(); cudaNonLocalMeans(inputArray, outputArray, h, searchWindow, blockSize, borderMode, stream); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cudaNonLocalMeans(IntPtr src, IntPtr dst, float h, int searchWindow, int blockSize, BorderType borderMode, IntPtr stream); public static void FastNlMeansDenoising(IInputArray src, IOutputArray dst, float h, int searchWindow = 21, int blockSize = 7, Stream stream = null) { using InputArray inputArray = src.GetInputArray(); using OutputArray outputArray = dst.GetOutputArray(); cudaFastNlMeansDenoising(inputArray, outputArray, h, searchWindow, blockSize, stream); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cudaFastNlMeansDenoising(IntPtr src, IntPtr dst, float h, int searchWindow, int blockSize, IntPtr stream); public static void FastNlMeansDenoisingColored(IInputArray src, IOutputArray dst, float hLuminance, float photoRender, int searchWindow = 21, int blockSize = 7, Stream stream = null) { using InputArray inputArray = src.GetInputArray(); using OutputArray outputArray = dst.GetOutputArray(); cudaFastNlMeansDenoisingColored(inputArray, outputArray, hLuminance, photoRender, searchWindow, blockSize, stream); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cudaFastNlMeansDenoisingColored(IntPtr src, IntPtr dst, float hLuminance, float photoRender, int searchWindow, int blockSize, IntPtr stream); } public class CudaDeviceInfo : UnmanagedObject { public enum GpuFeature { Compute10 = 10, Compute11 = 11, Compute12 = 12, Compute13 = 13, Compute20 = 20, Compute21 = 21, Compute30 = 30, Compute32 = 32, Compute35 = 35, Compute50 = 50, GlobalAtomics = 11, SharedAtomics = 12, NativeDouble = 13, WarpShuffleFunctions = 30, DynamicParallelism = 35 } private int _deviceID; public int ID => _deviceID; public string Name { get { StringBuilder stringBuilder = new StringBuilder(1024); CudaInvoke.cudaDeviceInfoDeviceName(_ptr, stringBuilder, 1024); return stringBuilder.ToString(); } } public Version CudaComputeCapability { get { int major = 0; int minor = 0; CudaInvoke.cudaDeviceInfoComputeCapability(_ptr, ref major, ref minor); return new Version(major, minor); } } public int MultiProcessorCount => CudaInvoke.cudaDeviceInfoMultiProcessorCount(_ptr); public ulong FreeMemory { get { UIntPtr free = default(UIntPtr); CudaInvoke.cudaDeviceInfoFreeMemInfo(_ptr, ref free); return free.ToUInt64(); } } public ulong TotalMemory { get { UIntPtr total = default(UIntPtr); CudaInvoke.cudaDeviceInfoTotalMemInfo(_ptr, ref total); return total.ToUInt64(); } } public bool IsCompatible => CudaInvoke.cudaDeviceInfoIsCompatible(_ptr); public CudaDeviceInfo() : this(CudaInvoke.GetDevice()) { } public CudaDeviceInfo(int deviceId) { _ptr = CudaInvoke.cudaDeviceInfoCreate(ref deviceId); _deviceID = deviceId; } public bool Supports(GpuFeature feature) { return CudaInvoke.cudaDeviceInfoSupports(_ptr, feature); } protected override void DisposeObject() { CudaInvoke.cudaDeviceInfoRelease(ref _ptr); } } public class CudaImage : GpuMat where TColor : struct, IColor where TDepth : new() { public CudaImage() { } internal CudaImage(IntPtr ptr, bool needDispose) : base(ptr, needDispose) { } public CudaImage(IInputArray img) : base(img) { } public CudaImage(int rows, int cols, bool continuous) : base(rows, cols, new TColor().Dimension, continuous) { } public CudaImage(int rows, int cols) : base(rows, cols, new TColor().Dimension, continuous: false) { } public CudaImage(Size size) : this(size.Height, size.Width) { } public CudaImage(CudaImage image, Emgu.CV.Structure.Range rowRange, Emgu.CV.Structure.Range colRange) : this(CudaInvoke.GetRegion(image, ref rowRange, ref colRange), needDispose: true) { } public Image ToImage() { Image image = new Image(base.Size); Download(image); return image; } public CudaImage Convert() where TOtherColor : struct, IColor where TOtherDepth : new() { CudaImage cudaImage = new CudaImage(base.Size); cudaImage.ConvertFrom(this); return cudaImage; } public void ConvertFrom(CudaImage srcImage) where TSrcColor : struct, IColor where TSrcDepth : new() { if (!base.Size.Equals((object?)srcImage.Size)) { using (CudaImage srcImage2 = srcImage.Resize(base.Size, Inter.Linear)) { ConvertFrom(srcImage2); return; } } if (typeof(TColor) == typeof(TSrcColor)) { if (typeof(TDepth) == typeof(TSrcDepth)) { srcImage.CopyTo(this); } else if (typeof(TDepth) == typeof(byte) && typeof(TSrcDepth) != typeof(byte)) { srcImage.MinMax(out var minValues, out var maxValues, out var _, out var _); double num = minValues[0]; double num2 = maxValues[0]; for (int i = 1; i < minValues.Length; i++) { num = Math.Min(num, minValues[i]); num2 = Math.Max(num2, maxValues[i]); } double num3 = 1.0; double shift = 0.0; if (num2 > 255.0 || num < 0.0) { num3 = ((num2 == num) ? 0.0 : (255.0 / (num2 - num))); shift = ((num3 == 0.0) ? num : ((0.0 - num) * num3)); } srcImage.ConvertTo(this, CvInvoke.GetDepthType(typeof(TDepth)), num3, shift); } else { srcImage.ConvertTo(this, CvInvoke.GetDepthType(typeof(TDepth))); } return; } if (typeof(TDepth) == typeof(TSrcDepth)) { ConvertColor(srcImage, this, typeof(TSrcColor), typeof(TColor), base.NumberOfChannels, base.Size, null); return; } using CudaImage src = srcImage.Convert(); ConvertColor(src, this, typeof(TSrcColor), typeof(TColor), base.NumberOfChannels, base.Size, null); } private static void ConvertColor(IInputArray src, IOutputArray dest, Type srcColor, Type destColor, int dcn, Size size, Stream stream) { try { CudaInvoke.CvtColor(src, dest, CvToolbox.GetColorCvtCode(srcColor, destColor), dcn, stream); } catch { try { using CudaImage cudaImage = new CudaImage(size); CudaInvoke.CvtColor(src, cudaImage, CvToolbox.GetColorCvtCode(srcColor, typeof(Bgr)), 3, stream); CudaInvoke.CvtColor(cudaImage, dest, CvToolbox.GetColorCvtCode(typeof(Bgr), destColor), dcn, stream); stream.WaitForCompletion(); } catch (Exception ex) { throw new NotSupportedException($"Conversion from CudaImage<{srcColor.ToString()}, {typeof(TDepth).ToString()}> to CudaImage<{destColor.ToString()}, {typeof(TDepth).ToString()}> is not supported by OpenCV: {ex.Message}"); } } } public CudaImage Clone(Stream stream) { CudaImage cudaImage = new CudaImage(base.Size); CopyTo(cudaImage, null, stream); return cudaImage; } public CudaImage Resize(Size size, Inter interpolationType, Stream stream = null) { CudaImage cudaImage = new CudaImage(size); CudaInvoke.Resize(this, cudaImage, size, 0.0, 0.0, interpolationType, stream); return cudaImage; } public new CudaImage GetSubRect(Rectangle region) { return new CudaImage(CudaInvoke.GetSubRect(this, ref region), needDispose: true); } public new CudaImage Row(int i) { return RowRange(i, i + 1); } public new CudaImage RowRange(int start, int end) { return new CudaImage(this, new Emgu.CV.Structure.Range(start, end), Emgu.CV.Structure.Range.All); } public new CudaImage Col(int i) { return ColRange(i, i + 1); } public new CudaImage ColRange(int start, int end) { return new CudaImage(this, Emgu.CV.Structure.Range.All, new Emgu.CV.Structure.Range(start, end)); } } public class CudaLookUpTable : SharedPtrObject { public CudaLookUpTable(IInputArray lookUpTable) { using InputArray inputArray = lookUpTable.GetInputArray(); _ptr = CudaInvoke.cudaLookUpTableCreate(inputArray, ref _sharedPtr); } public void Transform(IInputArray image, IOutputArray dst, Stream stream = null) { using InputArray inputArray = image.GetInputArray(); using OutputArray outputArray = dst.GetOutputArray(); CudaInvoke.cudaLookUpTableTransform(_ptr, inputArray, outputArray, stream); } protected override void DisposeObject() { if (_sharedPtr != IntPtr.Zero) { CudaInvoke.cudaLookUpTableRelease(ref _sharedPtr); _ptr = IntPtr.Zero; } } } [DebuggerTypeProxy(typeof(DebuggerProxy))] public class GpuMat : UnmanagedObject, IEquatable, IInputOutputArray, IInputArray, IDisposable, IOutputArray, IInputArrayOfArrays, IOutputArrayOfArrays { internal class DebuggerProxy { private GpuMat _v; public Mat Mat { get { Mat mat = new Mat(); _v.Download(mat); return mat; } } public DebuggerProxy(GpuMat v) { _v = v; } } internal bool _needDispose; public Size Size { get { Size size = default(Size); CudaInvoke.gpuMatGetSize(_ptr, ref size); return size; } } public int Type => CudaInvoke.gpuMatGetType(_ptr); public bool IsContinuous => CudaInvoke.cveGpuMatIsContinuous(_ptr); public DepthType Depth => CudaInvoke.cveGpuMatDepth(_ptr); public bool IsEmpty => CudaInvoke.cveGpuMatIsEmpty(_ptr); public int NumberOfChannels => CudaInvoke.cveGpuMatNumberOfChannels(_ptr); public GpuMat() : this(CudaInvoke.gpuMatCreateDefault(), needDispose: true) { } public GpuMat(int rows, int cols, DepthType depthType, int channels, bool continuous = false) : this(continuous ? CudaInvoke.gpuMatCreateContinuous(rows, cols, CvInvoke.MakeType(depthType, channels)) : CudaInvoke.gpuMatCreateDefault(), needDispose: true) { if (!continuous) { Create(rows, cols, depthType, channels); } } public void Create(int rows, int cols, DepthType depthType, int channels) { CudaInvoke.gpuMatCreate(base.Ptr, rows, cols, CvInvoke.MakeType(depthType, channels)); } internal GpuMat(IntPtr ptr, bool needDispose) { _ptr = ptr; _needDispose = needDispose; } public GpuMat(IInputArray arr) : this() { Upload(arr); } public GpuMat(GpuMat mat, Emgu.CV.Structure.Range rowRange, Emgu.CV.Structure.Range colRange) : this(CudaInvoke.GetRegion(mat, ref rowRange, ref colRange), needDispose: true) { } protected override void DisposeObject() { if (_needDispose && _ptr != IntPtr.Zero) { CudaInvoke.gpuMatRelease(ref _ptr); } } public InputArray GetInputArray() { return new InputArray(CudaInvoke.cveInputArrayFromGpuMat(_ptr), this); } public OutputArray GetOutputArray() { return new OutputArray(CudaInvoke.cveOutputArrayFromGpuMat(_ptr), this); } public InputOutputArray GetInputOutputArray() { return new InputOutputArray(CudaInvoke.cveInputOutputArrayFromGpuMat(_ptr), this); } public void Upload(IInputArray arr, Stream stream = null) { using InputArray inputArray = arr.GetInputArray(); CudaInvoke.gpuMatUpload(_ptr, inputArray, stream); } public void Download(IOutputArray arr, Stream stream = null) { using OutputArray outputArray = arr.GetOutputArray(); CudaInvoke.gpuMatDownload(_ptr, outputArray, stream); } public Mat ToMat() { Mat mat = new Mat(); Download(mat); return mat; } public Array GetData(bool jagged = true) { if (IsEmpty) { return null; } using Mat mat = new Mat(); Download(mat); return mat.GetData(jagged); } public void SetTo(MCvScalar value, IInputArray mask = null, Stream stream = null) { using InputArray inputArray = ((mask == null) ? InputArray.GetEmpty() : mask.GetInputArray()); CudaInvoke.gpuMatSetTo(base.Ptr, ref value, inputArray, stream); } public void CopyTo(IOutputArray dst, IInputArray mask = null, Stream stream = null) { using OutputArray outputArray = dst.GetOutputArray(); using InputArray inputArray = ((mask == null) ? InputArray.GetEmpty() : mask.GetInputArray()); CudaInvoke.gpuMatCopyTo(base.Ptr, outputArray, inputArray, stream); } public void ConvertTo(IOutputArray dst, DepthType rtype, double scale = 1.0, double shift = 0.0, Stream stream = null) { using OutputArray outputArray = dst.GetOutputArray(); CudaInvoke.gpuMatConvertTo(base.Ptr, outputArray, rtype, scale, shift, stream); } public GpuMat Reshape(int newCn, int newRows = 0) { GpuMat gpuMat = new GpuMat(); CudaInvoke.gpuMatReshape(base.Ptr, gpuMat, newCn, newRows); return gpuMat; } public GpuMat Row(int i) { return RowRange(i, i + 1); } public GpuMat RowRange(int start, int end) { return new GpuMat(this, new Emgu.CV.Structure.Range(start, end), Emgu.CV.Structure.Range.All); } public GpuMat Col(int i) { return ColRange(i, i + 1); } public GpuMat ColRange(int start, int end) { return new GpuMat(this, Emgu.CV.Structure.Range.All, new Emgu.CV.Structure.Range(start, end)); } public bool Equals(GpuMat other) { if (IsEmpty) { if (!other.IsEmpty) { return false; } } else if (other.IsEmpty) { return false; } if (NumberOfChannels != other.NumberOfChannels || Size != other.Size || Type != other.Type) { return false; } _ = Size; using GpuMat gpuMat = new GpuMat(); CudaInvoke.BitwiseXor(this, other, gpuMat); if (gpuMat.NumberOfChannels == 1) { return CudaInvoke.CountNonZero(gpuMat) == 0; } using GpuMat src = gpuMat.Reshape(1); return CudaInvoke.CountNonZero(src) == 0; } public void MergeFrom(GpuMat[] gpuMats, Stream stream = null) { if (gpuMats.Length == 1) { gpuMats[0].CopyTo(this, null, stream); } using VectorOfGpuMat srcArr = new VectorOfGpuMat(gpuMats); CudaInvoke.Merge(srcArr, this, stream); } private void SplitInto(GpuMat[] gpuMats, Stream stream) { if (NumberOfChannels == 1) { CopyTo(gpuMats[0], null, stream); return; } Size size = Size; for (int i = 0; i < gpuMats.Length; i++) { gpuMats[i].Create(size.Height, size.Width, Depth, 1); } using VectorOfGpuMat dstArray = new VectorOfGpuMat(gpuMats); CudaInvoke.Split(this, dstArray, stream); } public GpuMat[] Split(Stream stream = null) { GpuMat[] array = new GpuMat[NumberOfChannels]; _ = Size; for (int i = 0; i < array.Length; i++) { array[i] = new GpuMat(); } SplitInto(array, stream); return array; } public void MinMax(out double[] minValues, out double[] maxValues, out Point[] minLocations, out Point[] maxLocations) { minValues = new double[NumberOfChannels]; maxValues = new double[NumberOfChannels]; minLocations = new Point[NumberOfChannels]; maxLocations = new Point[NumberOfChannels]; double minVal = 0.0; double maxVal = 0.0; Point minLoc = default(Point); Point maxLoc = default(Point); if (NumberOfChannels == 1) { CudaInvoke.MinMaxLoc(this, ref minVal, ref maxVal, ref minLoc, ref maxLoc); minValues[0] = minVal; maxValues[0] = maxVal; minLocations[0] = minLoc; maxLocations[0] = maxLoc; return; } GpuMat[] array = Split(); try { for (int i = 0; i < NumberOfChannels; i++) { CudaInvoke.MinMaxLoc(array[i], ref minVal, ref maxVal, ref minLoc, ref maxLoc); minValues[i] = minVal; maxValues[i] = maxVal; minLocations[i] = minLoc; maxLocations[i] = maxLoc; } } finally { GpuMat[] array2 = array; for (int j = 0; j < array2.Length; j++) { array2[j].Dispose(); } } } public void Save(string fileName) { CvInvoke.Imwrite(fileName, this); } public object Clone() { GpuMat gpuMat = new GpuMat(); CopyTo(gpuMat); return gpuMat; } } public class GpuMat : GpuMat where TDepth : new() { internal GpuMat(IntPtr ptr, bool needDispose) : base(ptr, needDispose) { } public GpuMat() { } public GpuMat(IInputArray arr) : base(arr) { } public GpuMat(int rows, int cols, int channels, bool continuous = false) : base(rows, cols, CvInvoke.GetDepthType(typeof(TDepth)), channels, continuous) { } public GpuMat(Size size, int channels) : this(size.Height, size.Width, channels, continuous: false) { } public Matrix ToMatrix() { Size size = base.Size; Matrix matrix = new Matrix(size.Height, size.Width, base.NumberOfChannels); Download(matrix); return matrix; } public GpuMat GetSubRect(Rectangle region) { return new GpuMat(CudaInvoke.GetSubRect(this, ref region), needDispose: true); } } public class Stream : UnmanagedObject { public bool Completed => CudaInvoke.streamQueryIfComplete(_ptr); public Stream() { _ptr = CudaInvoke.streamCreate(); } public Stream(int flag) { _ptr = CudaInvoke.streamCreateWithFlag(flag); } public void WaitForCompletion() { CudaInvoke.streamWaitForCompletion(_ptr); } protected override void DisposeObject() { IntPtr zero = IntPtr.Zero; if (!zero.Equals((object?)(nint)_ptr)) { CudaInvoke.streamRelease(ref _ptr); } } } public static class TargetArchs { static TargetArchs() { _ = CudaInvoke.HasCuda; } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl, EntryPoint = "targetArchsBuildWith")] [return: MarshalAs(UnmanagedType.U1)] public static extern bool BuildWith(CudaDeviceInfo.GpuFeature featureSet); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl, EntryPoint = "targetArchsHas")] [return: MarshalAs(UnmanagedType.U1)] public static extern bool Has(int major, int minor); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl, EntryPoint = "targetArchsHasPtx")] [return: MarshalAs(UnmanagedType.U1)] public static extern bool HasPtx(int major, int minor); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl, EntryPoint = "targetArchsHasBin")] [return: MarshalAs(UnmanagedType.U1)] public static extern bool HasBin(int major, int minor); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl, EntryPoint = "targetArchsHasEqualOrLessPtx")] [return: MarshalAs(UnmanagedType.U1)] public static extern bool HasEqualOrLessPtx(int major, int minor); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl, EntryPoint = "targetArchsHasEqualOrGreater")] [return: MarshalAs(UnmanagedType.U1)] public static extern bool HasEqualOrGreater(int major, int minor); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl, EntryPoint = "targetArchsHasEqualOrGreaterPtx")] [return: MarshalAs(UnmanagedType.U1)] public static extern bool HasEqualOrGreaterPtx(int major, int minor); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl, EntryPoint = "targetArchsHasEqualOrGreaterBin")] [return: MarshalAs(UnmanagedType.U1)] public static extern bool HasEqualOrGreaterBin(int major, int minor); } [Serializable] [DebuggerTypeProxy(typeof(DebuggerProxy))] public class VectorOfGpuMat : UnmanagedVector, IInputOutputArray, IInputArray, IDisposable, IOutputArray, IInputArrayOfArrays, IOutputArrayOfArrays { internal class DebuggerProxy { private VectorOfGpuMat _v; public GpuMat[] Values { get { GpuMat[] array = new GpuMat[_v.Size]; for (int i = 0; i < array.Length; i++) { array[i] = _v[i]; } return array; } } public DebuggerProxy(VectorOfGpuMat v) { _v = v; } } private readonly bool _needDispose; public override int Size => VectorOfGpuMatGetSize(_ptr); public override IntPtr StartAddress => VectorOfGpuMatGetStartAddress(_ptr); public override long Length => VectorOfGpuMatGetMemorySize(_ptr); public GpuMat this[int index] { get { IntPtr element = IntPtr.Zero; VectorOfGpuMatGetItemPtr(_ptr, index, ref element); return new GpuMat(element, needDispose: false); } } public static int SizeOfItemInBytes => VectorOfGpuMatSizeOfItemInBytes(); static VectorOfGpuMat() { CvInvoke.Init(); } public VectorOfGpuMat() : this(VectorOfGpuMatCreate(), needDispose: true) { } internal VectorOfGpuMat(IntPtr ptr, bool needDispose) { _ptr = ptr; _needDispose = needDispose; } public VectorOfGpuMat(int size) : this(VectorOfGpuMatCreateSize(size), needDispose: true) { } public VectorOfGpuMat(params GpuMat[] values) : this() { Push(values); } public void Clear() { VectorOfGpuMatClear(_ptr); } public void Push(GpuMat value) { VectorOfGpuMatPush(_ptr, value.Ptr); } public void Push(GpuMat[] values) { foreach (GpuMat value in values) { Push(value); } } public void Push(VectorOfGpuMat other) { VectorOfGpuMatPushVector(_ptr, other); } protected override void DisposeObject() { if (_needDispose && _ptr != IntPtr.Zero) { VectorOfGpuMatRelease(ref _ptr); } } public InputArray GetInputArray() { return new InputArray(cveInputArrayFromVectorOfGpuMat(_ptr), this); } public OutputArray GetOutputArray() { return new OutputArray(cveOutputArrayFromVectorOfGpuMat(_ptr), this); } public InputOutputArray GetInputOutputArray() { return new InputOutputArray(cveInputOutputArrayFromVectorOfGpuMat(_ptr), this); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr VectorOfGpuMatCreate(); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr VectorOfGpuMatCreateSize(int size); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfGpuMatRelease(ref IntPtr v); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int VectorOfGpuMatGetSize(IntPtr v); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr VectorOfGpuMatGetStartAddress(IntPtr v); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern long VectorOfGpuMatGetMemorySize(IntPtr v); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfGpuMatPush(IntPtr v, IntPtr value); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfGpuMatPushVector(IntPtr ptr, IntPtr otherPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfGpuMatClear(IntPtr v); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfGpuMatGetItemPtr(IntPtr vec, int index, ref IntPtr element); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int VectorOfGpuMatSizeOfItemInBytes(); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveInputArrayFromVectorOfGpuMat(IntPtr vec); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveOutputArrayFromVectorOfGpuMat(IntPtr vec); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveInputOutputArrayFromVectorOfGpuMat(IntPtr vec); void IDisposable.Dispose() { Dispose(); } } public class CudaBackgroundSubtractorMOG : SharedPtrObject, IBackgroundSubtractor, IAlgorithm { private IntPtr _algorithmPtr; private IntPtr _backgroundSubtractorPtr; public IntPtr AlgorithmPtr => _algorithmPtr; public IntPtr BackgroundSubtractorPtr => _backgroundSubtractorPtr; public CudaBackgroundSubtractorMOG(int history = 200, int nMixtures = 4, double backgroundRatio = 0.7, double noiseSigma = 0.0) { _ptr = CudaInvoke.cudaBackgroundSubtractorMOGCreate(history, nMixtures, backgroundRatio, noiseSigma, ref _backgroundSubtractorPtr, ref _algorithmPtr, ref _sharedPtr); } public void Update(IInputArray frame, IOutputArray foregroundMask, double learningRate, Stream stream = null) { using InputArray inputArray = frame.GetInputArray(); using OutputArray outputArray = foregroundMask.GetOutputArray(); CudaInvoke.cudaBackgroundSubtractorMOGApply(_ptr, inputArray, outputArray, learningRate, stream); } protected override void DisposeObject() { if (IntPtr.Zero != _sharedPtr) { CudaInvoke.cudaBackgroundSubtractorMOGRelease(ref _sharedPtr); _ptr = IntPtr.Zero; } } } public class CudaBackgroundSubtractorMOG2 : SharedPtrObject, IBackgroundSubtractor, IAlgorithm { private IntPtr _algorithmPtr; private IntPtr _backgroundSubtractorPtr; public IntPtr AlgorithmPtr => _algorithmPtr; public IntPtr BackgroundSubtractorPtr => _backgroundSubtractorPtr; public CudaBackgroundSubtractorMOG2(int history = 500, double varThreshold = 16.0, bool detectShadows = true) { _ptr = CudaInvoke.cudaBackgroundSubtractorMOG2Create(history, varThreshold, detectShadows, ref _backgroundSubtractorPtr, ref _algorithmPtr, ref _sharedPtr); } public void Update(IInputArray frame, IOutputArray fgmask, double learningRate, Stream stream = null) { using InputArray inputArray = frame.GetInputArray(); using OutputArray outputArray = fgmask.GetOutputArray(); CudaInvoke.cudaBackgroundSubtractorMOG2Apply(_ptr, inputArray, outputArray, learningRate, stream); } protected override void DisposeObject() { if (IntPtr.Zero != _sharedPtr) { CudaInvoke.cudaBackgroundSubtractorMOG2Release(ref _sharedPtr); _ptr = IntPtr.Zero; } } } public class CudaBoxFilter : CudaFilter { public CudaBoxFilter(DepthType srcDepth, int srcChannels, DepthType dstDepth, int dstChannels, Size ksize, Point anchor, BorderType borderType = BorderType.Reflect101, MCvScalar borderValue = default(MCvScalar)) { _ptr = CudaInvoke.cudaCreateBoxFilter(CvInvoke.MakeType(srcDepth, srcChannels), CvInvoke.MakeType(dstDepth, dstChannels), ref ksize, ref anchor, borderType, ref borderValue, ref _sharedPtr); } } public class CudaBoxMaxFilter : CudaFilter { public CudaBoxMaxFilter(DepthType srcDepth, int srcChannels, Size ksize, Point anchor, BorderType borderType = BorderType.Reflect101, MCvScalar borderValue = default(MCvScalar)) { _ptr = CudaInvoke.cudaCreateBoxMaxFilter(CvInvoke.MakeType(srcDepth, srcChannels), ref ksize, ref anchor, borderType, ref borderValue, ref _sharedPtr); } } public class CudaBoxMinFilter : CudaFilter { public CudaBoxMinFilter(DepthType srcDepth, int srcChannels, Size ksize, Point anchor, BorderType borderType = BorderType.Reflect101, MCvScalar borderValue = default(MCvScalar)) { _ptr = CudaInvoke.cudaCreateBoxMinFilter(CvInvoke.MakeType(srcDepth, srcChannels), ref ksize, ref anchor, borderType, ref borderValue, ref _sharedPtr); } } public class ColumnSumFilter : CudaFilter { public ColumnSumFilter(DepthType srcDepth, int srcChannels, DepthType dstDepth, int dstChannels, int ksize, int anchor = -1, BorderType borderType = BorderType.Reflect101, MCvScalar borderValue = default(MCvScalar)) { _ptr = CudaInvoke.cudaCreateColumnSumFilter(CvInvoke.MakeType(srcDepth, srcChannels), CvInvoke.MakeType(dstDepth, dstChannels), ksize, anchor, borderType, ref borderValue, ref _sharedPtr); } } public class CudaDerivFilter : CudaFilter { public CudaDerivFilter(DepthType srcDepth, int srcChannels, DepthType dstDepth, int dstChannels, int dx, int dy, int ksize, bool normalize = false, double scale = 1.0, BorderType rowBorderType = BorderType.Reflect101, BorderType columnBorderType = BorderType.NegativeOne) { _ptr = CudaInvoke.cudaCreateDerivFilter(CvInvoke.MakeType(srcDepth, srcChannels), CvInvoke.MakeType(dstDepth, dstChannels), dx, dy, ksize, normalize, scale, rowBorderType, columnBorderType, ref _sharedPtr); } } public abstract class CudaFilter : SharedPtrObject { protected override void DisposeObject() { if (_sharedPtr != IntPtr.Zero) { CudaInvoke.cudaFilterRelease(ref _sharedPtr); _ptr = IntPtr.Zero; } } public void Apply(IInputArray image, IOutputArray dst, Stream stream = null) { using InputArray inputArray = image.GetInputArray(); using OutputArray outputArray = dst.GetOutputArray(); CudaInvoke.cudaFilterApply(_ptr, inputArray, outputArray, stream); } } public class CudaGaussianFilter : CudaFilter { public CudaGaussianFilter(DepthType srcDepth, int srcChannels, DepthType dstDepth, int dstChannels, Size ksize, double sigma1, double sigma2 = 0.0, BorderType rowBorderType = BorderType.Reflect101, BorderType columnBorderType = BorderType.NegativeOne) { _ptr = CudaInvoke.cudaCreateGaussianFilter(CvInvoke.MakeType(srcDepth, srcChannels), CvInvoke.MakeType(dstDepth, dstChannels), ref ksize, sigma1, sigma2, (int)rowBorderType, (int)columnBorderType, ref _sharedPtr); } } public class CudaLaplacianFilter : CudaFilter { public CudaLaplacianFilter(DepthType srcDepth, int srcChannels, DepthType dstDepth, int dstChannels, int ksize = 1, double scale = 1.0, BorderType borderType = BorderType.Reflect101, MCvScalar borderValue = default(MCvScalar)) { _ptr = CudaInvoke.cudaCreateLaplacianFilter(CvInvoke.MakeType(srcDepth, srcChannels), CvInvoke.MakeType(dstDepth, dstChannels), ksize, scale, borderType, ref borderValue, ref _sharedPtr); } } public class CudaLinearFilter : CudaFilter { public CudaLinearFilter(DepthType srcDepth, int srcChannels, DepthType dstDepth, int dstChannels, IInputArray kernel, Point anchor, BorderType borderType = BorderType.Reflect101, MCvScalar borderValue = default(MCvScalar)) { using InputArray inputArray = kernel.GetInputArray(); _ptr = CudaInvoke.cudaCreateLinearFilter(CvInvoke.MakeType(srcDepth, srcChannels), CvInvoke.MakeType(dstDepth, dstChannels), inputArray, ref anchor, borderType, ref borderValue, ref _sharedPtr); } } public class MedianFilter : CudaFilter { public MedianFilter(DepthType srcDepth, int srcChannels, int windowSize, int partition = 128) { _ptr = CudaInvoke.cudaCreateMedianFilter(CvInvoke.MakeType(srcDepth, srcChannels), windowSize, partition, ref _sharedPtr); } } public class CudaMorphologyFilter : CudaFilter { public CudaMorphologyFilter(MorphOp op, DepthType srcDepth, int srcChannels, IInputArray kernel, Point anchor, int iterations) { using InputArray inputArray = kernel.GetInputArray(); _ptr = CudaInvoke.cudaCreateMorphologyFilter(op, CvInvoke.MakeType(srcDepth, srcChannels), inputArray, ref anchor, iterations, ref _sharedPtr); } } public class RowSumFilter : CudaFilter { public RowSumFilter(DepthType srcDepth, int srcChannels, DepthType dstDepth, int dstChannels, int ksize, int anchor = -1, BorderType borderType = BorderType.Reflect101, MCvScalar borderValue = default(MCvScalar)) { _ptr = CudaInvoke.cudaCreateRowSumFilter(CvInvoke.MakeType(srcDepth, srcChannels), CvInvoke.MakeType(dstDepth, dstChannels), ksize, anchor, borderType, ref borderValue, ref _sharedPtr); } } public class ScharrFilter : CudaFilter { public ScharrFilter(DepthType srcDepth, int srcChannels, DepthType dstDepth, int dstChannels, int dx, int dy, double scale = 1.0, BorderType rowBorderMode = BorderType.Reflect101, BorderType columnBorderMode = BorderType.NegativeOne) { _ptr = CudaInvoke.cudaCreateScharrFilter(CvInvoke.MakeType(srcDepth, srcChannels), CvInvoke.MakeType(dstDepth, dstChannels), dx, dy, scale, rowBorderMode, columnBorderMode, ref _sharedPtr); } } public class SeparableLinearFilter : CudaFilter { public SeparableLinearFilter(DepthType srcDepth, int srcChannels, DepthType dstDepth, int dstChannels, IInputArray rowKernel, IInputArray columnKernel, Point anchor, BorderType rowBorderType = BorderType.Reflect101, BorderType columnBorderType = BorderType.Reflect101) { using InputArray inputArray = rowKernel.GetInputArray(); using InputArray inputArray2 = columnKernel.GetInputArray(); _ptr = CudaInvoke.cudaCreateSeparableLinearFilter(CvInvoke.MakeType(srcDepth, srcChannels), CvInvoke.MakeType(dstDepth, dstChannels), inputArray, inputArray2, ref anchor, rowBorderType, columnBorderType, ref _sharedPtr); } } public class CudaSobelFilter : CudaFilter { public CudaSobelFilter(DepthType srcDepth, int srcChannels, DepthType dstDepth, int dstChannels, int dx, int dy, int ksize = 3, double scale = 1.0, BorderType rowBorderType = BorderType.Reflect101, BorderType columnBorderType = BorderType.NegativeOne) { _ptr = CudaInvoke.cudaCreateSobelFilter(CvInvoke.MakeType(srcDepth, srcChannels), CvInvoke.MakeType(dstDepth, dstChannels), dx, dy, ksize, scale, rowBorderType, columnBorderType, ref _sharedPtr); } } public class CudaCannyEdgeDetector : SharedPtrObject { public CudaCannyEdgeDetector(double lowThreshold, double highThreshold, int apertureSize = 3, bool L2gradient = false) { _ptr = CudaInvoke.cudaCreateCannyEdgeDetector(lowThreshold, highThreshold, apertureSize, L2gradient, ref _sharedPtr); } public void Detect(IInputArray src, IOutputArray edges, Stream stream = null) { using InputArray inputArray = src.GetInputArray(); using OutputArray outputArray = edges.GetOutputArray(); CudaInvoke.cudaCannyEdgeDetectorDetect(_ptr, inputArray, outputArray, stream); } protected override void DisposeObject() { if (_sharedPtr != IntPtr.Zero) { CudaInvoke.cudaCannyEdgeDetectorRelease(ref _sharedPtr); _ptr = IntPtr.Zero; } } } public class CudaClahe : SharedPtrObject { public CudaClahe(double clipLimit, Size tileGridSize) { _ptr = CudaInvoke.cudaCLAHECreate(clipLimit, ref tileGridSize, ref _sharedPtr); } public void Apply(IInputArray source, IOutputArray dst, Stream stream = null) { using InputArray inputArray = source.GetInputArray(); using OutputArray outputArray = dst.GetOutputArray(); CudaInvoke.cudaCLAHEApply(_ptr, inputArray, outputArray, stream); } protected override void DisposeObject() { if (_sharedPtr != IntPtr.Zero) { CudaInvoke.cudaCLAHERelease(ref _sharedPtr); _ptr = IntPtr.Zero; } } } public abstract class CudaCornernessCriteria : SharedPtrObject { protected override void DisposeObject() { if (_sharedPtr != IntPtr.Zero) { CudaInvoke.cudaCornernessCriteriaRelease(ref _sharedPtr); _ptr = IntPtr.Zero; } } public void Apply(IInputArray image, IOutputArray dst, Stream stream = null) { using InputArray inputArray = image.GetInputArray(); using OutputArray outputArray = dst.GetOutputArray(); CudaInvoke.cudaCornernessCriteriaCompute(base.SharedPtr, inputArray, outputArray, stream); } } public class CudaGoodFeaturesToTrackDetector : SharedPtrObject { public CudaGoodFeaturesToTrackDetector(DepthType srcDepth, int srcChannels, int maxCorners = 1000, double qualityLevel = 0.01, double minDistance = 0.0, int blockSize = 3, bool useHarrisDetector = false, double harrisK = 0.04) { _ptr = CudaInvoke.cudaGoodFeaturesToTrackDetectorCreate(CvInvoke.MakeType(srcDepth, srcChannels), maxCorners, qualityLevel, minDistance, blockSize, useHarrisDetector, harrisK, ref _sharedPtr); } public void Detect(IInputArray image, IOutputArray corners, IInputArray mask = null, Stream stream = null) { using InputArray inputArray = image.GetInputArray(); using OutputArray outputArray = corners.GetOutputArray(); using InputArray inputArray2 = ((mask != null) ? mask.GetInputArray() : InputArray.GetEmpty()); CudaInvoke.cudaCornersDetectorDetect(_ptr, inputArray, outputArray, inputArray2, stream); } protected override void DisposeObject() { if (IntPtr.Zero != _sharedPtr) { CudaInvoke.cudaCornersDetectorRelease(ref _sharedPtr); _ptr = IntPtr.Zero; } } } public class CudaHarrisCorner : CudaCornernessCriteria { public CudaHarrisCorner(DepthType srcDepth, int srcChannels, int blockSize, int kSize, double k, BorderType borderType = BorderType.Reflect101) { _ptr = CudaInvoke.cudaCreateHarrisCorner(CvInvoke.MakeType(srcDepth, srcChannels), blockSize, kSize, k, borderType, ref _sharedPtr); } } public class CudaHoughCirclesDetector : SharedPtrObject { public CudaHoughCirclesDetector(float dp, float minDist, int cannyThreshold, int votesThreshold, int minRadius, int maxRadius, int maxCircles = 4096) { _ptr = CudaInvoke.cudaHoughCirclesDetectorCreate(dp, minDist, cannyThreshold, votesThreshold, minRadius, maxRadius, maxCircles, ref _sharedPtr); } public void Detect(IInputArray image, IOutputArray circles, Stream stream = null) { using InputArray inputArray = image.GetInputArray(); using OutputArray outputArray = circles.GetOutputArray(); CudaInvoke.cudaHoughCirclesDetectorDetect(_ptr, inputArray, outputArray, stream); } public CircleF[] Detect(IInputArray image) { using GpuMat gpuMat = new GpuMat(); using Mat mat = new Mat(); Detect(image, gpuMat); gpuMat.Download(mat); CircleF[] array = new CircleF[mat.Cols]; GCHandle gCHandle = GCHandle.Alloc(array, GCHandleType.Pinned); CvToolbox.Memcpy(gCHandle.AddrOfPinnedObject(), mat.DataPointer, Toolbox.SizeOf() * array.Length); gCHandle.Free(); return array; } protected override void DisposeObject() { if (_sharedPtr != IntPtr.Zero) { CudaInvoke.cudaHoughCirclesDetectorRelease(ref _sharedPtr); _ptr = IntPtr.Zero; } } } public class CudaHoughLinesDetector : SharedPtrObject { public float Rho { get { return CudaInvoke.cveCudaHoughLinesDetectorGetRho(_ptr); } set { CudaInvoke.cveCudaHoughLinesDetectorSetRho(_ptr, value); } } public float Theta { get { return CudaInvoke.cveCudaHoughLinesDetectorGetTheta(_ptr); } set { CudaInvoke.cveCudaHoughLinesDetectorSetTheta(_ptr, value); } } public int Threshold { get { return CudaInvoke.cveCudaHoughLinesDetectorGetThreshold(_ptr); } set { CudaInvoke.cveCudaHoughLinesDetectorSetThreshold(_ptr, value); } } public bool DoSort { get { return CudaInvoke.cveCudaHoughLinesDetectorGetDoSort(_ptr); } set { CudaInvoke.cveCudaHoughLinesDetectorSetDoSort(_ptr, value); } } public int MaxLines { get { return CudaInvoke.cveCudaHoughLinesDetectorGetMaxLines(_ptr); } set { CudaInvoke.cveCudaHoughLinesDetectorSetMaxLines(_ptr, value); } } public CudaHoughLinesDetector(float rho, float theta, int threshold, bool doSort = false, int maxLines = 4096) { _ptr = CudaInvoke.cudaHoughLinesDetectorCreate(rho, theta, threshold, doSort, maxLines, ref _sharedPtr); } public void Detect(IInputArray image, IOutputArray lines, Stream stream = null) { using InputArray inputArray = image.GetInputArray(); using OutputArray outputArray = lines.GetOutputArray(); CudaInvoke.cudaHoughLinesDetectorDetect(_ptr, inputArray, outputArray, stream); } protected override void DisposeObject() { if (IntPtr.Zero != _sharedPtr) { CudaInvoke.cudaHoughLinesDetectorRelease(ref _sharedPtr); _ptr = IntPtr.Zero; } } } public class CudaHoughSegmentDetector : SharedPtrObject { public CudaHoughSegmentDetector(float rho, float theta, int minLineLength, int maxLineGap, int maxLines = 4096) { _ptr = CudaInvoke.cudaHoughSegmentDetectorCreate(rho, theta, minLineLength, maxLineGap, maxLines, ref _sharedPtr); } public void Detect(IInputArray image, IOutputArray lines, Stream stream = null) { using InputArray inputArray = image.GetInputArray(); using OutputArray outputArray = lines.GetOutputArray(); CudaInvoke.cudaHoughSegmentDetectorDetect(_ptr, inputArray, outputArray, stream); } protected override void DisposeObject() { if (IntPtr.Zero != _sharedPtr) { CudaInvoke.cudaHoughSegmentDetectorRelease(ref _sharedPtr); _ptr = IntPtr.Zero; } } } public enum DemosaicTypes { BayerBG2BGR_MHT = 256, BayerGB2BGR_MHT = 257, BayerRG2BGR_MHT = 258, BayerGR2BGR_MHT = 259, BayerBG2RGB_MHT = 258, BayerGB2RGB_MHT = 259, BayerRG2RGB_MHT = 256, BayerGR2RGB_MHT = 257, BayerBG2GRAY_MHT = 260, BayerGB2GRAY_MHT = 261, BayerRG2GRAY_MHT = 262, BayerGR2GRAY_MHT = 263 } public enum AlphaCompTypes { Over, In, Out, Atop, Xor, Plus, OverPremul, InPremul, OutPremul, AtopPremul, XorPremul, PlusPremul, Premul } public class CudaMinEigenValCorner : CudaCornernessCriteria { public CudaMinEigenValCorner(DepthType srcDepth, int srcChannels, int blockSize, int kSize, BorderType borderType = BorderType.Reflect101) { _ptr = CudaInvoke.cudaCreateMinEigenValCorner(CvInvoke.MakeType(srcDepth, srcChannels), blockSize, kSize, borderType, ref _sharedPtr); } } public class CudaTemplateMatching : SharedPtrObject { public CudaTemplateMatching(DepthType depthType, int channels, TemplateMatchingType method, Size blockSize = default(Size)) { _ptr = CudaInvoke.cudaTemplateMatchingCreate(CvInvoke.MakeType(depthType, channels), method, ref blockSize, ref _sharedPtr); } public void Match(IInputArray image, IInputArray templ, IOutputArray result, Stream stream = null) { using InputArray inputArray = image.GetInputArray(); using InputArray inputArray2 = templ.GetInputArray(); using OutputArray outputArray = result.GetOutputArray(); CudaInvoke.cudaTemplateMatchingMatch(_ptr, inputArray, inputArray2, outputArray, stream); } protected override void DisposeObject() { if (_sharedPtr != IntPtr.Zero) { CudaInvoke.cudaTemplateMatchingRelease(ref _sharedPtr); _ptr = IntPtr.Zero; } } } public class CudaBroxOpticalFlow : SharedPtrObject, ICudaDenseOpticalFlow, IAlgorithm { private IntPtr _denseFlow; private IntPtr _algorithm; public IntPtr DenseOpticalFlowPtr => _denseFlow; public IntPtr AlgorithmPtr => _algorithm; public CudaBroxOpticalFlow(double alpha = 0.197, double gamma = 50.0, double scaleFactor = 0.8, int innerIterations = 5, int outerIterations = 150, int solverIterations = 10) { _ptr = CudaInvoke.cudaBroxOpticalFlowCreate(alpha, gamma, scaleFactor, innerIterations, outerIterations, solverIterations, ref _denseFlow, ref _algorithm, ref _sharedPtr); } protected override void DisposeObject() { if (_sharedPtr != IntPtr.Zero) { CudaInvoke.cudaBroxOpticalFlowRelease(ref _sharedPtr); _ptr = IntPtr.Zero; _denseFlow = IntPtr.Zero; _algorithm = IntPtr.Zero; } } } public class CudaDensePyrLKOpticalFlow : SharedPtrObject, ICudaDenseOpticalFlow, IAlgorithm { private IntPtr _denseFlow; private IntPtr _algorithm; public IntPtr DenseOpticalFlowPtr => _denseFlow; public IntPtr AlgorithmPtr => _algorithm; public CudaDensePyrLKOpticalFlow(Size winSize, int maxLevel = 3, int iters = 30, bool useInitialFlow = false) { _ptr = CudaInvoke.cudaDensePyrLKOpticalFlowCreate(ref winSize, maxLevel, iters, useInitialFlow, ref _denseFlow, ref _algorithm, ref _sharedPtr); } protected override void DisposeObject() { if (_sharedPtr != IntPtr.Zero) { CudaInvoke.cudaDensePyrLKOpticalFlowRelease(ref _sharedPtr); _ptr = IntPtr.Zero; _denseFlow = IntPtr.Zero; _algorithm = IntPtr.Zero; } } } public class CudaFarnebackOpticalFlow : SharedPtrObject, ICudaDenseOpticalFlow, IAlgorithm { private IntPtr _denseFlow; private IntPtr _algorithm; public IntPtr DenseOpticalFlowPtr => _denseFlow; public IntPtr AlgorithmPtr => _algorithm; public CudaFarnebackOpticalFlow(int numLevels = 5, double pyrScale = 0.5, bool fastPyramids = false, int winSize = 13, int numIters = 10, int polyN = 5, double polySigma = 1.1, OpticalflowFarnebackFlag flags = OpticalflowFarnebackFlag.Default) { _ptr = CudaInvoke.cudaFarnebackOpticalFlowCreate(numLevels, pyrScale, fastPyramids, winSize, numIters, polyN, polySigma, flags, ref _denseFlow, ref _algorithm, ref _sharedPtr); } protected override void DisposeObject() { if (_sharedPtr != IntPtr.Zero) { CudaInvoke.cudaFarnebackOpticalFlowRelease(ref _sharedPtr); _ptr = IntPtr.Zero; _denseFlow = IntPtr.Zero; _algorithm = IntPtr.Zero; } } } public class CudaOpticalFlowDualTvl1 : SharedPtrObject, ICudaDenseOpticalFlow, IAlgorithm { private IntPtr _denseFlow; private IntPtr _algorithm; public IntPtr DenseOpticalFlowPtr => _denseFlow; public IntPtr AlgorithmPtr => _algorithm; public CudaOpticalFlowDualTvl1(double tau = 0.25, double lambda = 0.15, double theta = 0.3, int nscales = 5, int warps = 5, double epsilon = 0.01, int iterations = 300, double scaleStep = 0.8, double gamma = 0.0, bool useInitialFlow = false) { _ptr = CudaInvoke.cudaOpticalFlowDualTvl1Create(tau, lambda, theta, nscales, warps, epsilon, iterations, scaleStep, gamma, useInitialFlow, ref _denseFlow, ref _algorithm, ref _sharedPtr); } protected override void DisposeObject() { if (_sharedPtr != IntPtr.Zero) { CudaInvoke.cudaOpticalFlowDualTvl1Release(ref _sharedPtr); _denseFlow = IntPtr.Zero; _algorithm = IntPtr.Zero; _ptr = IntPtr.Zero; } } } public class CudaSparsePyrLKOpticalFlow : SharedPtrObject, ICudaSparseOpticalFlow, IAlgorithm { private IntPtr _sparseFlow; private IntPtr _algorithm; public IntPtr SparseOpticalFlowPtr => _sparseFlow; public IntPtr AlgorithmPtr => _algorithm; public CudaSparsePyrLKOpticalFlow(Size winSize, int maxLevel = 3, int iters = 30, bool useInitialFlow = false) { _ptr = CudaInvoke.cudaSparsePyrLKOpticalFlowCreate(ref winSize, maxLevel, iters, useInitialFlow, ref _sparseFlow, ref _algorithm, ref _sharedPtr); } protected override void DisposeObject() { if (_sharedPtr != IntPtr.Zero) { CudaInvoke.cudaSparsePyrLKOpticalFlowRelease(ref _sharedPtr); _ptr = IntPtr.Zero; _sparseFlow = IntPtr.Zero; _algorithm = IntPtr.Zero; } } } public interface ICudaDenseOpticalFlow : IAlgorithm { IntPtr DenseOpticalFlowPtr { get; } } public interface ICudaSparseOpticalFlow : IAlgorithm { IntPtr SparseOpticalFlowPtr { get; } } public interface INvidiaOpticalFlow : IAlgorithm { IntPtr NvidiaOpticalFlowPtr { get; } } public class NvidiaOpticalFlow_1_0 : SharedPtrObject, INvidiaOpticalFlow, IAlgorithm { public enum PerfLevel { Undefined = 0, Slow = 5, Medium = 10, Fast = 20, Max = 21 } private IntPtr _nvidiaHWOpticalFlow; private IntPtr _algorithm; public IntPtr NvidiaOpticalFlowPtr => _nvidiaHWOpticalFlow; public IntPtr AlgorithmPtr => _algorithm; public NvidiaOpticalFlow_1_0(Size imageSize, PerfLevel perfPreset = PerfLevel.Slow, bool enableTemporalHints = false, bool enableExternalHints = false, bool enableCostBuffer = false, int gpuId = 0, Stream inputStream = null, Stream outputStream = null) { _ptr = CudaInvoke.cudaNvidiaOpticalFlow_1_0_Create(ref imageSize, perfPreset, enableTemporalHints, enableExternalHints, enableCostBuffer, gpuId, inputStream, outputStream, ref _nvidiaHWOpticalFlow, ref _algorithm, ref _sharedPtr); } public void UpSampler(IInputArray flow, Size imageSize, int gridSize, IInputOutputArray upsampledFlow) { using InputArray inputArray = flow.GetInputArray(); using InputOutputArray inputOutputArray = upsampledFlow.GetInputOutputArray(); CudaInvoke.cudaNvidiaOpticalFlow_1_0_UpSampler(_ptr, inputArray, ref imageSize, gridSize, inputOutputArray); } protected override void DisposeObject() { if (_sharedPtr != IntPtr.Zero) { CudaInvoke.cudaNvidiaOpticalFlow_1_0_Release(ref _sharedPtr); _nvidiaHWOpticalFlow = IntPtr.Zero; _algorithm = IntPtr.Zero; _ptr = IntPtr.Zero; } } } public class NvidiaOpticalFlow_2_0 : SharedPtrObject, INvidiaOpticalFlow, IAlgorithm { public enum PerfLevel { Undefined = 0, Slow = 5, Medium = 10, Fast = 20, Max = 21 } public enum OutputVectorGridSize { Undefined = 0, Size1 = 1, Size2 = 2, Size4 = 4, Max = 5 } public enum HintVectorGridSize { Undefined = 0, Size1 = 1, Size2 = 2, Size4 = 4, Size8 = 8, Max = 9 } private IntPtr _nvidiaHWOpticalFlow; private IntPtr _algorithm; public IntPtr NvidiaOpticalFlowPtr => _nvidiaHWOpticalFlow; public IntPtr AlgorithmPtr => _algorithm; public NvidiaOpticalFlow_2_0(Size imageSize, PerfLevel perfPreset = PerfLevel.Slow, OutputVectorGridSize outputGridSize = OutputVectorGridSize.Size1, HintVectorGridSize hintGridSize = HintVectorGridSize.Size1, bool enableTemporalHints = false, bool enableExternalHints = false, bool enableCostBuffer = false, int gpuId = 0, Stream inputStream = null, Stream outputStream = null) { _ptr = CudaInvoke.cudaNvidiaOpticalFlow_2_0_Create(ref imageSize, perfPreset, outputGridSize, hintGridSize, enableTemporalHints, enableExternalHints, enableCostBuffer, gpuId, inputStream, outputStream, ref _nvidiaHWOpticalFlow, ref _algorithm, ref _sharedPtr); } protected override void DisposeObject() { if (_sharedPtr != IntPtr.Zero) { CudaInvoke.cudaNvidiaOpticalFlow_2_0_Release(ref _sharedPtr); _nvidiaHWOpticalFlow = IntPtr.Zero; _algorithm = IntPtr.Zero; _ptr = IntPtr.Zero; } } public void ConvertToFloat(IInputArray flow, IInputOutputArray floatFlow) { using InputArray inputArray = flow.GetInputArray(); using InputOutputArray inputOutputArray = floatFlow.GetInputOutputArray(); CudaInvoke.cudaNvidiaOpticalFlow_2_0_ConvertToFloat(_ptr, inputArray, inputOutputArray); } } public abstract class DescriptorMatcher : SharedPtrObject, IAlgorithm { protected IntPtr _algorithmPtr; IntPtr IAlgorithm.AlgorithmPtr => _algorithmPtr; public bool IsMaskSupported => CudaInvoke.cveCudaDescriptorMatcherIsMaskSupported(_ptr); public bool Empty => CudaInvoke.cveCudaDescriptorMatcherEmpty(_ptr); public void KnnMatch(IInputArray queryDescriptors, IInputArray trainDescriptors, VectorOfVectorOfDMatch matches, int k, IInputArray mask = null, bool compactResult = false) { using InputArray inputArray = queryDescriptors.GetInputArray(); using InputArray inputArray2 = trainDescriptors.GetInputArray(); using InputArray inputArray3 = ((mask == null) ? InputArray.GetEmpty() : mask.GetInputArray()); CudaInvoke.cveCudaDescriptorMatcherKnnMatch1(_ptr, inputArray, inputArray2, matches, k, inputArray3, compactResult); } public void KnnMatch(IInputArray queryDescriptors, VectorOfVectorOfDMatch matches, int k, VectorOfGpuMat masks = null, bool compactResult = false) { using InputArray inputArray = queryDescriptors.GetInputArray(); CudaInvoke.cveCudaDescriptorMatcherKnnMatch2(_ptr, inputArray, matches, k, masks?.Ptr ?? IntPtr.Zero, compactResult); } public void KnnMatchAsync(IInputArray queryDescriptors, IInputArray trainDescriptors, IOutputArray matches, int k, IInputArray mask = null, Stream stream = null) { using InputArray inputArray = queryDescriptors.GetInputArray(); using InputArray inputArray2 = trainDescriptors.GetInputArray(); using OutputArray outputArray = matches.GetOutputArray(); using InputArray inputArray3 = ((mask == null) ? InputArray.GetEmpty() : mask.GetInputArray()); CudaInvoke.cveCudaDescriptorMatcherKnnMatchAsync1(_ptr, inputArray, inputArray2, outputArray, k, inputArray3, stream); } public void KnnMatchAsync(IInputArray queryDescriptors, IOutputArray matches, int k, VectorOfGpuMat masks = null, Stream stream = null) { using InputArray inputArray = queryDescriptors.GetInputArray(); using OutputArray outputArray = matches.GetOutputArray(); CudaInvoke.cveCudaDescriptorMatcherKnnMatchAsync2(_ptr, inputArray, outputArray, k, masks?.Ptr ?? IntPtr.Zero, stream); } public void KnnMatchConvert(IInputArray gpuMatches, VectorOfVectorOfDMatch matches, bool compactResult = false) { using InputArray inputArray = gpuMatches.GetInputArray(); CudaInvoke.cveCudaDescriptorMatcherKnnMatchConvert(_ptr, inputArray, matches, compactResult); } public void Match(IInputArray queryDescriptors, IInputArray trainDescriptors, VectorOfDMatch matches, IInputArray mask = null) { using InputArray inputArray = queryDescriptors.GetInputArray(); using InputArray inputArray2 = trainDescriptors.GetInputArray(); using InputArray inputArray3 = ((mask == null) ? InputArray.GetEmpty() : mask.GetInputArray()); CudaInvoke.cveCudaDescriptorMatcherMatch1(_ptr, inputArray, inputArray2, matches, inputArray3); } public void Match(IInputArray queryDescriptors, VectorOfDMatch matches, VectorOfGpuMat mask = null) { using InputArray inputArray = queryDescriptors.GetInputArray(); CudaInvoke.cveCudaDescriptorMatcherMatch2(_ptr, inputArray, matches, mask?.Ptr ?? IntPtr.Zero); } public void MatchAsync(IInputArray queryDescriptors, IInputArray trainDescriptors, IOutputArray matches, IInputArray mask = null, Stream stream = null) { using InputArray inputArray = queryDescriptors.GetInputArray(); using InputArray inputArray2 = trainDescriptors.GetInputArray(); using OutputArray outputArray = matches.GetOutputArray(); using InputArray inputArray3 = ((mask == null) ? InputArray.GetEmpty() : mask.GetInputArray()); CudaInvoke.cveCudaDescriptorMatcherMatchAsync1(_ptr, inputArray, inputArray2, outputArray, inputArray3, stream); } public void MatchAsync(IInputArray queryDescriptors, IOutputArray matches, VectorOfGpuMat masks = null, Stream stream = null) { using InputArray inputArray = queryDescriptors.GetInputArray(); using OutputArray outputArray = matches.GetOutputArray(); CudaInvoke.cveCudaDescriptorMatcherMatchAsync2(_ptr, inputArray, outputArray, masks?.Ptr ?? IntPtr.Zero, stream); } public void MatchConvert(IInputArray gpuMatches, VectorOfDMatch matches) { using InputArray inputArray = gpuMatches.GetInputArray(); CudaInvoke.cveCudaDescriptorMatcherMatchConvert(_ptr, inputArray, matches); } public void RadiusMatch(IInputArray queryDescriptors, IInputArray trainDescriptors, VectorOfVectorOfDMatch matches, float maxDistance, IInputArray mask = null, bool compactResult = false) { using InputArray inputArray = queryDescriptors.GetInputArray(); using InputArray inputArray2 = trainDescriptors.GetInputArray(); using InputArray inputArray3 = ((mask == null) ? InputArray.GetEmpty() : mask.GetInputArray()); CudaInvoke.cveCudaDescriptorMatcherRadiusMatch1(_ptr, inputArray, inputArray2, matches, maxDistance, inputArray3, compactResult); } public void RadiusMatch(IInputArray queryDescriptors, VectorOfVectorOfDMatch matches, float maxDistance, VectorOfGpuMat masks = null, bool compactResult = false) { using InputArray inputArray = queryDescriptors.GetInputArray(); CudaInvoke.cveCudaDescriptorMatcherRadiusMatch2(_ptr, inputArray, matches, maxDistance, masks?.Ptr ?? IntPtr.Zero, compactResult); } public void RadiusMatchAsync(IInputArray queryDescriptors, IInputArray trainDescriptors, IOutputArray matches, float maxDistance, IInputArray mask = null, Stream stream = null) { using InputArray inputArray = queryDescriptors.GetInputArray(); using InputArray inputArray2 = trainDescriptors.GetInputArray(); using OutputArray outputArray = matches.GetOutputArray(); using InputArray inputArray3 = ((mask == null) ? InputArray.GetEmpty() : mask.GetInputArray()); CudaInvoke.cveCudaDescriptorMatcherRadiusMatchAsync1(_ptr, inputArray, inputArray2, outputArray, maxDistance, inputArray3, stream); } public void RadiusMatchAsync(IInputArray queryDescriptors, IOutputArray matches, float maxDistance, VectorOfGpuMat masks, Stream stream) { using InputArray inputArray = queryDescriptors.GetInputArray(); using OutputArray outputArray = matches.GetOutputArray(); CudaInvoke.cveCudaDescriptorMatcherRadiusMatchAsync2(_ptr, inputArray, outputArray, maxDistance, masks?.Ptr ?? IntPtr.Zero, stream); } public void RadiusMatchConvert(IInputArray gpuMatches, VectorOfVectorOfDMatch matches, bool compactResult) { using InputArray inputArray = gpuMatches.GetInputArray(); CudaInvoke.cveCudaDescriptorMatcherRadiusMatchConvert(_ptr, inputArray, matches, compactResult); } public void Add(IInputArray modelDescriptors) { using InputArray inputArray = modelDescriptors.GetInputArray(); CudaInvoke.cveCudaDescriptorMatcherAdd(_ptr, inputArray); } public void Clear() { CudaInvoke.cveCudaDescriptorMatcherClear(_ptr); } public void Train() { CudaInvoke.cveCudaDescriptorMatcherTrain(_ptr); } protected override void DisposeObject() { if (IntPtr.Zero != _sharedPtr) { CudaInvoke.cveCudaDescriptorMatcherRelease(ref _sharedPtr); _ptr = IntPtr.Zero; } } } public class CudaBFMatcher : DescriptorMatcher { public CudaBFMatcher(DistanceType distanceType) { _ptr = CudaInvoke.cveCudaDescriptorMatcherCreateBFMatcher(distanceType, ref _algorithmPtr, ref _sharedPtr); } } public class CudaFastFeatureDetector : FastFeatureDetector, IFeature2DAsync { private IntPtr _feature2DAsyncPtr; IntPtr IFeature2DAsync.Feature2DAsyncPtr => _feature2DAsyncPtr; public CudaFastFeatureDetector(int threshold = 10, bool nonmaxSupression = true, DetectorType type = DetectorType.Type9_16, int maxNKeypoints = 5000) { _ptr = CudaInvoke.cveCudaFastFeatureDetectorCreate(threshold, nonmaxSupression, type, maxNKeypoints, ref _feature2D, ref _feature2DAsyncPtr, ref _sharedPtr); } protected override void DisposeObject() { if (_ptr != IntPtr.Zero) { CudaInvoke.cveCudaFastFeatureDetectorRelease(ref _sharedPtr); } _feature2DAsyncPtr = IntPtr.Zero; base.DisposeObject(); } } public class CudaORBDetector : ORB, IFeature2DAsync { private IntPtr _feature2DAsyncPtr; IntPtr IFeature2DAsync.Feature2DAsyncPtr => _feature2DAsyncPtr; public CudaORBDetector(int numberOfFeatures = 500, float scaleFactor = 1.2f, int nLevels = 8, int edgeThreshold = 31, int firstLevel = 0, int WTK_A = 2, ScoreType scoreType = ScoreType.Harris, int patchSize = 31, int fastThreshold = 20, bool blurForDescriptor = false) { _ptr = CudaInvoke.cveCudaORBCreate(numberOfFeatures, scaleFactor, nLevels, edgeThreshold, firstLevel, WTK_A, scoreType, patchSize, fastThreshold, blurForDescriptor, ref _feature2D, ref _feature2DAsyncPtr, ref _sharedPtr); } protected override void DisposeObject() { if (_sharedPtr != IntPtr.Zero) { CudaInvoke.cveCudaORBRelease(ref _sharedPtr); } _feature2DAsyncPtr = IntPtr.Zero; base.DisposeObject(); } } public interface IFeature2DAsync { IntPtr Feature2DAsyncPtr { get; } } public static class Feature2DAsyncExtension { public static void DetectAndComputeAsync(this IFeature2DAsync feature2DAsync, IInputArray image, IInputArray mask, IOutputArray keyPoints, IOutputArray descriptors, bool useProvidedKeyPoints, Stream stream = null) { using InputArray inputArray = image.GetInputArray(); using InputArray inputArray2 = ((mask == null) ? InputArray.GetEmpty() : mask.GetInputArray()); using OutputArray outputArray = keyPoints.GetOutputArray(); using OutputArray outputArray2 = descriptors.GetOutputArray(); CudaInvoke.cveCudaFeature2dAsyncDetectAndComputeAsync(feature2DAsync.Feature2DAsyncPtr, inputArray, inputArray2, outputArray, outputArray2, useProvidedKeyPoints, stream); } public static void DetectAsync(this IFeature2DAsync feature2DAsync, IInputArray image, IOutputArray keypoints, IInputArray mask = null, Stream stream = null) { using InputArray inputArray = image.GetInputArray(); using OutputArray outputArray = keypoints.GetOutputArray(); using InputArray inputArray2 = ((mask == null) ? InputArray.GetEmpty() : mask.GetInputArray()); CudaInvoke.cveCudaFeature2dAsyncDetectAsync(feature2DAsync.Feature2DAsyncPtr, inputArray, outputArray, inputArray2, stream); } public static void ComputeAsync(this IFeature2DAsync feature2DAsync, IInputArray image, IOutputArray keypoints, IOutputArray descriptors, Stream stream = null) { using InputArray inputArray = image.GetInputArray(); using OutputArray outputArray = keypoints.GetOutputArray(); using OutputArray outputArray2 = descriptors.GetOutputArray(); CudaInvoke.cveCudaFeature2dAsyncComputeAsync(feature2DAsync.Feature2DAsyncPtr, inputArray, outputArray, outputArray2, stream); } public static void Convert(this IFeature2DAsync feature2DAsync, IInputArray gpuKeypoints, VectorOfKeyPoint keypoints) { using InputArray inputArray = gpuKeypoints.GetInputArray(); CudaInvoke.cveCudaFeature2dAsyncConvert(feature2DAsync.Feature2DAsyncPtr, inputArray, keypoints); } } public class CudaDisparityBilateralFilter : SharedPtrObject { public CudaDisparityBilateralFilter(int ndisp = 64, int radius = 3, int iters = 1) { _ptr = CudaInvoke.cudaDisparityBilateralFilterCreate(ndisp, radius, iters, ref _sharedPtr); } public void Apply(IInputArray disparity, IInputArray image, IOutputArray dst, Stream stream = null) { using InputArray inputArray = disparity.GetInputArray(); using InputArray inputArray2 = image.GetInputArray(); using OutputArray outputArray = dst.GetOutputArray(); CudaInvoke.cudaDisparityBilateralFilterApply(this, inputArray, inputArray2, outputArray, stream); } protected override void DisposeObject() { if (IntPtr.Zero != _sharedPtr) { CudaInvoke.cudaDisparityBilateralFilterRelease(ref _sharedPtr); _ptr = IntPtr.Zero; } } } public class CudaStereoBM : SharedPtrObject { public CudaStereoBM(int numberOfDisparities = 64, int blockSize = 19) { _ptr = CudaInvoke.cudaStereoBMCreate(numberOfDisparities, blockSize, ref _sharedPtr); } public void FindStereoCorrespondence(IInputArray left, IInputArray right, IOutputArray disparity, Stream stream = null) { using InputArray inputArray = left.GetInputArray(); using InputArray inputArray2 = right.GetInputArray(); using OutputArray outputArray = disparity.GetOutputArray(); CudaInvoke.cudaStereoBMFindStereoCorrespondence(_ptr, inputArray, inputArray2, outputArray, stream); } protected override void DisposeObject() { if (IntPtr.Zero != _sharedPtr) { CudaInvoke.cudaStereoBMRelease(ref _sharedPtr); _ptr = IntPtr.Zero; } } } public class CudaStereoConstantSpaceBP : SharedPtrObject { public CudaStereoConstantSpaceBP(int ndisp = 128, int iters = 8, int levels = 4, int nrPlane = 4) { _ptr = CudaInvoke.cudaStereoConstantSpaceBPCreate(ndisp, iters, levels, nrPlane, ref _sharedPtr); } public void FindStereoCorrespondence(IInputArray left, IInputArray right, IOutputArray disparity, Stream stream = null) { using InputArray inputArray = left.GetInputArray(); using InputArray inputArray2 = right.GetInputArray(); using OutputArray outputArray = disparity.GetOutputArray(); CudaInvoke.cudaStereoConstantSpaceBPFindStereoCorrespondence(_ptr, inputArray, inputArray2, outputArray, stream); } protected override void DisposeObject() { if (IntPtr.Zero != _sharedPtr) { CudaInvoke.cudaStereoConstantSpaceBPRelease(ref _sharedPtr); _ptr = IntPtr.Zero; } } } public class CudaCascadeClassifier : SharedPtrObject { public double ScaleFactor { get { return CudaInvoke.cveCudaCascadeClassifierGetScaleFactor(_ptr); } set { CudaInvoke.cveCudaCascadeClassifierSetScaleFactor(_ptr, value); } } public int MinNeighbors { get { return CudaInvoke.cveCudaCascadeClassifierGetMinNeighbors(_ptr); } set { CudaInvoke.cveCudaCascadeClassifierSetMinNeighbors(_ptr, value); } } public int MaxNumObjects { get { return CudaInvoke.cveCudaCascadeClassifierGetMaxNumObjects(_ptr); } set { CudaInvoke.cveCudaCascadeClassifierSetMaxNumObjects(_ptr, value); } } public bool FindLargestObject { get { return CudaInvoke.cveCudaCascadeClassifierGetFindLargestObject(_ptr); } set { CudaInvoke.cveCudaCascadeClassifierSetFindLargestObject(_ptr, value); } } public Size MaxObjectSize { get { Size val = default(Size); CudaInvoke.cveCudaCascadeClassifierGetMaxObjectSize(_ptr, ref val); return val; } set { CudaInvoke.cveCudaCascadeClassifierSetMaxObjectSize(_ptr, ref value); } } public Size MinObjectSize { get { Size val = default(Size); CudaInvoke.cveCudaCascadeClassifierGetMinObjectSize(_ptr, ref val); return val; } set { CudaInvoke.cveCudaCascadeClassifierSetMinObjectSize(_ptr, ref value); } } public Size ClassifierSize { get { Size val = default(Size); CudaInvoke.cveCudaCascadeClassifierGetClassifierSize(_ptr, ref val); return val; } } public CudaCascadeClassifier(string fileName) { using CvString cvString = new CvString(fileName); _ptr = CudaInvoke.cudaCascadeClassifierCreate(cvString, ref _sharedPtr); } public CudaCascadeClassifier(FileStorage fs) { _ptr = CudaInvoke.cudaCascadeClassifierCreateFromFileStorage(fs, ref _sharedPtr); } public void DetectMultiScale(IInputArray image, IOutputArray objects, Stream stream = null) { using InputArray inputArray = image.GetInputArray(); using OutputArray outputArray = objects.GetOutputArray(); CudaInvoke.cudaCascadeClassifierDetectMultiScale(_ptr, inputArray, outputArray, stream?.Ptr ?? IntPtr.Zero); } public Rectangle[] Convert(IOutputArray objects) { using OutputArray outputArray = objects.GetOutputArray(); using VectorOfRect vectorOfRect = new VectorOfRect(); CudaInvoke.cudaCascadeClassifierConvert(_ptr, outputArray, vectorOfRect); return vectorOfRect.ToArray(); } protected override void DisposeObject() { if (_sharedPtr != IntPtr.Zero) { CudaInvoke.cudaCascadeClassifierRelease(ref _sharedPtr); _ptr = IntPtr.Zero; } } } public class CudaHOG : SharedPtrObject { public enum DescrFormat { RowByRow, ColByCol } public bool GammaCorrection { get { return CudaInvoke.cveCudaHOGGetGammaCorrection(_ptr); } set { CudaInvoke.cveCudaHOGSetGammaCorrection(_ptr, value); } } public double WinSigma { get { return CudaInvoke.cveCudaHOGGetWinSigma(_ptr); } set { CudaInvoke.cveCudaHOGSetWinSigma(_ptr, value); } } public int NumLevels { get { return CudaInvoke.cveCudaHOGGetNumLevels(_ptr); } set { CudaInvoke.cveCudaHOGSetNumLevels(_ptr, value); } } public int GroupThreshold { get { return CudaInvoke.cveCudaHOGGetGroupThreshold(_ptr); } set { CudaInvoke.cveCudaHOGSetGroupThreshold(_ptr, value); } } public double HitThreshold { get { return CudaInvoke.cveCudaHOGGetHitThreshold(_ptr); } set { CudaInvoke.cveCudaHOGSetHitThreshold(_ptr, value); } } public double ScaleFactor { get { return CudaInvoke.cveCudaHOGGetScaleFactor(_ptr); } set { CudaInvoke.cveCudaHOGSetScaleFactor(_ptr, value); } } public double L2HysThreshold { get { return CudaInvoke.cveCudaHOGGetL2HysThreshold(_ptr); } set { CudaInvoke.cveCudaHOGSetL2HysThreshold(_ptr, value); } } public DescrFormat DescriptorFormat => CudaInvoke.cveCudaHOGGetDescriptorFormat(_ptr); public IntPtr DescriptorSize => CudaInvoke.cveCudaHOGGetDescriptorSize(_ptr); public Size WinStride { get { Size val = default(Size); CudaInvoke.cveCudaHOGGetWinStride(_ptr, ref val); return val; } set { CudaInvoke.cveCudaHOGSetWinStride(_ptr, ref value); } } public IntPtr BlockHistogramSize => CudaInvoke.cveCudaHOGGetBlockHistogramSize(_ptr); public CudaHOG(Size winSize, Size blockSize, Size blockStride, Size cellSize, int nbins = 9) { _ptr = CudaInvoke.cudaHOGCreate(ref winSize, ref blockSize, ref blockStride, ref cellSize, nbins, ref _sharedPtr); } public Mat GetDefaultPeopleDetector() { Mat mat = new Mat(); CudaInvoke.cudaHOGGetDefaultPeopleDetector(_ptr, mat); return mat; } public void SetSVMDetector(IInputArray detector) { using InputArray inputArray = detector.GetInputArray(); CudaInvoke.cudaHOGSetSVMDetector(_ptr, inputArray); } public MCvObjectDetection[] DetectMultiScale(IInputArray image) { using VectorOfRect vectorOfRect = new VectorOfRect(); using VectorOfDouble vectorOfDouble = new VectorOfDouble(); DetectMultiScale(image, vectorOfRect, vectorOfDouble); Rectangle[] array = vectorOfRect.ToArray(); double[] array2 = vectorOfDouble.ToArray(); MCvObjectDetection[] array3 = new MCvObjectDetection[array.Length]; for (int i = 0; i < array3.Length; i++) { MCvObjectDetection mCvObjectDetection = default(MCvObjectDetection); mCvObjectDetection.Rect = array[i]; mCvObjectDetection.Score = (float)array2[i]; array3[i] = mCvObjectDetection; } return array3; } public void DetectMultiScale(IInputArray image, VectorOfRect objects, VectorOfDouble confident = null) { using InputArray inputArray = image.GetInputArray(); CudaInvoke.cudaHOGDetectMultiScale(_ptr, inputArray, objects, confident); } protected override void DisposeObject() { if (_sharedPtr != IntPtr.Zero) { CudaInvoke.cudaHOGRelease(ref _sharedPtr); _ptr = IntPtr.Zero; } } } public class CudaVideoReader : SharedPtrObject { public enum Codec { MPEG1 = 0, MPEG2 = 1, MPEG4 = 2, VC1 = 3, H264 = 4, JPEG = 5, H264_SVC = 6, H264_MVC = 7, HEVC = 8, VP8 = 9, VP9 = 10, NumCodecs = 11, Uncompressed_YUV420 = 1230591318, Uncompressed_YV12 = 1498820914, Uncompressed_NV12 = 1314271538, Uncompressed_YUYV = 1498765654, Uncompressed_UYVY = 1431918169 } public enum ChromaFormat { Monochrome, YUV420, YUV422, YUV444, NumFormats } public struct FormatInfo { public Codec Codec; public ChromaFormat ChromaFormat; public int Width; public int Height; } public FormatInfo Format { get { FormatInfo formatInfo = default(FormatInfo); CudaInvoke.cudaVideoReaderFormat(_ptr, ref formatInfo); return formatInfo; } } public CudaVideoReader(string fileName) { using CvString cvString = new CvString(fileName); _ptr = CudaInvoke.cudaVideoReaderCreate(cvString, ref _sharedPtr); } public bool NextFrame(GpuMat frame, Stream stream = null) { return CudaInvoke.cudaVideoReaderNextFrame(_ptr, frame, stream); } protected override void DisposeObject() { if (_sharedPtr != IntPtr.Zero) { CudaInvoke.cudaVideoReaderRelease(ref _sharedPtr); _ptr = IntPtr.Zero; } } } public class CudaVideoWriter : SharedPtrObject { public enum SurfaceFormat { UYVY = 0, YUY2 = 1, YV12 = 2, NV12 = 3, IYUV = 4, BGR = 5, GRAY = 5 } public CudaVideoWriter(string fileName, Size frameSize, double fps, SurfaceFormat format = SurfaceFormat.BGR) { using CvString cvString = new CvString(fileName); _ptr = CudaInvoke.cudaVideoWriterCreate(cvString, ref frameSize, fps, format, ref _sharedPtr); } protected override void DisposeObject() { if (IntPtr.Zero != _sharedPtr) { CudaInvoke.cudaVideoWriterRelease(ref _sharedPtr); _ptr = IntPtr.Zero; } } public void Write(IInputArray frame, bool lastFrame = false) { using InputArray inputArray = frame.GetInputArray(); CudaInvoke.cudaVideoWriterWrite(_ptr, inputArray, lastFrame); } } public class CudaBackgroundSubtractorFGD : SharedPtrObject { public CudaBackgroundSubtractorFGD(int Lc = 128, int N1c = 15, int N2c = 25, int Lcc = 64, int N1cc = 25, int N2cc = 40, bool isObjWithoutHoles = true, int performMorphing = 1, float alpha1 = 0.1f, float alpha2 = 0.005f, float alpha3 = 0.1f, float delta = 2f, float T = 0.9f, float minArea = 15f) { _ptr = CudaInvoke.cudaBackgroundSubtractorFGDCreate(Lc, N1c, N2c, Lcc, N1cc, N2cc, isObjWithoutHoles, performMorphing, alpha1, alpha2, alpha3, delta, T, minArea, ref _sharedPtr); } public void Apply(IInputArray frame, IOutputArray forgroundMask, double learningRate = -1.0) { using InputArray inputArray = frame.GetInputArray(); using OutputArray outputArray = forgroundMask.GetOutputArray(); CudaInvoke.cudaBackgroundSubtractorFGDApply(_ptr, inputArray, outputArray, learningRate); } protected override void DisposeObject() { if (IntPtr.Zero != _sharedPtr) { CudaInvoke.cudaBackgroundSubtractorFGDRelease(ref _sharedPtr); _ptr = IntPtr.Zero; } } } public class CudaBackgroundSubtractorGMG : SharedPtrObject { public CudaBackgroundSubtractorGMG(int initializationFrames = 120, double decisionThreshold = 0.8) { _ptr = CudaInvoke.cudaBackgroundSubtractorGMGCreate(initializationFrames, decisionThreshold, ref _sharedPtr); } public void Apply(IInputArray frame, IOutputArray foregroundMask, double learningRate = -1.0, Stream stream = null) { using InputArray inputArray = frame.GetInputArray(); using OutputArray outputArray = foregroundMask.GetOutputArray(); CudaInvoke.cudaBackgroundSubtractorGMGApply(_ptr, inputArray, outputArray, learningRate, stream); } protected override void DisposeObject() { if (IntPtr.Zero != _sharedPtr) { CudaInvoke.cudaBackgroundSubtractorGMGRelease(ref _sharedPtr); _ptr = IntPtr.Zero; } } } } namespace Emgu.CV.OCR { public interface ITessResultRenderer { IntPtr TessResultRendererPtr { get; } } public class LocaleGuard : DisposableObject { public enum LocaleCategory { All, Collate, Ctype, Monetary, Numeric, Time } private LocaleCategory _category; private string _locale; private string _oldLocale; public LocaleGuard(LocaleCategory category, string locale) { _category = category; _locale = locale; _oldLocale = OcrInvoke.SetLocale(_category); if (locale != _oldLocale) { OcrInvoke.SetLocale(_category, _locale); } } protected override void DisposeObject() { if (_oldLocale != _locale) { OcrInvoke.SetLocale(_category, _oldLocale); } } } public static class OcrInvoke { public static string SetLocale(LocaleGuard.LocaleCategory category, string locale = null) { IntPtr intPtr; if (locale == null) { intPtr = cveStdSetlocale(category, IntPtr.Zero); if (!(intPtr == IntPtr.Zero)) { return Marshal.PtrToStringAnsi(intPtr); } return null; } IntPtr intPtr2 = Marshal.StringToHGlobalAnsi(locale); try { intPtr = cveStdSetlocale(category, intPtr2); } finally { Marshal.FreeHGlobal(intPtr2); } if (!(intPtr == IntPtr.Zero)) { return Marshal.PtrToStringAnsi(intPtr); } return null; } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern IntPtr cveStdSetlocale(LocaleGuard.LocaleCategory category, IntPtr locale); static OcrInvoke() { CvInvoke.Init(); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveTessBaseAPICreate(); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int cveTessBaseAPIInit(IntPtr ocr, IntPtr dataPath, IntPtr language, OcrEngineMode mode); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int cveTessBaseAPIInitRaw(IntPtr ocr, IntPtr rawData, int dataSize, IntPtr language, OcrEngineMode mode); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveTessBaseAPIRelease(ref IntPtr ocr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveTessBaseAPISetImage(IntPtr ocr, IntPtr image); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveTessBaseAPISetImagePix(IntPtr ocr, IntPtr pix); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveTessBaseAPIGetUTF8Text(IntPtr ocr, IntPtr text); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveTessBaseAPIGetHOCRText(IntPtr ocr, int pageNumber, IntPtr vectorOfByte); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveTessBaseAPIGetTSVText(IntPtr ocr, int pageNumber, IntPtr vectorOfByte); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveTessBaseAPIGetBoxText(IntPtr ocr, int pageNumber, IntPtr vectorOfByte); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveTessBaseAPIGetUNLVText(IntPtr ocr, IntPtr vectorOfByte); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveTessBaseAPIGetOsdText(IntPtr ocr, int pageNumber, IntPtr vectorOfByte); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveTessBaseAPIExtractResult(IntPtr ocr, IntPtr charSeq, IntPtr resultSeq); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.U1)] internal static extern bool cveTessBaseAPIProcessPage(IntPtr ocr, IntPtr pix, int pageIndex, IntPtr filename, IntPtr retryConfig, int timeoutMillisec, IntPtr renderer); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.U1)] internal static extern bool cveTessBaseAPISetVariable(IntPtr ocr, [MarshalAs(UnmanagedType.LPStr)] string varName, [MarshalAs(UnmanagedType.LPStr)] string value); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveTesseractGetVersion(); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveTessBaseAPISetPageSegMode(IntPtr ocr, PageSegMode mode); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern PageSegMode cveTessBaseAPIGetPageSegMode(IntPtr ocr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int cveTessBaseAPIGetOpenCLDevice(IntPtr ocr, ref IntPtr device); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveTessBaseAPIAnalyseLayout(IntPtr ocr, [MarshalAs(UnmanagedType.U1)] bool mergeSimilarWords); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int cveTessBaseAPIIsValidWord(IntPtr ocr, [MarshalAs(UnmanagedType.LPStr)] string word); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveTessPageIteratorRelease(ref IntPtr iterator); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveTessPageIteratorGetOrientation(IntPtr iterator, ref PageOrientation orientation, ref WritingDirection writingDirection, ref TextlineOrder order, ref float deskewAngle); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.U1)] internal static extern bool cveTessPageIteratorGetBaseLine(IntPtr iterator, PageIteratorLevel level, ref int x1, ref int y1, ref int x2, ref int y2); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern OcrEngineMode cveTessBaseAPIGetOem(IntPtr ocr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int cveTessBaseAPIRecognize(IntPtr ocr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveTessBaseAPIGetDatapath(IntPtr ocr, IntPtr datapath); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveLeptCreatePixFromMat(IntPtr m); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveLeptPixDestroy(ref IntPtr pix); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveTessPDFRendererCreate(IntPtr outputbase, IntPtr datadir, [MarshalAs(UnmanagedType.U1)] bool textonly, ref IntPtr resultRenderer); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveTessPDFRendererRelease(ref IntPtr renderer); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.U1)] internal static extern bool cveTessResultRendererBeginDocument(IntPtr resultRenderer, IntPtr title); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.U1)] internal static extern bool cveTessResultRendererAddImage(IntPtr resultRenderer, IntPtr api); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.U1)] internal static extern bool cveTessResultRendererEndDocument(IntPtr resultRenderer); public static bool BeginDocument(this ITessResultRenderer renderer, string title) { using CvString cvString = new CvString(title); return cveTessResultRendererBeginDocument(renderer.TessResultRendererPtr, cvString); } public static bool AddImage(this ITessResultRenderer renderer, Tesseract api) { return cveTessResultRendererAddImage(renderer.TessResultRendererPtr, api.Ptr); } public static bool EndDocument(this ITessResultRenderer renderer) { return cveTessResultRendererEndDocument(renderer.TessResultRendererPtr); } } public enum OcrEngineMode { TesseractOnly, LstmOnly, TesseractLstmCombined, Default } public class PageIterator : UnmanagedObject { public Orientation Orientation { get { Orientation result = default(Orientation); PageOrientation orientation = PageOrientation.Up; WritingDirection writingDirection = WritingDirection.LeftToRight; TextlineOrder order = TextlineOrder.TopToBottom; float deskewAngle = 0f; OcrInvoke.cveTessPageIteratorGetOrientation(_ptr, ref orientation, ref writingDirection, ref order, ref deskewAngle); result.PageOrientation = orientation; result.WritingDirection = writingDirection; result.TextlineOrder = order; result.DeskewAngle = deskewAngle; return result; } } internal PageIterator(IntPtr ptr) { _ptr = ptr; } public LineSegment2D? GetBaseLine(PageIteratorLevel level) { int x = 0; int y = 0; int x2 = 0; int y2 = 0; if (!OcrInvoke.cveTessPageIteratorGetBaseLine(_ptr, level, ref x, ref y, ref x2, ref y2)) { return null; } return new LineSegment2D(new Point(x, y), new Point(x2, y2)); } protected override void DisposeObject() { if (IntPtr.Zero != _ptr) { OcrInvoke.cveTessPageIteratorRelease(ref _ptr); } } } public struct Orientation { public PageOrientation PageOrientation; public WritingDirection WritingDirection; public TextlineOrder TextlineOrder; public float DeskewAngle; } public enum PageOrientation { Up, Right, Down, Left } public enum WritingDirection { LeftToRight, RightToLeft, TopToBottom } public enum TextlineOrder { LeftToRight, RightToLeft, TopToBottom } public enum PageIteratorLevel { Block, Para, Textline, Word, Symbol } public enum PageSegMode { OsdOnly, AutoOsd, AutoOnly, Auto, SingleColumn, SingleBlockVertText, SingleBlock, SingleLine, SingleWord, CircleWord, SingleChar, SparseText, SparseTextOsd, RawLine, Count } public class Pix : UnmanagedObject { public Pix(Mat mat) { _ptr = OcrInvoke.cveLeptCreatePixFromMat(mat); } protected override void DisposeObject() { if (_ptr != IntPtr.Zero) { OcrInvoke.cveLeptPixDestroy(ref _ptr); } } } public class Tesseract : UnmanagedObject { public struct Character { public string Text; public float Cost; public Rectangle Region; } private UTF8Encoding _utf8 = new UTF8Encoding(); public static string VersionString { get { IntPtr intPtr = OcrInvoke.cveTesseractGetVersion(); if (intPtr == IntPtr.Zero) { return string.Empty; } return Marshal.PtrToStringAnsi(intPtr); } } public static Version Version { get { string text = VersionString; if (string.IsNullOrEmpty(text)) { return new Version(0, 0); } if (text.Contains("-")) { text = text[..text.IndexOf('-')]; } return new Version(text.Replace("dev", string.Empty).Replace("alpha", string.Empty)); } } public PageSegMode PageSegMode { get { return OcrInvoke.cveTessBaseAPIGetPageSegMode(_ptr); } set { OcrInvoke.cveTessBaseAPISetPageSegMode(_ptr, value); } } public static string DefaultTesseractDirectory { get { string path = "."; Assembly assembly = typeof(CvInvoke).Assembly; if ((!string.IsNullOrEmpty(assembly.Location) && File.Exists(assembly.Location)) || AppDomain.CurrentDomain.BaseDirectory == null) { path = Path.GetDirectoryName(assembly.Location); } string text = Path.Combine(path, "tessdata"); char directorySeparatorChar = Path.DirectorySeparatorChar; return text + directorySeparatorChar; } } private static string TessdataUrl => "https://github.com/tesseract-ocr/tessdata/blob/4.1.0"; public string Datapath { get { using CvString cvString = new CvString(); OcrInvoke.cveTessBaseAPIGetDatapath(_ptr, cvString); return cvString.ToString(); } } public OcrEngineMode Oem => OcrInvoke.cveTessBaseAPIGetOem(_ptr); public Tesseract(bool enforceLocale = true) { LocaleGuard localeGuard = null; if (enforceLocale) { localeGuard = new LocaleGuard(LocaleGuard.LocaleCategory.All, "C"); } try { _ptr = OcrInvoke.cveTessBaseAPICreate(); } finally { localeGuard?.Dispose(); } } public int GetOpenCLDevice(ref IntPtr device) { return OcrInvoke.cveTessBaseAPIGetOpenCLDevice(_ptr, ref device); } public Tesseract(string dataPath, string language, OcrEngineMode mode, string whiteList = null, bool enforceLocale = true) : this(enforceLocale) { Init(dataPath, language, mode); if (whiteList != null) { SetVariable("tessedit_char_whitelist", whiteList); } } public int IsValidWord(string word) { return OcrInvoke.cveTessBaseAPIIsValidWord(_ptr, word); } public static string GetLangFileUrl(string lang) { return $"{TessdataUrl}/{lang}.traineddata?raw=true"; } public void Init(string dataPath, string language, OcrEngineMode mode) { using CvString cvString = new CvString(dataPath); using CvString cvString2 = new CvString(language); if (OcrInvoke.cveTessBaseAPIInit(_ptr, cvString, cvString2, mode) != 0) { if (dataPath.Equals(string.Empty)) { dataPath = Path.GetFullPath("."); } throw new ArgumentException($"Unable to create ocr model using Path '{dataPath}', language '{language}' and OcrEngineMode '{mode}'."); } } public void Init(byte[] rawTrainedData, string language, OcrEngineMode mode) { GCHandle gCHandle = GCHandle.Alloc(rawTrainedData, GCHandleType.Pinned); try { using CvString cvString = new CvString(language); if (OcrInvoke.cveTessBaseAPIInitRaw(_ptr, gCHandle.AddrOfPinnedObject(), rawTrainedData.Length, cvString, mode) != 0) { throw new ArgumentException($"Unable to create ocr model using OcrEngineMode '{mode}'."); } } finally { gCHandle.Free(); } } protected override void DisposeObject() { if (_ptr != IntPtr.Zero) { OcrInvoke.cveTessBaseAPIRelease(ref _ptr); } } public void SetImage(IInputArray image) { using InputArray inputArray = image.GetInputArray(); OcrInvoke.cveTessBaseAPISetImage(_ptr, inputArray); } public void SetImage(Pix image) { OcrInvoke.cveTessBaseAPISetImagePix(_ptr, image); } public int Recognize() { return OcrInvoke.cveTessBaseAPIRecognize(_ptr); } public void SetVariable(string variableName, string value) { if (!OcrInvoke.cveTessBaseAPISetVariable(_ptr, variableName, value)) { throw new ArgumentException($"Unable to set {variableName} to {value}"); } } public string GetUTF8Text() { using VectorOfByte vectorOfByte = new VectorOfByte(); OcrInvoke.cveTessBaseAPIGetUTF8Text(_ptr, vectorOfByte); return UtfByteVectorToString(vectorOfByte); } public string GetTSVText(int pageNumber = 0) { using VectorOfByte vectorOfByte = new VectorOfByte(); OcrInvoke.cveTessBaseAPIGetTSVText(_ptr, pageNumber, vectorOfByte); return UtfByteVectorToString(vectorOfByte); } public string GetBoxText(int pageNumber = 0) { using VectorOfByte vectorOfByte = new VectorOfByte(); OcrInvoke.cveTessBaseAPIGetBoxText(_ptr, pageNumber, vectorOfByte); return UtfByteVectorToString(vectorOfByte); } public string GetUNLVText(int pageNumber = 0) { using VectorOfByte vectorOfByte = new VectorOfByte(); OcrInvoke.cveTessBaseAPIGetUNLVText(_ptr, vectorOfByte); return UtfByteVectorToString(vectorOfByte); } public string GetOsdText(int pageNumber = 0) { using VectorOfByte vectorOfByte = new VectorOfByte(); OcrInvoke.cveTessBaseAPIGetOsdText(_ptr, pageNumber, vectorOfByte); return UtfByteVectorToString(vectorOfByte); } public string GetHOCRText(int pageNumber = 0) { using VectorOfByte vectorOfByte = new VectorOfByte(); OcrInvoke.cveTessBaseAPIGetHOCRText(_ptr, pageNumber, vectorOfByte); return UtfByteVectorToString(vectorOfByte); } private string UtfByteVectorToString(VectorOfByte bytes) { byte[] array = bytes.ToArray(); return _utf8.GetString(array, 0, array.Length).Replace("\n", Environment.NewLine); } public Character[] GetCharacters() { using VectorOfByte vectorOfByte = new VectorOfByte(); using VectorOfTesseractResult vectorOfTesseractResult = new VectorOfTesseractResult(); OcrInvoke.cveTessBaseAPIExtractResult(_ptr, vectorOfByte, vectorOfTesseractResult); byte[] bytes = vectorOfByte.ToArray(); TesseractResult[] array = vectorOfTesseractResult.ToArray(); Character[] array2 = new Character[array.Length]; int num = 0; for (int i = 0; i < array.Length; i++) { TesseractResult tesseractResult = array[i]; array2[i].Text = _utf8.GetString(bytes, num, tesseractResult.Length).Replace("\n", Environment.NewLine); num += tesseractResult.Length; array2[i].Cost = tesseractResult.Confident; if (tesseractResult.Confident == 0f) { array2[i].Region = Rectangle.Empty; } else { array2[i].Region = tesseractResult.Region; } } return array2; } public bool ProcessPage(Pix pix, int pageIndex, string filename, string retryConfig, int timeoutMillisec, ITessResultRenderer renderer) { using CvString cvString = new CvString(filename); using CvString cvString2 = new CvString(retryConfig); return OcrInvoke.cveTessBaseAPIProcessPage(_ptr, pix, pageIndex, cvString, cvString2, timeoutMillisec, renderer.TessResultRendererPtr); } public PageIterator AnalyseLayout(bool mergeSimilarWords = false) { return new PageIterator(OcrInvoke.cveTessBaseAPIAnalyseLayout(_ptr, mergeSimilarWords)); } } public struct TesseractResult { public int Length; public float Confident; public Rectangle Region; } public class PDFRenderer : UnmanagedObject, ITessResultRenderer { private IntPtr _tessResultRendererPtr; public IntPtr TessResultRendererPtr => _tessResultRendererPtr; public PDFRenderer(string outputBase, string dataDir, bool textOnly) { using CvString cvString = new CvString(outputBase); using CvString cvString2 = new CvString(dataDir); _ptr = OcrInvoke.cveTessPDFRendererCreate(cvString, cvString2, textOnly, ref _tessResultRendererPtr); } protected override void DisposeObject() { if (IntPtr.Zero != _ptr) { OcrInvoke.cveTessPDFRendererRelease(ref _ptr); } _tessResultRendererPtr = IntPtr.Zero; } } [Serializable] [DebuggerTypeProxy(typeof(DebuggerProxy))] public class VectorOfTesseractResult : UnmanagedVector, ISerializable, IInputOutputArray, IInputArray, IDisposable, IOutputArray, IInputArrayOfArrays, IOutputArrayOfArrays { internal class DebuggerProxy { private VectorOfTesseractResult _v; public TesseractResult[] Values => _v.ToArray(); public DebuggerProxy(VectorOfTesseractResult v) { _v = v; } } private readonly bool _needDispose; public override int Size => VectorOfTesseractResultGetSize(_ptr); public override IntPtr StartAddress => VectorOfTesseractResultGetStartAddress(_ptr); public override long Length => VectorOfTesseractResultGetMemorySize(_ptr); public TesseractResult this[int index] { get { TesseractResult element = default(TesseractResult); VectorOfTesseractResultGetItem(_ptr, index, ref element); return element; } } public static int SizeOfItemInBytes => VectorOfTesseractResultSizeOfItemInBytes(); static VectorOfTesseractResult() { CvInvoke.Init(); } public VectorOfTesseractResult(SerializationInfo info, StreamingContext context) : this() { Push((TesseractResult[])info.GetValue("TesseractResultArray", typeof(TesseractResult[]))); } public void GetObjectData(SerializationInfo info, StreamingContext context) { info.AddValue("TesseractResultArray", ToArray()); } public VectorOfTesseractResult() : this(VectorOfTesseractResultCreate(), needDispose: true) { } internal VectorOfTesseractResult(IntPtr ptr, bool needDispose) { _ptr = ptr; _needDispose = needDispose; } public VectorOfTesseractResult(int size) : this(VectorOfTesseractResultCreateSize(size), needDispose: true) { } public VectorOfTesseractResult(TesseractResult[] values) : this() { Push(values); } public void Push(TesseractResult[] value) { if (value.Length != 0) { GCHandle gCHandle = GCHandle.Alloc(value, GCHandleType.Pinned); VectorOfTesseractResultPushMulti(_ptr, gCHandle.AddrOfPinnedObject(), value.Length); gCHandle.Free(); } } public void Push(VectorOfTesseractResult other) { VectorOfTesseractResultPushVector(_ptr, other); } public TesseractResult[] ToArray() { TesseractResult[] array = new TesseractResult[Size]; if (array.Length != 0) { GCHandle gCHandle = GCHandle.Alloc(array, GCHandleType.Pinned); VectorOfTesseractResultCopyData(_ptr, gCHandle.AddrOfPinnedObject()); gCHandle.Free(); } return array; } public void Clear() { VectorOfTesseractResultClear(_ptr); } protected override void DisposeObject() { if (_needDispose && _ptr != IntPtr.Zero) { VectorOfTesseractResultRelease(ref _ptr); } } public InputArray GetInputArray() { return new InputArray(cveInputArrayFromVectorOfTesseractResult(_ptr), this); } public OutputArray GetOutputArray() { return new OutputArray(cveOutputArrayFromVectorOfTesseractResult(_ptr), this); } public InputOutputArray GetInputOutputArray() { return new InputOutputArray(cveInputOutputArrayFromVectorOfTesseractResult(_ptr), this); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr VectorOfTesseractResultCreate(); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr VectorOfTesseractResultCreateSize(int size); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfTesseractResultRelease(ref IntPtr v); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int VectorOfTesseractResultGetSize(IntPtr v); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfTesseractResultCopyData(IntPtr v, IntPtr data); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr VectorOfTesseractResultGetStartAddress(IntPtr v); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern long VectorOfTesseractResultGetMemorySize(IntPtr v); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfTesseractResultPushMulti(IntPtr v, IntPtr values, int count); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfTesseractResultPushVector(IntPtr ptr, IntPtr otherPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfTesseractResultClear(IntPtr v); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfTesseractResultGetItem(IntPtr vec, int index, ref TesseractResult element); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int VectorOfTesseractResultSizeOfItemInBytes(); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveInputArrayFromVectorOfTesseractResult(IntPtr vec); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveOutputArrayFromVectorOfTesseractResult(IntPtr vec); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveInputOutputArrayFromVectorOfTesseractResult(IntPtr vec); void IDisposable.Dispose() { Dispose(); } } } namespace Emgu.CV.CvEnum { public enum AccessType { Read = 16777216, Write = 33554432, ReadWrite = 50331648, Mask = 50331648, Fast = 67108864 } public enum AdaptiveThresholdType { MeanC, GaussianC } public enum BackOrFront { Back, Front } public enum BorderType { NegativeOne = -1, Constant = 0, Replicate = 1, Reflect = 2, Wrap = 3, Reflect101 = 4, Transparent = 5, Default = 4, Isolated = 16 } [Flags] public enum CalibCbType { Default = 0, AdaptiveThresh = 1, NormalizeImage = 2, FilterQuads = 4, FastCheck = 8, Exhaustive = 0x10, Accuracy = 0x20 } [Flags] public enum CalibCgType { SymmetricGrid = 1, AsymmetricGrid = 2, Clustering = 4 } [Flags] public enum CalibType { Default = 0, UseIntrinsicGuess = 1, FixAspectRatio = 2, FixPrincipalPoint = 4, ZeroTangentDist = 8, FixFocalLength = 0x10, FixK1 = 0x20, FixK2 = 0x40, FixK3 = 0x80, FixK4 = 0x800, FixK5 = 0x1000, FixK6 = 0x2000, RationalModel = 0x4000, ThinPrismModel = 0x8000, FixS1S2S3S4 = 0x10000, TiltedModel = 0x40000, FixTauxTauy = 0x80000, UseQR = 0x100000, FixIntrinsic = 0x100, SameFocalLength = 0x200, ZeroDisparity = 0x400, UseLU = 0x20000 } public enum CapProp { DC1394Off = -4, DC1394ModeManual = -3, DC1394ModeAuto = -2, DC1394ModeOnePushAuto = -1, PosMsec = 0, PosFrames = 1, PosAviRatio = 2, FrameWidth = 3, FrameHeight = 4, Fps = 5, FourCC = 6, FrameCount = 7, Format = 8, Mode = 9, Brightness = 10, Contrast = 11, Saturation = 12, Hue = 13, Gain = 14, Exposure = 15, ConvertRgb = 16, WhiteBalanceBlueU = 17, Rectification = 18, Monochrome = 19, Sharpness = 20, AutoExposure = 21, Gamma = 22, Temperature = 23, Trigger = 24, TriggerDelay = 25, WhiteBalanceRedV = 26, Zoom = 27, Focus = 28, Guid = 29, IsoSpeed = 30, MaxDC1394 = 31, Backlight = 32, Pan = 33, Tilt = 34, Roll = 35, Iris = 36, Settings = 37, Buffersize = 38, Autofocus = 39, SarNum = 40, SarDen = 41, Backend = 42, Channel = 43, AutoWb = 44, WbTemperature = 45, CodecPixelFormat = 46, Bitrate = 47, OrientationMeta = 48, OrientationAuto = 49, HwAcceleration = 50, HwDevice = 51, HwAccelerationUseOpencl = 52, OpenTimeoutMsec = 53, ReadTimeoutMsec = 54, StreamOpenTimeUsec = 55, VideoTotalChannels = 56, VideoStream = 57, AudioStream = 58, AudioPos = 59, AudioShiftNsec = 60, AudioDataDepth = 61, AudioSamplesPerSecond = 62, AudioBaseIndex = 63, AudioTotalChannels = 64, AudioTotalStreams = 65, AudioSynchronize = 66, LrfHasKeyFrame = 67, CodecExtradataIndex = 68, Autograb = 1024, SupportedPreviewSizesString = 1025, PreviewFormat = 1026, OpenniDepthGenerator = int.MinValue, OpenniImageGenerator = 1073741824, OpenniIRGenerator = 536870912, OpenniGeneratorsMask = -536870912, OpenniOutputMode = 100, OpenniFrameMaxDepth = 101, OpenniBaseline = 102, OpenniFocalLength = 103, OpenniRegistration = 104, OpenniRegistrationOn = 104, OpenniApproxFrameSync = 105, OpenniMaxBufferSize = 106, OpenniCircleBuffer = 107, OpenniMaxTimeDuration = 108, OpenniGeneratorPresent = 109, Openni2Sync = 110, Openni2Mirror = 111, OpenniImageGeneratorPresent = 1073741933, OpenniImageGeneratorOutputMode = 1073741924, OpenniDepthGeneratorPresent = -2147483539, OpenniDepthGeneratorBaseline = -2147483546, OpenniDepthGeneratorFocalLength = -2147483545, OpenniDepthGeneratorRegistration = -2147483544, OpenniDepthGeneratorRegistrationOn = -2147483544, OpenniIRGeneratorPresent = 536871021, GstreamerQueueLength = 200, PvapiMulticastip = 300, PvapiFrameStartTriggerMode = 301, PvapiDecimationHorizontal = 302, PvapiDecimationVertical = 303, PvapiBinningX = 304, PvapiBinningY = 305, PvapiPixelFormat = 306, XiDownsampling = 400, XiDataFormat = 401, XiOffsetX = 402, XiOffsetY = 403, XiTrgSource = 404, XiTrgSoftware = 405, XiGpiSelector = 406, XiGpiMode = 407, XiGpiLevel = 408, XiGpoSelector = 409, XiGpoMode = 410, XiLedSelector = 411, XiLedMode = 412, XiManualWb = 413, XiAutoWb = 414, XiAeag = 415, XiExpPriority = 416, XiAeMaxLimit = 417, XiAgMaxLimit = 418, XiAeagLevel = 419, XiTimeout = 420, XiExposure = 421, XiExposureBurstCount = 422, XiGainSelector = 423, XiGain = 424, XiDownsamplingType = 426, XiBinningSelector = 427, XiBinningVertical = 428, XiBinningHorizontal = 429, XiBinningPattern = 430, XiDecimationSelector = 431, XiDecimationVertical = 432, XiDecimationHorizontal = 433, XiDecimationPattern = 434, XiTestPatternGeneratorSelector = 587, XiTestPattern = 588, XiImageDataFormat = 435, XiShutterType = 436, XiSensorTaps = 437, XiAeagRoiOffsetX = 439, XiAeagRoiOffsetY = 440, XiAeagRoiWidth = 441, XiAeagRoiHeight = 442, XiBpc = 445, XiWbKr = 448, XiWbKg = 449, XiWbKb = 450, XiWidth = 451, XiHeight = 452, XiRegionSelector = 589, XiRegionMode = 595, XiLimitBandwidth = 459, XiSensorDataBitDepth = 460, XiOutputDataBitDepth = 461, XiImageDataBitDepth = 462, XiOutputDataPacking = 463, XiOutputDataPackingType = 464, XiIsCooled = 465, XiCooling = 466, XiTargetTemp = 467, XiChipTemp = 468, XiHousTemp = 469, XiHousBackSideTemp = 590, XiSensorBoardTemp = 596, XiCms = 470, XiApplyCms = 471, XiImageIsColor = 474, XiColorFilterArray = 475, XiGammay = 476, XiGammac = 477, XiSharpness = 478, XiCcMatrix00 = 479, XiCcMatrix01 = 480, XiCcMatrix02 = 481, XiCcMatrix03 = 482, XiCcMatrix10 = 483, XiCcMatrix11 = 484, XiCcMatrix12 = 485, XiCcMatrix13 = 486, XiCcMatrix20 = 487, XiCcMatrix21 = 488, XiCcMatrix22 = 489, XiCcMatrix23 = 490, XiCcMatrix30 = 491, XiCcMatrix31 = 492, XiCcMatrix32 = 493, XiCcMatrix33 = 494, XiDefaultCcMatrix = 495, XiTrgSelector = 498, XiAcqFrameBurstCount = 499, XiDebounceEn = 507, XiDebounceT0 = 508, XiDebounceT1 = 509, XiDebouncePol = 510, XiLensMode = 511, XiLensApertureValue = 512, XiLensFocusMovementValue = 513, XiLensFocusMove = 514, XiLensFocusDistance = 515, XiLensFocalLength = 516, XiLensFeatureSelector = 517, XiLensFeature = 518, XiDeviceModelId = 521, XiDeviceSn = 522, XiImageDataFormatRgb32Alpha = 529, XiImagePayloadSize = 530, XiTransportPixelFormat = 531, XiSensorClockFreqHz = 532, XiSensorClockFreqIndex = 533, XiSensorOutputChannelCount = 534, XiFramerate = 535, XiCounterSelector = 536, XiCounterValue = 537, XiAcqTimingMode = 538, XiAvailableBandwidth = 539, XiBufferPolicy = 540, XiLutEn = 541, XiLutIndex = 542, XiLutValue = 543, XiTrgDelay = 544, XiTsRstMode = 545, XiTsRstSource = 546, XiIsDeviceExist = 547, XiAcqBufferSize = 548, XiAcqBufferSizeUnit = 549, XiAcqTransportBufferSize = 550, XiBuffersQueueSize = 551, XiAcqTransportBufferCommit = 552, XiRecentFrame = 553, XiDeviceReset = 554, XiColumnFpnCorrection = 555, XiRowFpnCorrection = 591, XiSensorMode = 558, XiHdr = 559, XiHdrKneepointCount = 560, XiHdrT1 = 561, XiHdrT2 = 562, XiKneepoint1 = 563, XiKneepoint2 = 564, XiImageBlackLevel = 565, XiHwRevision = 571, XiDebugLevel = 572, XiAutoBandwidthCalculation = 573, XiFfsFileId = 594, XiFfsFileSize = 580, XiFreeFfsSize = 581, XiUsedFfsSize = 582, XiFfsAccessKey = 583, XiSensorFeatureSelector = 585, XiSensorFeatureValue = 586, AndroidFlashMode = 8001, AndroidFocusMode = 8002, AndroidWhiteBalance = 8003, AndroidAntibanding = 8004, AndroidFocalLength = 8005, AndroidFocusDistanceNear = 8006, AndroidFocusDistanceOptimal = 8007, AndroidFocusDistanceFar = 8008, AndroidExposeLock = 8009, AndroidWhitebalanceLock = 8010, IOSDeviceFocus = 9001, IOSDeviceExposure = 9002, IOSDeviceFlash = 9003, IOSDeviceWhitebalance = 9004, IOSDeviceTorch = 9005, GigaFrameOffsetX = 10001, GigaFrameOffsetY = 10002, GigaFrameWidthMax = 10003, GigaFrameHeighMax = 10004, GigaFrameSensWidth = 10005, GigaFrameSensHeigh = 10006, IntelpercProfileCount = 11001, IntelpercProfileIdx = 11002, IntelpercDepthLowConfidenceValue = 11003, IntelpercDepthSaturationValue = 11004, IntelpercDepthConfidenceThreshold = 11005, IntelpercDepthFocalLengthHorz = 11006, IntelpercDepthFocalLengthVert = 11007, IntelpercDepthGenerator = 536870912, IntelpercImageGenerator = 268435456, IntelpercGeneratorsMask = 805306368, Gphoto2Preview = 17001, Gphoto2WidgetEnumerate = 17002, Gphoto2ReloadConfig = 17003, Gphoto2ReloadOnChange = 17004, Gphoto2CollectMsgs = 17005, Gphoto2FlushMsgs = 17006, Gphoto2Speed = 17007, Gphoto2Aperture = 17008, Gphoto2Exposureprogram = 17009, Gphoto2Viewfinder = 17010 } public enum ChainApproxMethod { ChainCode, ChainApproxNone, ChainApproxSimple, ChainApproxTc89L1, ChainApproxTc89Kcos, LinkRuns } [Flags] public enum CheckType { NanInfinity = 0, Range = 1, Quite = 2 } public enum CloningMethod { Normal = 1, Mixed, MonochromeTransfer } public enum CmpType { Equal, GreaterThan, GreaterEqual, LessThan, LessEqual, NotEqual } public enum ColorConversion { Bgr2Bgra = 0, Rgb2Rgba = 0, Bgra2Bgr = 1, Rgba2Rgb = 1, Bgr2Rgba = 2, Rgb2Bgra = 2, Rgba2Bgr = 3, Bgra2Rgb = 3, Bgr2Rgb = 4, Rgb2Bgr = 4, Bgra2Rgba = 5, Rgba2Bgra = 5, Bgr2Gray = 6, Rgb2Gray = 7, Gray2Bgr = 8, Gray2Rgb = 8, Gray2Bgra = 9, Gray2Rgba = 9, Bgra2Gray = 10, Rgba2Gray = 11, Bgr2Bgr565 = 12, Rgb2Bgr565 = 13, Bgr5652Bgr = 14, Bgr5652Rgb = 15, Bgra2Bgr565 = 16, Rgba2Bgr565 = 17, Bgr5652Bgra = 18, Bgr5652Rgba = 19, Gray2Bgr565 = 20, Bgr5652Gray = 21, Bgr2Bgr555 = 22, Rgb2Bgr555 = 23, Bgr5552Bgr = 24, Bgr5552Rgb = 25, Bgra2Bgr555 = 26, Rgba2Bgr555 = 27, Bgr5552Bgra = 28, Bgr5552Rgba = 29, Gray2Bgr555 = 30, Bgr5552Gray = 31, Bgr2Xyz = 32, Rgb2Xyz = 33, Xyz2Bgr = 34, Xyz2Rgb = 35, Bgr2YCrCb = 36, Rgb2YCrCb = 37, YCrCb2Bgr = 38, YCrCb2Rgb = 39, Bgr2Hsv = 40, Rgb2Hsv = 41, Bgr2Lab = 44, Rgb2Lab = 45, BayerBg2Bgr = 46, BayerGb2Bgr = 47, BayerRg2Bgr = 48, BayerGr2Bgr = 49, BayerBg2Rgb = 48, BayerGb2Rgb = 49, BayerRg2Rgb = 46, BayerGr2Rgb = 47, BayerRggb2Bgr = 46, BayerGrbg2Bgr = 47, BayerBggr2Bgr = 48, BayerGbrg2Bgr = 49, BayerRggb2Rgb = 48, BayerGrbg2Rgb = 49, BayerBggr2Rgb = 46, BayerGbrg2Rgb = 47, Bgr2Luv = 50, Rgb2Luv = 51, Bgr2Hls = 52, Rgb2Hls = 53, Hsv2Bgr = 54, Hsv2Rgb = 55, Lab2Bgr = 56, Lab2Rgb = 57, Luv2Bgr = 58, Luv2Rgb = 59, Hls2Bgr = 60, Hls2Rgb = 61, BayerBg2BgrVng = 62, BayerGb2BgrVng = 63, BayerRg2BgrVng = 64, BayerGr2BgrVng = 65, BayerBg2RgbVng = 64, BayerGb2RgbVng = 65, BayerRg2RgbVng = 62, BayerGr2RgbVng = 63, BayerRggb2BgrVng = 62, BayerGrbg2BgrVng = 63, BayerBggr2BgrVng = 64, BayerGbrg2BgrVng = 65, BayerRggb2RgbVng = 64, BayerGrbg2RgbVng = 65, BayerBggr2RgbVng = 62, BayerGbrg2RgbVng = 63, Bgr2HsvFull = 66, Rgb2HsvFull = 67, Bgr2HlsFull = 68, Rgb2HlsFull = 69, Hsv2BgrFull = 70, Hsv2RgbFull = 71, Hls2BgrFull = 72, Hls2RgbFull = 73, Lbgr2Lab = 74, Lrgb2Lab = 75, Lbgr2Luv = 76, Lrgb2Luv = 77, Lab2Lbgr = 78, Lab2Lrgb = 79, Luv2Lbgr = 80, Luv2Lrgb = 81, Bgr2Yuv = 82, Rgb2Yuv = 83, Yuv2Bgr = 84, Yuv2Rgb = 85, BayerBg2Gray = 86, BayerGb2Gray = 87, BayerRg2Gray = 88, BayerGr2Gray = 89, BayerRggb2Gray = 86, BayerGrbg2Gray = 87, BayerBggr2Gray = 88, BayerGbrg2Gray = 89, Yuv2RgbNv12 = 90, Yuv2BgrNv12 = 91, Yuv2RgbNv21 = 92, Yuv2BgrNv21 = 93, Yuv420sp2Rgb = 92, Yuv420sp2Bgr = 93, Yuv2RgbaNv12 = 94, Yuv2BgraNv12 = 95, Yuv2RgbaNv21 = 96, Yuv2BgraNv21 = 97, Yuv420sp2Rgba = 96, Yuv420sp2Bgra = 97, Yuv2RgbYv12 = 98, Yuv2BgrYv12 = 99, Yuv2RgbIyuv = 100, Yuv2BgrIyuv = 101, Yuv2RgbI420 = 100, Yuv2BgrI420 = 101, Yuv420P2Rgb = 98, Yuv420P2Bgr = 99, Yuv2RgbaYv12 = 102, Yuv2BgraYv12 = 103, Yuv2RgbaIyuv = 104, Yuv2BgraIyuv = 105, Yuv2RgbaI420 = 104, Yuv2BgraI420 = 105, Yuv420P2Rgba = 102, Yuv420P2Bgra = 103, Yuv2Gray420 = 106, Yuv2GrayNv21 = 106, Yuv2GrayNv12 = 106, Yuv2GrayYv12 = 106, Yuv2GrayIyuv = 106, Yuv2GrayI420 = 106, Yuv420Sp2Gray = 106, Yuv420P2Gray = 106, Yuv2RgbUyvy = 107, Yuv2BgrUyvy = 108, Yuv2RgbY422 = 107, Yuv2BgrY422 = 108, Yuv2RgbUynv = 107, Yuv2BgrUynv = 108, Yuv2RgbaUyvy = 111, Yuv2BgraUyvy = 112, Yuv2RgbaY422 = 111, Yuv2BgraY422 = 112, Yuv2RgbaUynv = 111, Yuv2BgraUynv = 112, Yuv2RgbYuy2 = 115, Yuv2BgrYuy2 = 116, Yuv2RgbYvyu = 117, Yuv2BgrYvyu = 118, Yuv2RgbYuyv = 115, Yuv2BgrYuyv = 116, Yuv2RgbYunv = 115, Yuv2BgrYunv = 116, Yuv2RgbaYuy2 = 119, Yuv2BgraYuy2 = 120, Yuv2RgbaYvyu = 121, Yuv2BgraYvyu = 122, Yuv2RgbaYuyv = 119, Yuv2BgraYuyv = 120, Yuv2RgbaYunv = 119, Yuv2BgraYunv = 120, Yuv2GrayUyvy = 123, Yuv2GrayYuy2 = 124, Yuv2GrayY422 = 123, Yuv2GrayUynv = 123, Yuv2GrayYvyu = 124, Yuv2GrayYuyv = 124, Yuv2GrayYunv = 124, Rgba2MRgba = 125, MRgba2Rgba = 126, Rgb2YuvI420 = 127, Bgr2YuvI420 = 128, Rgb2YuvIyuv = 127, Bgr2YuvIyuv = 128, Rgba2YuvI420 = 129, Bgra2YuvI420 = 130, Rgba2YuvIyuv = 129, Bgra2YuvIyuv = 130, Rgb2YuvYv12 = 131, Bgr2YuvYv12 = 132, Rgba2YuvYv12 = 133, Bgra2YuvYv12 = 134, BayerBg2BgrEa = 135, BayerGb2BgrEa = 136, BayerRg2BgrEa = 137, BayerGr2BgrEa = 138, BayerBg2RgbEa = 137, BayerGb2RgbEa = 138, BayerRg2RgbEa = 135, BayerGr2RgbEa = 136, BayerRggb2BgrEa = 135, BayerGrbg2BgrEa = 136, BayerBggr2BgrEa = 137, BayerGbrg2BgrEa = 138, BayerRggb2RgbEa = 137, BayerGrbg2RgbEa = 138, BayerBggr2RgbEa = 135, BayerGbrg2RgbEa = 136, BayerBg2Bgra = 139, BayerGb2Bgra = 140, BayerRg2Bgra = 141, BayerGr2Bgra = 142, BayerRggb2Bgra = 139, BayerGrbg2Bgra = 140, BayerBggr2Bgra = 141, BayerGbrg2Bgra = 142, BayerRggb2Rgba = 141, BayerGrbg2Rgba = 142, BayerBggr2Rgba = 139, BayerGbrg2Rgba = 140, BayerBg2Rgba = 141, BayerGb2Rgba = 142, BayerRg2Rgba = 139, BayerGr2Rgba = 140, ColorCvtMax = 143 } public enum ColorMapType { Autumn, Bone, Jet, Winter, Rainbow, Ocean, Summer, Spring, Cool, Hsv, Pink, Hot, Parula, Magma, Inferno, Plasma, Viridis, Cividis, Twilight, TwilightShifted, Turbo } public enum ConnectedComponentsAlgorithmsTypes { Default = -1, Wu, Grana, Bolelli, Sauf, Bbdt, Spaghetti } public enum ConnectedComponentsTypes { Left, Top, Width, Height, Area, Max } public enum Connectivity { EightConnected = 8, FourConnected = 4 } public enum ContoursMatchType { I1 = 1, I2, I3 } [Flags] public enum CovarMethod { Scrambled = 0, Normal = 1, UseAvg = 2, Scale = 4, Rows = 8, Cols = 0x10 } public enum DctType { Forward = 0, Inverse = 1, Rows = 4 } public enum DecompMethod { LU = 0, Svd = 1, Eig = 2, Cholesky = 3, QR = 4, Normal = 16 } public enum DepthType { Default = -1, Cv8U, Cv8S, Cv16U, Cv16S, Cv32S, Cv32F, Cv64F } public enum DistLabelType { CComp, Pixel } public enum DistType { User = -1, L1 = 1, L2 = 2, C = 3, L12 = 4, Fair = 5, Welsch = 6, Huber = 7 } [Flags] public enum DxtType { Forward = 0, Inverse = 1, Scale = 2, Rows = 4, InvScale = 3 } public enum EdgePreservingFilterFlag { RecursFilter = 1, NormconvFilter } public enum EigobjType { NoCallback, InputCallback, OutputCallback, BothCallback } public enum ElementShape { Rectangle = 0, Cross = 1, Ellipse = 2, Custom = 100 } public enum ErrorCodes { StsOk = 0, StsBacktrace = -1, StsError = -2, StsInternal = -3, StsNoMem = -4, StsBadArg = -5, StsBadFunc = -6, StsNoConv = -7, StsAutoTrace = -8, HeaderIsNull = -9, BadImageSize = -10, BadOffset = -11, BadDataPtr = -12, Badstep = -13, BadModelOrChseq = -14, BadNumChannels = -15, BadNumChannel1U = -16, BadDepth = -17, BadAlphaChannel = -18, BadOrder = -19, BadOrigin = -20, BadAlign = -21, BadCallback = -22, BadTileSize = -23, BadCoi = -24, BadRoiSize = -25, MaskIsTiled = -26, StsNullPtr = -27, StsVecLengthErr = -28, StsFilterStructContenterr = -29, StsKernelStructContenterr = -30, StsFilterOffSetErr = -31, StsBadSize = -201, StsDivByZero = -202, StsInplaceNotSupported = -203, StsObjectNotFound = -204, StsUnmatchedFormats = -205, StsBadFlag = -206, StsBadPoint = -207, StsBadMask = -208, StsUnmatchedSizes = -209, StsUnsupportedFormat = -210, StsOutOfRange = -211, StsParseError = -212, StsNotImplemented = -213, StsBadMemBlock = -214 } public enum FlipType { Vertical = 0, Horizontal = 1, Both = -1 } [Flags] public enum FloodFillType { Default = 0, FixedRange = 0x10000, MaskOnly = 0x20000 } [Flags] public enum FmType { SevenPoint = 1, EightPoint = 2, LMedsOnly = 4, RansacOnly = 8, LMeds = 6, Ransac = 0xA } public enum FontFace { HersheySimplex, HersheyPlain, HersheyDuplex, HersheyComplex, HersheyTriplex, HersheyComplexSmall, HersheyScriptSimplex, HersheyScriptComplex } [Flags] public enum GemmType { Default = 0, Src1Transpose = 1, Src2Transpose = 2, Src3Transpose = 4 } public enum General { MaxDim = 32, SeqMagicVal = 1117323264, SetMagicVal = 1117257728 } public enum GrabcutInitType { InitWithRect, InitWithMask, Eval } [Flags] public enum HaarDetectionType { Default = 0, DoCannyPruning = 1, ScaleImage = 2, FindBiggestObject = 4, DoRoughSearch = 8 } public enum HandEyeCalibrationMethod { Tsai, Park, Horaud, Andreff, Daniilidis } public enum HistogramCompMethod { Correl = 0, Chisqr = 1, Intersect = 2, Bhattacharyya = 3, Hellinger = 3, ChisqrAlt = 4 } public enum HoughModes { Standard, Probabilistic, MultiScale, Gradient, GradientAlt } [Flags] public enum ImreadModes { Unchanged = -1, Grayscale = 0, Color = 1, AnyDepth = 2, AnyColor = 4, LoadGdal = 8, ReducedGrayscale2 = 0x10, ReducedColor2 = 0x11, ReducedGrayscale4 = 0x20, ReducedColor4 = 0x21, ReducedGrayscale8 = 0x40, ReducedColor8 = 0x41, IgnoreOrientation = 0x80 } [Flags] public enum ImwriteFlags { JpegQuality = 1, JpegProgressive = 2, JpegOptimize = 3, JpegRstInterval = 4, JpegLumaQuality = 5, JpegChromaQuality = 6, PngCompression = 0x10, PngStrategy = 0x11, PngBilevel = 0x12, PxmBinary = 0x20, ExrType = 0x30, ExrCompression = 0x31, WebpQuality = 0x40, PamTupletype = 0x80, TiffResunit = 0x100, TiffXdpi = 0x101, TiffYdpi = 0x102, TiffCompression = 0x103, Jpeg2000CompressionX1000 = 0x110 } public enum InpaintType { NS, Telea } public enum Inter { Nearest, Linear, Cubic, Area, Lanczos4, LinearExact, NearestExact } public enum IplDepth : uint { IplDepthSign = 2147483648u, IplDepth_1U = 1u, IplDepth_8U = 8u, IplDepth16U = 16u, IplDepth32F = 32u, IplDepth_8S = 2147483656u, IplDepth16S = 2147483664u, IplDepth32S = 2147483680u, IplDepth64F = 64u } public enum KMeansInitType { RandomCenters, UseInitialLabels, PPCenters } public enum LineType { Filled = -1, EightConnected = 8, FourConnected = 4, AntiAlias = 16 } public enum LKFlowFlag { Default = 0, UserInitialFlow = 4, LKGetMinEigenvals = 8 } public enum LogLevel { Silent, Fatal, Error, Warning, Info, Debug, Verbose } public enum MarkerTypes { Cross, TiltedCross, Star, Diamond, Square, TriangleUp, TriangleDown } public enum MorphOp { Erode, Dilate, Open, Close, Gradient, Tophat, Blackhat, HitMiss } public enum MotionType { Translation, Euclidean, Affine, Homography } [Flags] public enum MulSpectrumsType { Default = 0, DxtRows = 4, DxtMulConj = 8 } [Flags] public enum NormType { C = 1, L1 = 2, L2 = 4, NormMask = 7, Relative = 8, Diff = 0x10, MinMax = 0x20, DiffC = 0x11, DiffL1 = 0x12, DiffL2 = 0x14, RelativeC = 9, RelativeL1 = 0xA, RelativeL2 = 0xC } [Flags] public enum OpticalflowFarnebackFlag { Default = 0, UseInitialFlow = 4, FarnebackGaussian = 0x100 } public enum Orientation { Clockwise = 1, CounterClockwise } [Flags] public enum PcaType { DataAsRow = 0, DataAsCol = 1, UseAvg = 2 } public enum RectIntersectType { None, Partial, Full } public enum ReduceDimension { SingleRow = 0, SingleCol = 1, Auto = -1 } public enum ReduceType { ReduceSum, ReduceAvg, ReduceMax, ReduceMin } public enum RetrType { External, List, Ccomp, Tree, Floodfill } public enum RobustEstimationAlgorithm { AllPoints = 0, LMEDS = 4, Ransac = 8, RHO = 0x10 } public enum RotateFlags { Rotate90Clockwise, Rotate180, Rotate90CounterClockwise } internal static class SeqConst { public const int EltypeBits = 12; public const int EltypeMask = 4095; public const int KindBits = 2; public const int Shift = 14; } public enum SeqEltype { Point = 12, Code = 0, Generic = 0, Ptr = 7, Ppoint = 7, Index = 4, GraphEdge = 0, GraphVertex = 0, TrainAtr = 0, ConnectedComp = 0, Point3D = 56 } public enum SeqFlag { Closed = 0x4000, Simple = 0x8000, Convex = 0x10000, Hole = 0x20000 } public enum SeqKind { Generic = 0, Curve = 4096, BinTree = 8192, Graph = 4096, Subdiv2D = 8192 } public enum SeqType { PointSet = 12, Point3DSet = 56, Polyline = 4108, Polygon = 20492, SimplePolygon = 53260 } public enum SmoothType { BlurNoScale, Blur, Gaussian, Median, Bilateral } public enum SoftNMSMethod { Linear = 1, Gaussian } public enum SolveLPResult { Unbounded = -2, Unfeasible, Single, Multi } public enum SolvePnpMethod { Iterative, EPnP, P3P, Dls, UPnP, AP3P, IPPE, IPPESquare } [Flags] public enum SortFlags { SortEveryRow = 0, SortEveryColumn = 1, SortAscending = 0, SortDescending = 0x10 } public enum StereoBmPrefilter { NormalizedResponse, XSobel } public enum StereoRectifyType { Default = 0, CalibZeroDisparity = 0x400 } public enum StorageOp { Read, Write, Append } public enum Subdiv2DPointLocationType { Error = -2, OutsideRect, Inside, Vertex, OnEdge } [Flags] public enum SvdFlag { Default = 0, ModifyA = 1, NoUV = 2, FullUV = 4 } public enum TemplateMatchingType { Sqdiff, SqdiffNormed, Ccorr, CcorrNormed, Ccoeff, CcoeffNormed } [Flags] public enum TermCritType { Iter = 1, Eps = 2 } public enum ThresholdType { Binary = 0, BinaryInv = 1, Trunc = 2, ToZero = 3, ToZeroInv = 4, Mask = 7, Otsu = 8, Triangle = 16 } public enum VideoAccelerationType { None, Any, D3D11, VaAPI, Mfx } public enum Warp { Default = 0, FillOutliers = 8, InverseMap = 0x10 } [Flags] public enum WindowFlags { Normal = 0, AutoSize = 1, Opengl = 0x1000, Fullscreen = 1, FreeRatio = 0x100, KeepRatio = 0, GuiExpanded = 0, GuiNormal = 0x10 } [Flags] public enum WindowPropertyFlags { FullScreen = 0, AutoSize = 1, AspectRatio = 2, Opengl = 3, Visible = 4, TopMost = 5 } public enum StereoOutputFormat { DepthFloat16 = 0, DepthFloat32 = 1, DisparityFixed_16_11_5 = 2, DisparityFixed16_12_4 = 3, Depth16F = 0, Depth32F = 1, Disparity_16Q_10_5 = 2, Disparity_16Q_11_4 = 3 } } namespace Emgu.CV.Dnn { public enum Backend { Default = 0, Halide = 1, InferenceEngine = 2, OpenCV = 3, VkCom = 4, Cuda = 5, InferenceEngineNgraph = 1000000, InferenceEngineNnBuilder2019 = 1000001 } public struct BackendTargetPair { public Backend Backend; public Target Target; public BackendTargetPair(Backend backend, Target target) { Backend = backend; Target = target; } } public class ClassificationModel : Model { public ClassificationModel(string model, string config = null) { using CvString cvString = new CvString(model); using CvString cvString2 = new CvString(config); _ptr = DnnInvoke.cveDnnClassificationModelCreate1(cvString, cvString2, ref _model); } public ClassificationModel(Net net) { _ptr = DnnInvoke.cveDnnClassificationModelCreate2(net, ref _model); } public void Classify(IInputArray frame, out int classId, out float conf) { classId = -1; conf = 0f; using InputArray inputArray = frame.GetInputArray(); DnnInvoke.cveDnnClassificationModelClassify(_ptr, inputArray, ref classId, ref conf); } protected override void DisposeObject() { if (_ptr != IntPtr.Zero) { DnnInvoke.cveDnnClassificationModelRelease(ref _ptr); } _model = IntPtr.Zero; } } public static class DnnInvoke { public static BackendTargetPair[] AvailableBackends { get { using VectorOfInt vectorOfInt = new VectorOfInt(); using VectorOfInt vectorOfInt2 = new VectorOfInt(); cveDNNGetAvailableBackends(vectorOfInt, vectorOfInt2); int[] array = vectorOfInt.ToArray(); int[] array2 = vectorOfInt2.ToArray(); BackendTargetPair[] array3 = new BackendTargetPair[array.Length]; for (int i = 0; i < array.Length; i++) { array3[i] = new BackendTargetPair((Backend)array[i], (Target)array2[i]); } return array3; } } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveDnnClassificationModelCreate1(IntPtr model, IntPtr config, ref IntPtr baseModel); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveDnnClassificationModelCreate2(IntPtr network, ref IntPtr baseModel); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveDnnClassificationModelRelease(ref IntPtr model); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveDnnClassificationModelClassify(IntPtr classificationModel, IntPtr frame, ref int classId, ref float conf); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveDnnDetectionModelCreate1(IntPtr model, IntPtr config, ref IntPtr baseModel); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveDnnDetectionModelCreate2(IntPtr network, ref IntPtr baseModel); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveDnnDetectionModelRelease(ref IntPtr model); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveDnnDetectionModelDetect(IntPtr detectionModel, IntPtr frame, IntPtr classIds, IntPtr confidences, IntPtr boxes, float confThreshold, float nmsThreshold); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.U1)] internal static extern bool cveDetectionModelGetNmsAcrossClasses(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveDetectionModelSetNmsAcrossClasses(IntPtr obj, [MarshalAs(UnmanagedType.U1)] bool val); static DnnInvoke() { CvInvoke.Init(); } public static Mat BlobFromImage(IInputArray image, double scaleFactor = 1.0, Size size = default(Size), MCvScalar mean = default(MCvScalar), bool swapRB = false, bool crop = false, DepthType ddepth = DepthType.Cv32F) { Mat mat = new Mat(); BlobFromImage(image, mat, scaleFactor, size, mean, swapRB, crop, ddepth); return mat; } public static void BlobFromImage(IInputArray image, IOutputArray blob, double scaleFactor = 1.0, Size size = default(Size), MCvScalar mean = default(MCvScalar), bool swapRB = false, bool crop = false, DepthType ddepth = DepthType.Cv32F) { using InputArray inputArray = image.GetInputArray(); using OutputArray outputArray = blob.GetOutputArray(); cveDnnBlobFromImage(inputArray, outputArray, scaleFactor, ref size, ref mean, swapRB, crop, ddepth); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveDnnBlobFromImage(IntPtr image, IntPtr blob, double scaleFactor, ref Size size, ref MCvScalar mean, [MarshalAs(UnmanagedType.U1)] bool swapRB, [MarshalAs(UnmanagedType.U1)] bool crop, DepthType ddepth); public static Mat BlobFromImages(Mat[] images, double scaleFactor = 1.0, Size size = default(Size), MCvScalar mean = default(MCvScalar), bool swapRB = false, bool crop = false, DepthType ddepth = DepthType.Cv32F) { Mat mat = new Mat(); using VectorOfMat images2 = new VectorOfMat(images); BlobFromImages(images2, mat, scaleFactor, size, mean, swapRB, crop, ddepth); return mat; } public static void BlobFromImages(IInputArrayOfArrays images, IOutputArray blob, double scaleFactor = 1.0, Size size = default(Size), MCvScalar mean = default(MCvScalar), bool swapRB = false, bool crop = false, DepthType ddepth = DepthType.Cv32F) { using InputArray inputArray = images.GetInputArray(); using OutputArray outputArray = blob.GetOutputArray(); cveDnnBlobFromImages(inputArray, outputArray, scaleFactor, ref size, ref mean, swapRB, crop, ddepth); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveDnnBlobFromImages(IntPtr images, IntPtr blob, double scalefactor, ref Size size, ref MCvScalar mean, [MarshalAs(UnmanagedType.U1)] bool swapRB, [MarshalAs(UnmanagedType.U1)] bool crop, DepthType ddepth); public static void ImagesFromBlob(Mat blob, IOutputArrayOfArrays images) { using OutputArray outputArray = images.GetOutputArray(); cveDnnImagesFromBlob(blob, outputArray); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveDnnImagesFromBlob(IntPtr blob, IntPtr images); public static Net ReadNetFromDarknet(string cfgFile, string darknetModel = null) { using CvString cvString = new CvString(cfgFile); using CvString cvString2 = ((darknetModel == null) ? new CvString() : new CvString(darknetModel)); return new Net(cveReadNetFromDarknet(cvString, cvString2)); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern IntPtr cveReadNetFromDarknet(IntPtr cfgFile, IntPtr darknetModel); public static Net ReadNetFromDarknet(byte[] bufferCfg, byte[] bufferModel = null) { GCHandle gCHandle = GCHandle.Alloc(bufferCfg, GCHandleType.Pinned); GCHandle gCHandle2 = ((bufferModel == null) ? default(GCHandle) : GCHandle.Alloc(bufferModel, GCHandleType.Pinned)); try { return new Net(cveReadNetFromDarknet2(gCHandle.AddrOfPinnedObject(), bufferCfg.Length, (bufferModel == null) ? IntPtr.Zero : gCHandle2.AddrOfPinnedObject(), (bufferModel != null) ? bufferModel.Length : 0)); } finally { gCHandle.Free(); if (gCHandle2.IsAllocated) { gCHandle2.Free(); } } } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern IntPtr cveReadNetFromDarknet2(IntPtr bufferCfg, int lenCfg, IntPtr bufferModel, int lenModel); public static Net ReadNetFromCaffe(byte[] prototxt, byte[] caffeModel = null) { GCHandle gCHandle = GCHandle.Alloc(prototxt, GCHandleType.Pinned); GCHandle gCHandle2 = ((caffeModel == null) ? default(GCHandle) : GCHandle.Alloc(caffeModel, GCHandleType.Pinned)); try { return new Net(cveReadNetFromCaffe2(gCHandle.AddrOfPinnedObject(), prototxt.Length, (caffeModel == null) ? IntPtr.Zero : gCHandle2.AddrOfPinnedObject(), (caffeModel != null) ? caffeModel.Length : 0)); } finally { gCHandle.Free(); if (gCHandle2.IsAllocated) { gCHandle2.Free(); } } } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern IntPtr cveReadNetFromCaffe2(IntPtr bufferProto, int lenProto, IntPtr bufferModel, int lenModel); public static Net ReadNetFromCaffe(string prototxt, string caffeModel = null) { using CvString cvString = new CvString(prototxt); using CvString cvString2 = ((caffeModel == null) ? new CvString() : new CvString(caffeModel)); return new Net(cveReadNetFromCaffe(cvString, cvString2)); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern IntPtr cveReadNetFromCaffe(IntPtr prototxt, IntPtr caffeModel); public static Net ReadNetFromTensorflow(string model, string config = null) { using CvString cvString = new CvString(model); using CvString cvString2 = ((config == null) ? new CvString() : new CvString(config)); return new Net(cveReadNetFromTensorflow(cvString, cvString2)); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern IntPtr cveReadNetFromTensorflow(IntPtr model, IntPtr config); public static Net ReadNetFromTensorflow(byte[] model, byte[] config = null) { GCHandle gCHandle = GCHandle.Alloc(model, GCHandleType.Pinned); GCHandle gCHandle2 = ((config == null) ? default(GCHandle) : GCHandle.Alloc(config, GCHandleType.Pinned)); try { return new Net(cveReadNetFromTensorflow2(gCHandle.AddrOfPinnedObject(), model.Length, (config == null) ? IntPtr.Zero : gCHandle2.AddrOfPinnedObject(), (config != null) ? config.Length : 0)); } finally { gCHandle.Free(); if (gCHandle2.IsAllocated) { gCHandle2.Free(); } } } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern IntPtr cveReadNetFromTensorflow2(IntPtr bufferModel, int lenModel, IntPtr bufferConfig, int lenConfig); public static Net ReadNetFromONNX(string onnxFile) { using CvString cvString = new CvString(onnxFile); return new Net(cveReadNetFromONNX(cvString)); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern IntPtr cveReadNetFromONNX(IntPtr onnxFile); public static Mat ReadTensorFromONNX(string path) { Mat mat = new Mat(); using CvString cvString = new CvString(path); cveReadTensorFromONNX(cvString, mat); return mat; } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveReadTensorFromONNX(IntPtr path, IntPtr tensor); public static Net ReadNet(string model, string config = null, string framework = null) { using CvString cvString = new CvString(model); using CvString cvString2 = new CvString((config == null) ? string.Empty : config); using CvString cvString3 = new CvString((framework == null) ? string.Empty : framework); return new Net(cveReadNet(cvString, cvString2, cvString3)); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern IntPtr cveReadNet(IntPtr model, IntPtr config, IntPtr framework); public static Net ReadNetFromModelOptimizer(string xml, string bin) { using CvString cvString = new CvString(xml); using CvString cvString2 = new CvString(bin); return new Net(cveReadNetFromModelOptimizer(cvString, cvString2)); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern IntPtr cveReadNetFromModelOptimizer(IntPtr xml, IntPtr bin); public static void ShrinkCaffeModel(string src, string dst) { using CvString cvString = new CvString(src); using CvString cvString2 = new CvString(dst); cveDnnShrinkCaffeModel(cvString, cvString2); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveDnnShrinkCaffeModel(IntPtr src, IntPtr dst); public static void WriteTextGraph(string model, string output) { using CvString cvString = new CvString(model); using CvString cvString2 = new CvString(output); cveDnnWriteTextGraph(cvString, cvString2); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveDnnWriteTextGraph(IntPtr model, IntPtr output); public static int[] NMSBoxes(Rectangle[] bboxes, float[] scores, float scoreThreshold, float nmsThreshold, float eta = 1f, int topK = 0) { using VectorOfRect bboxes2 = new VectorOfRect(bboxes); using VectorOfFloat scores2 = new VectorOfFloat(scores); using VectorOfInt vectorOfInt = new VectorOfInt(); NMSBoxes(bboxes2, scores2, scoreThreshold, nmsThreshold, vectorOfInt, eta, topK); return vectorOfInt.ToArray(); } public static void NMSBoxes(VectorOfRect bboxes, VectorOfFloat scores, float scoreThreshold, float nmsThreshold, VectorOfInt indices, float eta = 1f, int topK = 0) { cveDnnNMSBoxes(bboxes, scores, scoreThreshold, nmsThreshold, indices, eta, topK); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveDnnNMSBoxes(IntPtr bboxes, IntPtr scores, float scoreThreshold, float nmsThreshold, IntPtr indices, float eta, int topK); public static int[] NMSBoxes(RotatedRect[] bboxes, float[] scores, float scoreThreshold, float nmsThreshold, float eta = 1f, int topK = 0) { using VectorOfRotatedRect bboxes2 = new VectorOfRotatedRect(bboxes); using VectorOfFloat scores2 = new VectorOfFloat(scores); using VectorOfInt vectorOfInt = new VectorOfInt(); NMSBoxes(bboxes2, scores2, scoreThreshold, nmsThreshold, vectorOfInt, eta, topK); return vectorOfInt.ToArray(); } public static void NMSBoxes(VectorOfRotatedRect bboxes, VectorOfFloat scores, float scoreThreshold, float nmsThreshold, VectorOfInt indices, float eta = 1f, int topK = 0) { cveDnnNMSBoxes2(bboxes, scores, scoreThreshold, nmsThreshold, indices, eta, topK); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveDnnNMSBoxes2(IntPtr bboxes, IntPtr scores, float scoreThreshold, float nmsThreshold, IntPtr indices, float eta, int topK); public static void SoftNMSBoxes(VectorOfRect bboxes, VectorOfFloat scores, VectorOfFloat updatedScores, float scoreThreshold, float nmsThreshold, VectorOfInt indices, int topK = 0, float sigma = 0.5f, SoftNMSMethod method = SoftNMSMethod.Gaussian) { cveDnnSoftNMSBoxes(bboxes, scores, updatedScores, scoreThreshold, nmsThreshold, indices, topK, sigma, method); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveDnnSoftNMSBoxes(IntPtr bboxes, IntPtr scores, IntPtr updatedScores, float scoreThreshold, float nmsThreshold, IntPtr indices, int topK, float sigma, SoftNMSMethod method); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] private static extern void cveDNNGetAvailableBackends(IntPtr backends, IntPtr targets); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveDnnKeypointsModelCreate1(IntPtr model, IntPtr config, ref IntPtr baseModel); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveDnnKeypointsModelCreate2(IntPtr network, ref IntPtr baseModel); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveDnnKeypointsModelRelease(ref IntPtr model); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveDnnKeypointsModelEstimate(IntPtr keypointsModel, IntPtr frame, IntPtr keypoints, float thresh); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveDnnLayerRelease(ref IntPtr layerPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveDnnLayerGetBlobs(IntPtr layer); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveLayerGetName(IntPtr obj, IntPtr str); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveLayerGetType(IntPtr obj, IntPtr str); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern Target cveLayerGetPreferableTarget(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveModelCreate(IntPtr model, IntPtr config); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveModelCreateFromNet(IntPtr network); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveModelRelease(ref IntPtr model); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveModelPredict(IntPtr model, IntPtr frame, IntPtr outs); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveModelSetInputScale(IntPtr model, double scale); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveModelSetInputMean(IntPtr model, ref MCvScalar mean); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveModelSetInputSize(IntPtr model, ref Size size); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveModelSetInputCrop(IntPtr model, [MarshalAs(UnmanagedType.U1)] bool crop); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveModelSetInputSwapRB(IntPtr model, [MarshalAs(UnmanagedType.U1)] bool swapRB); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveModelSetPreferableBackend(IntPtr model, Backend backendId); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveModelSetPreferableTarget(IntPtr model, Target targetId); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveDnnNetCreate(); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveDnnNetSetInput(IntPtr net, IntPtr blob, IntPtr name, double scaleFactor, ref MCvScalar mean); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveDnnNetForward(IntPtr net, IntPtr outputName, IntPtr output); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveDnnNetForward2(IntPtr net, IntPtr outputBlobs, IntPtr outputName); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveDnnNetForward3(IntPtr net, IntPtr outputBlobs, IntPtr outBlobNames); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveDnnNetRelease(ref IntPtr net); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveDnnNetGetLayerNames(IntPtr net); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int cveDnnGetLayerId(IntPtr net, IntPtr layer); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveDnnGetLayerByName(IntPtr net, IntPtr layerName, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveDnnGetLayerById(IntPtr net, int layerId, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveDnnNetGetUnconnectedOutLayers(IntPtr net, IntPtr layerIds); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveDnnNetGetUnconnectedOutLayersNames(IntPtr net, IntPtr layerNames); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern long cveDnnNetGetPerfProfile(IntPtr net, IntPtr timings); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveDnnNetDump(IntPtr net, IntPtr dnnString); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveDnnNetDumpToFile(IntPtr net, IntPtr path); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveNetSetPreferableBackend(IntPtr obj, Backend val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveNetSetPreferableTarget(IntPtr obj, Target val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveNetEnableFusion(IntPtr obj, [MarshalAs(UnmanagedType.U1)] bool val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.U1)] internal static extern bool cveNetEmpty(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveNetSetHalideScheduler(IntPtr obj, IntPtr str); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveDnnSegmentationModelCreate1(IntPtr model, IntPtr config, ref IntPtr baseModel); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveDnnSegmentationModelCreate2(IntPtr network, ref IntPtr baseModel); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveDnnSegmentationModelRelease(ref IntPtr model); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveDnnSegmentationModelSegment(IntPtr segmentationModel, IntPtr frame, IntPtr mask); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveDnnTextDetectionModelDetect(IntPtr textDetectionModel, IntPtr frame, IntPtr detections, IntPtr confidences); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveDnnTextDetectionModelDetectTextRectangles(IntPtr textDetectionModel, IntPtr frame, IntPtr detections, IntPtr confidences); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveDnnTextDetectionModelDbCreate1(IntPtr model, IntPtr config, ref IntPtr textDetectionModel, ref IntPtr baseModel); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveDnnTextDetectionModelDbCreate2(IntPtr network, ref IntPtr textDetectionModel, ref IntPtr baseModel); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveDnnTextDetectionModelDbRelease(ref IntPtr textDetectionModel); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern float cveTextDetectionModel_DBGetBinaryThreshold(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveTextDetectionModel_DBSetBinaryThreshold(IntPtr obj, float val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern float cveTextDetectionModel_DBGetPolygonThreshold(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveTextDetectionModel_DBSetPolygonThreshold(IntPtr obj, float val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern double cveTextDetectionModel_DBGetUnclipRatio(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveTextDetectionModel_DBSetUnclipRatio(IntPtr obj, double val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int cveTextDetectionModel_DBGetMaxCandidates(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveTextDetectionModel_DBSetMaxCandidates(IntPtr obj, int val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveDnnTextDetectionModelEastCreate1(IntPtr model, IntPtr config, ref IntPtr textDetectionModel, ref IntPtr baseModel); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveDnnTextDetectionModelEastCreate2(IntPtr network, ref IntPtr textDetectionModel, ref IntPtr baseModel); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveDnnTextDetectionModelEastRelease(ref IntPtr textDetectionModel); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern float cveTextDetectionModel_EASTGetConfidenceThreshold(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveTextDetectionModel_EASTSetConfidenceThreshold(IntPtr obj, float val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern float cveTextDetectionModel_EASTGetNMSThreshold(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveTextDetectionModel_EASTSetNMSThreshold(IntPtr obj, float val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveDnnTextRecognitionModelCreate1(IntPtr model, IntPtr config, ref IntPtr baseModel); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveDnnTextRecognitionModelCreate2(IntPtr network, ref IntPtr baseModel); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveDnnTextRecognitionModelRelease(ref IntPtr textDetectionModel); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveDnnTextRecognitionModelSetDecodeOptsCTCPrefixBeamSearch(IntPtr textRecognitionModel, int beamSize, int vocPruneSize); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveDnnTextRecognitionModelSetVocabulary(IntPtr textRecognitionModel, IntPtr vocabulary); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveDnnTextRecognitionModelGetVocabulary(IntPtr textRecognitionModel, IntPtr vocabulary); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveDnnTextRecognitionModelRecognize1(IntPtr textRecognitionModel, IntPtr frame, IntPtr text); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveDnnTextRecognitionModelRecognize2(IntPtr textRecognitionModel, IntPtr frame, IntPtr roiRects, IntPtr results); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveTextRecognitionModelGetDecodeType(IntPtr obj, IntPtr str); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveTextRecognitionModelSetDecodeType(IntPtr obj, IntPtr str); } public class DetectionModel : Model { public bool NmsAcrossClasses { get { return DnnInvoke.cveDetectionModelGetNmsAcrossClasses(_ptr); } set { DnnInvoke.cveDetectionModelSetNmsAcrossClasses(_ptr, value); } } public DetectionModel(string model, string config = null) { using CvString cvString = new CvString(model); using CvString cvString2 = new CvString(config); _ptr = DnnInvoke.cveDnnDetectionModelCreate1(cvString, cvString2, ref _model); } public DetectionModel(Net net) { _ptr = DnnInvoke.cveDnnDetectionModelCreate2(net, ref _model); } public void Detect(IInputArray frame, VectorOfInt classIds, VectorOfFloat confidences, VectorOfRect boxes, float confThreshold = 0.5f, float nmsThreshold = 0f) { using InputArray inputArray = frame.GetInputArray(); DnnInvoke.cveDnnDetectionModelDetect(_ptr, inputArray, classIds, confidences, boxes, confThreshold, nmsThreshold); } protected override void DisposeObject() { if (_ptr != IntPtr.Zero) { DnnInvoke.cveDnnDetectionModelRelease(ref _ptr); } _model = IntPtr.Zero; } } public class KeypointsModel : Model { public KeypointsModel(string model, string config = null) { using CvString cvString = new CvString(model); using CvString cvString2 = new CvString(config); _ptr = DnnInvoke.cveDnnKeypointsModelCreate1(cvString, cvString2, ref _model); } public KeypointsModel(Net net) { _ptr = DnnInvoke.cveDnnKeypointsModelCreate2(net, ref _model); } public PointF[] Estimate(IInputArray frame, float thresh = 0.5f) { using InputArray inputArray = frame.GetInputArray(); using VectorOfPointF vectorOfPointF = new VectorOfPointF(); DnnInvoke.cveDnnKeypointsModelEstimate(_ptr, inputArray, vectorOfPointF, thresh); return vectorOfPointF.ToArray(); } protected override void DisposeObject() { if (_ptr != IntPtr.Zero) { DnnInvoke.cveDnnKeypointsModelRelease(ref _ptr); } _model = IntPtr.Zero; } } public class Layer : SharedPtrObject { public VectorOfMat Blobs => new VectorOfMat(DnnInvoke.cveDnnLayerGetBlobs(_ptr), needDispose: false); public string Name { get { using CvString cvString = new CvString(); DnnInvoke.cveLayerGetName(_ptr, cvString); return cvString.ToString(); } } public string Type { get { using CvString cvString = new CvString(); DnnInvoke.cveLayerGetType(_ptr, cvString); return cvString.ToString(); } } public Target PreferableTarget => DnnInvoke.cveLayerGetPreferableTarget(_ptr); internal Layer(IntPtr sharedPtr, IntPtr ptr) { _sharedPtr = sharedPtr; _ptr = ptr; } protected override void DisposeObject() { IntPtr zero = IntPtr.Zero; if (!zero.Equals((object?)(nint)_sharedPtr)) { DnnInvoke.cveDnnLayerRelease(ref _sharedPtr); } } } public class Model : UnmanagedObject { protected IntPtr _model; internal Model() { } public Model(string model, string config) { using CvString cvString = new CvString(model); using CvString cvString2 = new CvString(config); _ptr = DnnInvoke.cveModelCreate(cvString, cvString2); _model = _ptr; } public Model(Net network) { _ptr = DnnInvoke.cveModelCreateFromNet(network); _model = _ptr; } public void Predict(IInputArray frame, IOutputArrayOfArrays outs) { using InputArray inputArray = frame.GetInputArray(); using OutputArray outputArray = outs.GetOutputArray(); DnnInvoke.cveModelPredict(_model, inputArray, outputArray); } public void SetInputScale(double scale) { DnnInvoke.cveModelSetInputScale(_model, scale); } public void SetInputMean(MCvScalar mean) { DnnInvoke.cveModelSetInputMean(_model, ref mean); } public void SetInputSize(Size size) { DnnInvoke.cveModelSetInputSize(_model, ref size); } public void SetInputCrop(bool crop) { DnnInvoke.cveModelSetInputCrop(_model, crop); } public void SetInputSwapRB(bool swapRB) { DnnInvoke.cveModelSetInputSwapRB(_model, swapRB); } protected override void DisposeObject() { if (_ptr != IntPtr.Zero) { DnnInvoke.cveModelRelease(ref _ptr); } _model = IntPtr.Zero; } public void SetPreferableBackend(Backend value) { DnnInvoke.cveModelSetPreferableBackend(_model, value); } public void SetPreferableTarget(Target value) { DnnInvoke.cveModelSetPreferableTarget(_model, value); } } [DebuggerTypeProxy(typeof(DebuggerProxy))] public class Net : UnmanagedObject { internal class DebuggerProxy { private Net _net; public string Graph => _net.Dump(); public DebuggerProxy(Net net) { _net = net; } } public string[] LayerNames { get { using VectorOfCvString vectorOfCvString = new VectorOfCvString(DnnInvoke.cveDnnNetGetLayerNames(_ptr), needDispose: true); return vectorOfCvString.ToArray(); } } public int[] UnconnectedOutLayers { get { using VectorOfInt vectorOfInt = new VectorOfInt(); DnnInvoke.cveDnnNetGetUnconnectedOutLayers(_ptr, vectorOfInt); return vectorOfInt.ToArray(); } } public string[] UnconnectedOutLayersNames { get { using VectorOfCvString vectorOfCvString = new VectorOfCvString(); DnnInvoke.cveDnnNetGetUnconnectedOutLayersNames(_ptr, vectorOfCvString); return vectorOfCvString.ToArray(); } } public bool Empty => DnnInvoke.cveNetEmpty(_ptr); public Net() { _ptr = DnnInvoke.cveDnnNetCreate(); } internal Net(IntPtr ptr) { _ptr = ptr; } public void SetInput(IInputArray blob, string name = "", double scaleFactor = 1.0, MCvScalar mean = default(MCvScalar)) { using CvString cvString = new CvString(name); using InputArray inputArray = blob.GetInputArray(); DnnInvoke.cveDnnNetSetInput(_ptr, inputArray, cvString, scaleFactor, ref mean); } public Mat Forward(string outputName = "") { using CvString cvString = new CvString(outputName); Mat mat = new Mat(); DnnInvoke.cveDnnNetForward(_ptr, cvString, mat); return mat; } public void Forward(IOutputArrayOfArrays outputBlobs, string outputName = "") { using OutputArray outputArray = outputBlobs.GetOutputArray(); using CvString cvString = new CvString(outputName); DnnInvoke.cveDnnNetForward2(_ptr, outputArray, cvString); } public void Forward(IOutputArrayOfArrays outputBlobs, string[] outBlobNames) { using OutputArray outputArray = outputBlobs.GetOutputArray(); using VectorOfCvString vectorOfCvString = new VectorOfCvString(outBlobNames); DnnInvoke.cveDnnNetForward3(_ptr, outputArray, vectorOfCvString); } protected override void DisposeObject() { if (_ptr != IntPtr.Zero) { DnnInvoke.cveDnnNetRelease(ref _ptr); } } public int GetLayerId(string layerName) { using CvString cvString = new CvString(layerName); return DnnInvoke.cveDnnGetLayerId(_ptr, cvString); } public Layer GetLayer(string layerName) { IntPtr sharedPtr = IntPtr.Zero; IntPtr ptr; using (CvString cvString = new CvString(layerName)) { ptr = DnnInvoke.cveDnnGetLayerByName(_ptr, cvString, ref sharedPtr); } return new Layer(sharedPtr, ptr); } public Layer GetLayer(int layerId) { IntPtr sharedPtr = IntPtr.Zero; IntPtr ptr = DnnInvoke.cveDnnGetLayerById(_ptr, layerId, ref sharedPtr); return new Layer(sharedPtr, ptr); } public string Dump() { using CvString cvString = new CvString(); DnnInvoke.cveDnnNetDump(_ptr, cvString); return cvString.ToString(); } public void DumpToFile(string path) { using CvString cvString = new CvString(path); DnnInvoke.cveDnnNetDumpToFile(_ptr, cvString); } public long GetPerfProfile(VectorOfDouble timings = null) { if (timings != null) { return DnnInvoke.cveDnnNetGetPerfProfile(_ptr, timings); } using VectorOfDouble vectorOfDouble = new VectorOfDouble(); return DnnInvoke.cveDnnNetGetPerfProfile(_ptr, vectorOfDouble); } public void SetPreferableBackend(Backend value) { DnnInvoke.cveNetSetPreferableBackend(_ptr, value); } public void SetPreferableTarget(Target value) { DnnInvoke.cveNetSetPreferableTarget(_ptr, value); } public void EnableFusion(bool value) { DnnInvoke.cveNetEnableFusion(_ptr, value); } public void SetHalideScheduler(string s) { using CvString cvString = new CvString(s); DnnInvoke.cveNetSetHalideScheduler(_ptr, cvString); } } public class SegmentationModel : Model { public SegmentationModel(string model, string config = null) { using CvString cvString = new CvString(model); using CvString cvString2 = new CvString(config); _ptr = DnnInvoke.cveDnnSegmentationModelCreate1(cvString, cvString2, ref _model); } public SegmentationModel(Net net) { _ptr = DnnInvoke.cveDnnSegmentationModelCreate2(net, ref _model); } public void Segment(IInputArray frame, IOutputArray mask) { using InputArray inputArray = frame.GetInputArray(); using OutputArray outputArray = mask.GetOutputArray(); DnnInvoke.cveDnnSegmentationModelSegment(_ptr, inputArray, outputArray); } protected override void DisposeObject() { if (_ptr != IntPtr.Zero) { DnnInvoke.cveDnnSegmentationModelRelease(ref _ptr); } _model = IntPtr.Zero; } } public enum Target { Cpu, OpenCL, OpenCLFp16, Myriad, Vulkan, FPGA, Cuda, CudaFp16, HDDL } public abstract class TextDetectionModel : Model { protected IntPtr _textDetectionModel; public void Detect(IInputArray frame, VectorOfVectorOfPoint detections, VectorOfFloat confidences) { using InputArray inputArray = frame.GetInputArray(); DnnInvoke.cveDnnTextDetectionModelDetect(_textDetectionModel, inputArray, detections, confidences); } public void DetectTextRectangles(IInputArray frame, VectorOfRotatedRect detections, VectorOfFloat confidences) { using InputArray inputArray = frame.GetInputArray(); DnnInvoke.cveDnnTextDetectionModelDetectTextRectangles(_textDetectionModel, inputArray, detections, confidences); } protected override void DisposeObject() { _textDetectionModel = IntPtr.Zero; _model = IntPtr.Zero; } } public class TextDetectionModel_DB : TextDetectionModel { public float BinaryThreshold { get { return DnnInvoke.cveTextDetectionModel_DBGetBinaryThreshold(_ptr); } set { DnnInvoke.cveTextDetectionModel_DBSetBinaryThreshold(_ptr, value); } } public float PolygonThreshold { get { return DnnInvoke.cveTextDetectionModel_DBGetPolygonThreshold(_ptr); } set { DnnInvoke.cveTextDetectionModel_DBSetPolygonThreshold(_ptr, value); } } public double UnclipRatio { get { return DnnInvoke.cveTextDetectionModel_DBGetUnclipRatio(_ptr); } set { DnnInvoke.cveTextDetectionModel_DBSetUnclipRatio(_ptr, value); } } public int MaxCandidates { get { return DnnInvoke.cveTextDetectionModel_DBGetMaxCandidates(_ptr); } set { DnnInvoke.cveTextDetectionModel_DBSetMaxCandidates(_ptr, value); } } public TextDetectionModel_DB(string model, string config = null) { using CvString cvString = new CvString(model); using CvString cvString2 = new CvString(config); _ptr = DnnInvoke.cveDnnTextDetectionModelDbCreate1(cvString, cvString2, ref _textDetectionModel, ref _model); } public TextDetectionModel_DB(Net net) { _ptr = DnnInvoke.cveDnnTextDetectionModelDbCreate2(net, ref _textDetectionModel, ref _model); } protected override void DisposeObject() { if (_ptr != IntPtr.Zero) { DnnInvoke.cveDnnTextDetectionModelDbRelease(ref _ptr); } base.DisposeObject(); } } public class TextDetectionModel_EAST : TextDetectionModel { public float ConfidenceThreshold { get { return DnnInvoke.cveTextDetectionModel_EASTGetConfidenceThreshold(_ptr); } set { DnnInvoke.cveTextDetectionModel_EASTSetConfidenceThreshold(_ptr, value); } } public float NMSThreshold { get { return DnnInvoke.cveTextDetectionModel_EASTGetNMSThreshold(_ptr); } set { DnnInvoke.cveTextDetectionModel_EASTSetNMSThreshold(_ptr, value); } } public TextDetectionModel_EAST(string model, string config = null) { using CvString cvString = new CvString(model); using CvString cvString2 = new CvString(config); _ptr = DnnInvoke.cveDnnTextDetectionModelEastCreate1(cvString, cvString2, ref _textDetectionModel, ref _model); } public TextDetectionModel_EAST(Net net) { _ptr = DnnInvoke.cveDnnTextDetectionModelEastCreate2(net, ref _textDetectionModel, ref _model); } protected override void DisposeObject() { if (_ptr != IntPtr.Zero) { DnnInvoke.cveDnnTextDetectionModelEastRelease(ref _ptr); } base.DisposeObject(); } } public class TextRecognitionModel : Model { public string[] Vocabulary { get { using VectorOfCvString vectorOfCvString = new VectorOfCvString(); DnnInvoke.cveDnnTextRecognitionModelGetVocabulary(_ptr, vectorOfCvString); return vectorOfCvString.ToArray(); } set { using VectorOfCvString vectorOfCvString = new VectorOfCvString(value); DnnInvoke.cveDnnTextRecognitionModelSetVocabulary(_ptr, vectorOfCvString); } } public string DecodeType { get { using CvString cvString = new CvString(); DnnInvoke.cveTextRecognitionModelGetDecodeType(_ptr, cvString); return cvString.ToString(); } set { using CvString cvString = new CvString(value); DnnInvoke.cveTextRecognitionModelSetDecodeType(_ptr, cvString); } } public TextRecognitionModel(string model, string config = null) { using CvString cvString = new CvString(model); using CvString cvString2 = new CvString(config); _ptr = DnnInvoke.cveDnnTextRecognitionModelCreate1(cvString, cvString2, ref _model); } public TextRecognitionModel(Net net) { _ptr = DnnInvoke.cveDnnTextRecognitionModelCreate2(net, ref _model); } public void SetDecodeOptsCTCPrefixBeamSearch(int beamSize, int vocPruneSize) { DnnInvoke.cveDnnTextRecognitionModelSetDecodeOptsCTCPrefixBeamSearch(_ptr, beamSize, vocPruneSize); } public string Recognize(IInputArray frame) { using CvString cvString = new CvString(); using InputArray inputArray = frame.GetInputArray(); DnnInvoke.cveDnnTextRecognitionModelRecognize1(_ptr, inputArray, cvString); return cvString.ToString(); } public string[] Recognize(IInputArray frame, IInputArrayOfArrays roiRects) { using VectorOfCvString vectorOfCvString = new VectorOfCvString(); using InputArray inputArray = frame.GetInputArray(); using InputArray inputArray2 = roiRects.GetInputArray(); DnnInvoke.cveDnnTextRecognitionModelRecognize2(_ptr, inputArray, inputArray2, vectorOfCvString); return vectorOfCvString.ToArray(); } protected override void DisposeObject() { if (_ptr != IntPtr.Zero) { DnnInvoke.cveDnnTextRecognitionModelRelease(ref _ptr); } _model = IntPtr.Zero; } } } namespace Emgu.CV.ML { public class ANN_MLP : UnmanagedObject, IStatModel, IAlgorithm { public enum AnnMlpActivationFunction { Identity, SigmoidSym, Gaussian, Relu, LeakyRelu } public enum AnnMlpTrainMethod { Backprop, Rprop, Anneal } private IntPtr _sharedPtr; private IntPtr _statModelPtr; private IntPtr _algorithmPtr; IntPtr IStatModel.StatModelPtr => _statModelPtr; IntPtr IAlgorithm.AlgorithmPtr => _algorithmPtr; public MCvTermCriteria TermCriteria { get { MCvTermCriteria val = default(MCvTermCriteria); MlInvoke.cveANN_MLPGetTermCriteria(_ptr, ref val); return val; } set { MlInvoke.cveANN_MLPSetTermCriteria(_ptr, ref value); } } public double BackpropWeightScale { get { return MlInvoke.cveANN_MLPGetBackpropWeightScale(_ptr); } set { MlInvoke.cveANN_MLPSetBackpropWeightScale(_ptr, value); } } public double BackpropMomentumScale { get { return MlInvoke.cveANN_MLPGetBackpropMomentumScale(_ptr); } set { MlInvoke.cveANN_MLPSetBackpropMomentumScale(_ptr, value); } } public double RpropDW0 { get { return MlInvoke.cveANN_MLPGetRpropDW0(_ptr); } set { MlInvoke.cveANN_MLPSetRpropDW0(_ptr, value); } } public double RpropDWPlus { get { return MlInvoke.cveANN_MLPGetRpropDWPlus(_ptr); } set { MlInvoke.cveANN_MLPSetRpropDWPlus(_ptr, value); } } public double RpropDWMinus { get { return MlInvoke.cveANN_MLPGetRpropDWMinus(_ptr); } set { MlInvoke.cveANN_MLPSetRpropDWMinus(_ptr, value); } } public double RpropDWMin { get { return MlInvoke.cveANN_MLPGetRpropDWMin(_ptr); } set { MlInvoke.cveANN_MLPSetRpropDWMin(_ptr, value); } } public double RpropDWMax { get { return MlInvoke.cveANN_MLPGetRpropDWMax(_ptr); } set { MlInvoke.cveANN_MLPSetRpropDWMax(_ptr, value); } } public double AnnealInitialT { get { return MlInvoke.cveANN_MLPGetAnnealInitialT(_ptr); } set { MlInvoke.cveANN_MLPSetAnnealInitialT(_ptr, value); } } public double AnnealFinalT { get { return MlInvoke.cveANN_MLPGetAnnealFinalT(_ptr); } set { MlInvoke.cveANN_MLPSetAnnealFinalT(_ptr, value); } } public double AnnealCoolingRatio { get { return MlInvoke.cveANN_MLPGetAnnealCoolingRatio(_ptr); } set { MlInvoke.cveANN_MLPSetAnnealCoolingRatio(_ptr, value); } } public int AnnealItePerStep { get { return MlInvoke.cveANN_MLPGetAnnealItePerStep(_ptr); } set { MlInvoke.cveANN_MLPSetAnnealItePerStep(_ptr, value); } } public ANN_MLP() { _ptr = MlInvoke.cveANN_MLPCreate(ref _statModelPtr, ref _algorithmPtr, ref _sharedPtr); } protected override void DisposeObject() { if (IntPtr.Zero != _ptr) { MlInvoke.cveANN_MLPRelease(ref _ptr, ref _sharedPtr); _statModelPtr = IntPtr.Zero; _algorithmPtr = IntPtr.Zero; } } public void SetLayerSizes(IInputArray layerSizes) { using InputArray inputArray = layerSizes.GetInputArray(); MlInvoke.cveANN_MLPSetLayerSizes(_ptr, inputArray); } public void SetActivationFunction(AnnMlpActivationFunction function, double param1 = 0.0, double param2 = 0.0) { MlInvoke.cveANN_MLPSetActivationFunction(_ptr, function, param1, param2); } public void SetTrainMethod(AnnMlpTrainMethod method = AnnMlpTrainMethod.Rprop, double param1 = 0.0, double param2 = 0.0) { MlInvoke.cveANN_MLPSetTrainMethod(_ptr, method, param1, param2); } } public static class MlInvoke { [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveANN_MLPCreate(ref IntPtr statModel, ref IntPtr algorithm, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveANN_MLPRelease(ref IntPtr model, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveANN_MLPSetLayerSizes(IntPtr model, IntPtr layerSizes); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveANN_MLPSetActivationFunction(IntPtr model, ANN_MLP.AnnMlpActivationFunction type, double param1, double param2); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveANN_MLPSetTrainMethod(IntPtr model, ANN_MLP.AnnMlpTrainMethod method, double param1, double param2); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveANN_MLPGetTermCriteria(IntPtr obj, ref MCvTermCriteria val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveANN_MLPSetTermCriteria(IntPtr obj, ref MCvTermCriteria val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern double cveANN_MLPGetBackpropWeightScale(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveANN_MLPSetBackpropWeightScale(IntPtr obj, double val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern double cveANN_MLPGetBackpropMomentumScale(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveANN_MLPSetBackpropMomentumScale(IntPtr obj, double val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern double cveANN_MLPGetRpropDW0(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveANN_MLPSetRpropDW0(IntPtr obj, double val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern double cveANN_MLPGetRpropDWPlus(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveANN_MLPSetRpropDWPlus(IntPtr obj, double val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern double cveANN_MLPGetRpropDWMinus(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveANN_MLPSetRpropDWMinus(IntPtr obj, double val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern double cveANN_MLPGetRpropDWMin(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveANN_MLPSetRpropDWMin(IntPtr obj, double val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern double cveANN_MLPGetRpropDWMax(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveANN_MLPSetRpropDWMax(IntPtr obj, double val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern double cveANN_MLPGetAnnealInitialT(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveANN_MLPSetAnnealInitialT(IntPtr obj, double val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern double cveANN_MLPGetAnnealFinalT(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveANN_MLPSetAnnealFinalT(IntPtr obj, double val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern double cveANN_MLPGetAnnealCoolingRatio(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveANN_MLPSetAnnealCoolingRatio(IntPtr obj, double val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int cveANN_MLPGetAnnealItePerStep(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveANN_MLPSetAnnealItePerStep(IntPtr obj, int val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int cveBoostGetMaxCategories(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveBoostSetMaxCategories(IntPtr obj, int val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int cveBoostGetMaxDepth(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveBoostSetMaxDepth(IntPtr obj, int val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int cveBoostGetMinSampleCount(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveBoostSetMinSampleCount(IntPtr obj, int val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int cveBoostGetCVFolds(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveBoostSetCVFolds(IntPtr obj, int val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.U1)] internal static extern bool cveBoostGetUseSurrogates(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveBoostSetUseSurrogates(IntPtr obj, [MarshalAs(UnmanagedType.U1)] bool val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.U1)] internal static extern bool cveBoostGetUse1SERule(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveBoostSetUse1SERule(IntPtr obj, [MarshalAs(UnmanagedType.U1)] bool val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.U1)] internal static extern bool cveBoostGetTruncatePrunedTree(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveBoostSetTruncatePrunedTree(IntPtr obj, [MarshalAs(UnmanagedType.U1)] bool val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern float cveBoostGetRegressionAccuracy(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveBoostSetRegressionAccuracy(IntPtr obj, float val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int cveDTreesGetMaxCategories(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveDTreesSetMaxCategories(IntPtr obj, int val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int cveDTreesGetMaxDepth(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveDTreesSetMaxDepth(IntPtr obj, int val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int cveDTreesGetMinSampleCount(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveDTreesSetMinSampleCount(IntPtr obj, int val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int cveDTreesGetCVFolds(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveDTreesSetCVFolds(IntPtr obj, int val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.U1)] internal static extern bool cveDTreesGetUseSurrogates(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveDTreesSetUseSurrogates(IntPtr obj, [MarshalAs(UnmanagedType.U1)] bool val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.U1)] internal static extern bool cveDTreesGetUse1SERule(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveDTreesSetUse1SERule(IntPtr obj, [MarshalAs(UnmanagedType.U1)] bool val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.U1)] internal static extern bool cveDTreesGetTruncatePrunedTree(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveDTreesSetTruncatePrunedTree(IntPtr obj, [MarshalAs(UnmanagedType.U1)] bool val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern float cveDTreesGetRegressionAccuracy(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveDTreesSetRegressionAccuracy(IntPtr obj, float val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int cveEMGetClustersNumber(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveEMSetClustersNumber(IntPtr obj, int val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern EM.CovarianMatrixType cveEMGetCovarianceMatrixType(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveEMSetCovarianceMatrixType(IntPtr obj, EM.CovarianMatrixType val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveEMGetTermCriteria(IntPtr obj, ref MCvTermCriteria val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveEMSetTermCriteria(IntPtr obj, ref MCvTermCriteria val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int cveKNearestGetDefaultK(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveKNearestSetDefaultK(IntPtr obj, int val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.U1)] internal static extern bool cveKNearestGetIsClassifier(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveKNearestSetIsClassifier(IntPtr obj, [MarshalAs(UnmanagedType.U1)] bool val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int cveKNearestGetEmax(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveKNearestSetEmax(IntPtr obj, int val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern KNearest.Types cveKNearestGetAlgorithmType(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveKNearestSetAlgorithmType(IntPtr obj, KNearest.Types val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern double cveLogisticRegressionGetLearningRate(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveLogisticRegressionSetLearningRate(IntPtr obj, double val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int cveLogisticRegressionGetIterations(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveLogisticRegressionSetIterations(IntPtr obj, int val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern LogisticRegression.RegularizationMethod cveLogisticRegressionGetRegularization(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveLogisticRegressionSetRegularization(IntPtr obj, LogisticRegression.RegularizationMethod val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern LogisticRegression.TrainType cveLogisticRegressionGetTrainMethod(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveLogisticRegressionSetTrainMethod(IntPtr obj, LogisticRegression.TrainType val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int cveLogisticRegressionGetMiniBatchSize(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveLogisticRegressionSetMiniBatchSize(IntPtr obj, int val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveLogisticRegressionGetTermCriteria(IntPtr obj, ref MCvTermCriteria val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveLogisticRegressionSetTermCriteria(IntPtr obj, ref MCvTermCriteria val); static MlInvoke() { CvInvoke.Init(); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.U1)] internal static extern bool StatModelTrain(IntPtr model, IntPtr samples, DataLayoutType layout, IntPtr responses); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.U1)] internal static extern bool StatModelTrainWithData(IntPtr model, IntPtr data, int flags); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern float StatModelPredict(IntPtr model, IntPtr samples, IntPtr results, int flags); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveTrainDataCreate(IntPtr samples, DataLayoutType layout, IntPtr responses, IntPtr varIdx, IntPtr sampleIdx, IntPtr sampleWeights, IntPtr varType, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveTrainDataRelease(ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveNormalBayesClassifierDefaultCreate(ref IntPtr statModel, ref IntPtr algorithm, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveNormalBayesClassifierRelease(ref IntPtr classifier, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveKNearestCreate(ref IntPtr statModel, ref IntPtr algorithm, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveKNearestRelease(ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern float cveKNearestFindNearest(IntPtr classifier, IntPtr samples, int k, IntPtr results, IntPtr neighborResponses, IntPtr dist); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveEMDefaultCreate(ref IntPtr statModel, ref IntPtr algorithm, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveEMRelease(ref IntPtr emModel, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveEMTrainE(IntPtr model, IntPtr samples, IntPtr means0, IntPtr covs0, IntPtr weights0, IntPtr logLikelihoods, IntPtr labels, IntPtr probs, ref IntPtr statModel, ref IntPtr algorithm); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveEMTrainM(IntPtr model, IntPtr samples, IntPtr probs0, IntPtr logLikelihoods, IntPtr labels, IntPtr probs, ref IntPtr statModel, ref IntPtr algorithm); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveEMPredict(IntPtr model, IntPtr samples, ref MCvPoint2D64f result, IntPtr probs); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveSVMDefaultCreate(ref IntPtr statModel, ref IntPtr algorithm, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveSVMRelease(ref IntPtr model, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveSVMGetDefaultGrid(SVM.ParamType type, ref MCvParamGrid grid); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.U1)] internal static extern bool cveSVMTrainAuto(IntPtr model, IntPtr trainData, int kFold, ref MCvParamGrid cGrid, ref MCvParamGrid gammaGrid, ref MCvParamGrid pGrid, ref MCvParamGrid nuGrid, ref MCvParamGrid coefGrid, ref MCvParamGrid degreeGrid, [MarshalAs(UnmanagedType.U1)] bool balanced); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveSVMGetSupportVectors(IntPtr model, IntPtr supportVectors); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveDTreesCreate(ref IntPtr statModel, ref IntPtr algorithm, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveDTreesRelease(ref IntPtr model, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveRTreesCreate(ref IntPtr statModel, ref IntPtr algorithm, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveRTreesGetVotes(IntPtr model, IntPtr samples, IntPtr results, DTrees.Flags flags); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveRTreesRelease(ref IntPtr model, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveBoostCreate(ref IntPtr statModel, ref IntPtr algorithm, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveBoostRelease(ref IntPtr model, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveLogisticRegressionCreate(ref IntPtr statModel, ref IntPtr algorithm, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveLogisticRegressionRelease(ref IntPtr model, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveSVMSGDDefaultCreate(ref IntPtr statModel, ref IntPtr algorithm, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveSVMSGDRelease(ref IntPtr model, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveSVMSGDSetOptimalParameters(IntPtr model, SVMSGD.SvmsgdType svmsgdType, SVMSGD.MarginType marginType); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int cveRTreesGetMaxCategories(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveRTreesSetMaxCategories(IntPtr obj, int val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int cveRTreesGetMaxDepth(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveRTreesSetMaxDepth(IntPtr obj, int val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int cveRTreesGetMinSampleCount(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveRTreesSetMinSampleCount(IntPtr obj, int val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int cveRTreesGetCVFolds(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveRTreesSetCVFolds(IntPtr obj, int val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.U1)] internal static extern bool cveRTreesGetUseSurrogates(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveRTreesSetUseSurrogates(IntPtr obj, [MarshalAs(UnmanagedType.U1)] bool val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.U1)] internal static extern bool cveRTreesGetUse1SERule(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveRTreesSetUse1SERule(IntPtr obj, [MarshalAs(UnmanagedType.U1)] bool val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.U1)] internal static extern bool cveRTreesGetTruncatePrunedTree(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveRTreesSetTruncatePrunedTree(IntPtr obj, [MarshalAs(UnmanagedType.U1)] bool val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern float cveRTreesGetRegressionAccuracy(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveRTreesSetRegressionAccuracy(IntPtr obj, float val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.U1)] internal static extern bool cveRTreesGetCalculateVarImportance(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveRTreesSetCalculateVarImportance(IntPtr obj, [MarshalAs(UnmanagedType.U1)] bool val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int cveRTreesGetActiveVarCount(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveRTreesSetActiveVarCount(IntPtr obj, int val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveRTreesGetTermCriteria(IntPtr obj, ref MCvTermCriteria val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveRTreesSetTermCriteria(IntPtr obj, ref MCvTermCriteria val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern SVM.SvmType cveSVMGetType(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveSVMSetType(IntPtr obj, SVM.SvmType val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern double cveSVMGetGamma(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveSVMSetGamma(IntPtr obj, double val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern double cveSVMGetCoef0(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveSVMSetCoef0(IntPtr obj, double val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern double cveSVMGetDegree(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveSVMSetDegree(IntPtr obj, double val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern double cveSVMGetC(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveSVMSetC(IntPtr obj, double val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern double cveSVMGetNu(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveSVMSetNu(IntPtr obj, double val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern double cveSVMGetP(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveSVMSetP(IntPtr obj, double val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveSVMSetKernel(IntPtr obj, SVM.SvmKernelType val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveSVMGetTermCriteria(IntPtr obj, ref MCvTermCriteria val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveSVMSetTermCriteria(IntPtr obj, ref MCvTermCriteria val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern SVM.SvmKernelType cveSVMGetKernelType(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern SVMSGD.SvmsgdType cveSVMSGDGetType(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveSVMSGDSetType(IntPtr obj, SVMSGD.SvmsgdType val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern SVMSGD.MarginType cveSVMSGDGetMargin(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveSVMSGDSetMargin(IntPtr obj, SVMSGD.MarginType val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern float cveSVMSGDGetMarginRegularization(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveSVMSGDSetMarginRegularization(IntPtr obj, float val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern float cveSVMSGDGetInitialStepSize(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveSVMSGDSetInitialStepSize(IntPtr obj, float val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern float cveSVMSGDGetStepDecreasingPower(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveSVMSGDSetStepDecreasingPower(IntPtr obj, float val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveSVMSGDGetTermCriteria(IntPtr obj, ref MCvTermCriteria val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveSVMSGDSetTermCriteria(IntPtr obj, ref MCvTermCriteria val); } public class Boost : UnmanagedObject, IStatModel, IAlgorithm { public enum Type { Discrete, Real, Logit, Gentle } private IntPtr _sharedPtr; private IntPtr _statModel; private IntPtr _algorithm; IntPtr IStatModel.StatModelPtr => _statModel; IntPtr IAlgorithm.AlgorithmPtr => _algorithm; public int MaxCategories { get { return MlInvoke.cveBoostGetMaxCategories(_ptr); } set { MlInvoke.cveBoostSetMaxCategories(_ptr, value); } } public int MaxDepth { get { return MlInvoke.cveBoostGetMaxDepth(_ptr); } set { MlInvoke.cveBoostSetMaxDepth(_ptr, value); } } public int MinSampleCount { get { return MlInvoke.cveBoostGetMinSampleCount(_ptr); } set { MlInvoke.cveBoostSetMinSampleCount(_ptr, value); } } public int CVFolds { get { return MlInvoke.cveBoostGetCVFolds(_ptr); } set { MlInvoke.cveBoostSetCVFolds(_ptr, value); } } public bool UseSurrogates { get { return MlInvoke.cveBoostGetUseSurrogates(_ptr); } set { MlInvoke.cveBoostSetUseSurrogates(_ptr, value); } } public bool Use1SERule { get { return MlInvoke.cveBoostGetUse1SERule(_ptr); } set { MlInvoke.cveBoostSetUse1SERule(_ptr, value); } } public bool TruncatePrunedTree { get { return MlInvoke.cveBoostGetTruncatePrunedTree(_ptr); } set { MlInvoke.cveBoostSetTruncatePrunedTree(_ptr, value); } } public float RegressionAccuracy { get { return MlInvoke.cveBoostGetRegressionAccuracy(_ptr); } set { MlInvoke.cveBoostSetRegressionAccuracy(_ptr, value); } } public Boost() { _ptr = MlInvoke.cveBoostCreate(ref _statModel, ref _algorithm, ref _sharedPtr); } protected override void DisposeObject() { if (IntPtr.Zero != _ptr) { MlInvoke.cveBoostRelease(ref _ptr, ref _sharedPtr); _statModel = IntPtr.Zero; _algorithm = IntPtr.Zero; } } } public class DTrees : UnmanagedObject, IStatModel, IAlgorithm { public enum Flags { PredictAuto = 0, PredictSum = 256, PredictMaxVote = 512, PredictMask = 768 } private IntPtr _sharedPtr; private IntPtr _statModelPtr; private IntPtr _algorithmPtr; IntPtr IStatModel.StatModelPtr => _statModelPtr; IntPtr IAlgorithm.AlgorithmPtr => _algorithmPtr; public int MaxCategories { get { return MlInvoke.cveDTreesGetMaxCategories(_ptr); } set { MlInvoke.cveDTreesSetMaxCategories(_ptr, value); } } public int MaxDepth { get { return MlInvoke.cveDTreesGetMaxDepth(_ptr); } set { MlInvoke.cveDTreesSetMaxDepth(_ptr, value); } } public int MinSampleCount { get { return MlInvoke.cveDTreesGetMinSampleCount(_ptr); } set { MlInvoke.cveDTreesSetMinSampleCount(_ptr, value); } } public int CVFolds { get { return MlInvoke.cveDTreesGetCVFolds(_ptr); } set { MlInvoke.cveDTreesSetCVFolds(_ptr, value); } } public bool UseSurrogates { get { return MlInvoke.cveDTreesGetUseSurrogates(_ptr); } set { MlInvoke.cveDTreesSetUseSurrogates(_ptr, value); } } public bool Use1SERule { get { return MlInvoke.cveDTreesGetUse1SERule(_ptr); } set { MlInvoke.cveDTreesSetUse1SERule(_ptr, value); } } public bool TruncatePrunedTree { get { return MlInvoke.cveDTreesGetTruncatePrunedTree(_ptr); } set { MlInvoke.cveDTreesSetTruncatePrunedTree(_ptr, value); } } public float RegressionAccuracy { get { return MlInvoke.cveDTreesGetRegressionAccuracy(_ptr); } set { MlInvoke.cveDTreesSetRegressionAccuracy(_ptr, value); } } public DTrees() { _ptr = MlInvoke.cveDTreesCreate(ref _statModelPtr, ref _algorithmPtr, ref _sharedPtr); } protected override void DisposeObject() { if (IntPtr.Zero != _ptr) { MlInvoke.cveDTreesRelease(ref _ptr, ref _sharedPtr); _statModelPtr = IntPtr.Zero; _algorithmPtr = IntPtr.Zero; } } } public class EM : UnmanagedObject, IStatModel, IAlgorithm { public enum CovarianMatrixType { Spherical = 0, Diagonal = 1, Generic = 2, Default = 1 } private IntPtr _sharedPtr; private IntPtr _statModel; private IntPtr _algorithm; IntPtr IAlgorithm.AlgorithmPtr => _algorithm; IntPtr IStatModel.StatModelPtr => _statModel; public int ClustersNumber { get { return MlInvoke.cveEMGetClustersNumber(_ptr); } set { MlInvoke.cveEMSetClustersNumber(_ptr, value); } } public CovarianMatrixType CovarianceMatrixType { get { return MlInvoke.cveEMGetCovarianceMatrixType(_ptr); } set { MlInvoke.cveEMSetCovarianceMatrixType(_ptr, value); } } public MCvTermCriteria TermCriteria { get { MCvTermCriteria val = default(MCvTermCriteria); MlInvoke.cveEMGetTermCriteria(_ptr, ref val); return val; } set { MlInvoke.cveEMSetTermCriteria(_ptr, ref value); } } public EM() { _ptr = MlInvoke.cveEMDefaultCreate(ref _statModel, ref _algorithm, ref _sharedPtr); } public void trainE(IInputArray samples, IInputArray means0, IInputArray covs0 = null, IInputArray weights0 = null, IOutputArray loglikelihoods = null, IOutputArray labels = null, IOutputArray probs = null) { using InputArray inputArray = samples.GetInputArray(); using InputArray inputArray2 = means0.GetInputArray(); using InputArray inputArray3 = ((covs0 == null) ? InputArray.GetEmpty() : covs0.GetInputArray()); using InputArray inputArray4 = ((weights0 == null) ? InputArray.GetEmpty() : weights0.GetInputArray()); using OutputArray outputArray = ((loglikelihoods == null) ? OutputArray.GetEmpty() : loglikelihoods.GetOutputArray()); using OutputArray outputArray2 = ((labels == null) ? OutputArray.GetEmpty() : labels.GetOutputArray()); using OutputArray outputArray3 = ((probs == null) ? OutputArray.GetEmpty() : probs.GetOutputArray()); MlInvoke.cveEMTrainE(_ptr, inputArray, inputArray2, inputArray3, inputArray4, outputArray, outputArray2, outputArray3, ref _statModel, ref _algorithm); } public void TrainM(IInputArray samples, IInputArray probs0, IOutputArray logLikelihoods = null, IOutputArray labels = null, IOutputArray probs = null) { using InputArray inputArray = samples.GetInputArray(); using InputArray inputArray2 = probs0.GetInputArray(); using OutputArray outputArray = ((logLikelihoods == null) ? OutputArray.GetEmpty() : logLikelihoods.GetOutputArray()); using OutputArray outputArray2 = ((labels == null) ? OutputArray.GetEmpty() : labels.GetOutputArray()); using OutputArray outputArray3 = ((probs == null) ? OutputArray.GetEmpty() : probs.GetOutputArray()); MlInvoke.cveEMTrainM(_ptr, inputArray, inputArray2, outputArray, outputArray2, outputArray3, ref _statModel, ref _algorithm); } public MCvPoint2D64f Predict(IInputArray samples, IOutputArray probs = null) { MCvPoint2D64f result = default(MCvPoint2D64f); using InputArray inputArray = samples.GetInputArray(); using OutputArray outputArray = ((probs == null) ? OutputArray.GetEmpty() : probs.GetOutputArray()); MlInvoke.cveEMPredict(_ptr, inputArray, ref result, outputArray); return result; } protected override void DisposeObject() { if (IntPtr.Zero != _ptr) { MlInvoke.cveEMRelease(ref _ptr, ref _sharedPtr); _statModel = IntPtr.Zero; _algorithm = IntPtr.Zero; } } } public class KNearest : SharedPtrObject, IStatModel, IAlgorithm { public enum Types { BruteForce = 1, KdTree } private IntPtr _statModelPtr; private IntPtr _algorithmPtr; IntPtr IStatModel.StatModelPtr => _statModelPtr; IntPtr IAlgorithm.AlgorithmPtr => _algorithmPtr; public int DefaultK { get { return MlInvoke.cveKNearestGetDefaultK(_ptr); } set { MlInvoke.cveKNearestSetDefaultK(_ptr, value); } } public bool IsClassifier { get { return MlInvoke.cveKNearestGetIsClassifier(_ptr); } set { MlInvoke.cveKNearestSetIsClassifier(_ptr, value); } } public int Emax { get { return MlInvoke.cveKNearestGetEmax(_ptr); } set { MlInvoke.cveKNearestSetEmax(_ptr, value); } } public Types AlgorithmType { get { return MlInvoke.cveKNearestGetAlgorithmType(_ptr); } set { MlInvoke.cveKNearestSetAlgorithmType(_ptr, value); } } public KNearest() { _ptr = MlInvoke.cveKNearestCreate(ref _statModelPtr, ref _algorithmPtr, ref _sharedPtr); } protected override void DisposeObject() { if (IntPtr.Zero != _sharedPtr) { MlInvoke.cveKNearestRelease(ref _sharedPtr); _ptr = IntPtr.Zero; _statModelPtr = IntPtr.Zero; _algorithmPtr = IntPtr.Zero; } } public float FindNearest(IInputArray samples, int k, IOutputArray results, IOutputArray neighborResponses = null, IOutputArray dist = null) { using InputArray inputArray = samples.GetInputArray(); using OutputArray outputArray = results.GetOutputArray(); using OutputArray outputArray2 = ((neighborResponses == null) ? OutputArray.GetEmpty() : neighborResponses.GetOutputArray()); using OutputArray outputArray3 = ((dist == null) ? OutputArray.GetEmpty() : dist.GetOutputArray()); return MlInvoke.cveKNearestFindNearest(_ptr, inputArray, k, outputArray, outputArray2, outputArray3); } } public class LogisticRegression : UnmanagedObject, IStatModel, IAlgorithm { public enum TrainType { Batch, MiniBatch } public enum RegularizationMethod { Disable = -1, L1, L2 } private IntPtr _sharedPtr; private IntPtr _statModelPtr; private IntPtr _algorithmPtr; public IntPtr StatModelPtr => _statModelPtr; public IntPtr AlgorithmPtr => _algorithmPtr; public double LearningRate { get { return MlInvoke.cveLogisticRegressionGetLearningRate(_ptr); } set { MlInvoke.cveLogisticRegressionSetLearningRate(_ptr, value); } } public int Iterations { get { return MlInvoke.cveLogisticRegressionGetIterations(_ptr); } set { MlInvoke.cveLogisticRegressionSetIterations(_ptr, value); } } public RegularizationMethod Regularization { get { return MlInvoke.cveLogisticRegressionGetRegularization(_ptr); } set { MlInvoke.cveLogisticRegressionSetRegularization(_ptr, value); } } public TrainType TrainMethod { get { return MlInvoke.cveLogisticRegressionGetTrainMethod(_ptr); } set { MlInvoke.cveLogisticRegressionSetTrainMethod(_ptr, value); } } public int MiniBatchSize { get { return MlInvoke.cveLogisticRegressionGetMiniBatchSize(_ptr); } set { MlInvoke.cveLogisticRegressionSetMiniBatchSize(_ptr, value); } } public MCvTermCriteria TermCriteria { get { MCvTermCriteria val = default(MCvTermCriteria); MlInvoke.cveLogisticRegressionGetTermCriteria(_ptr, ref val); return val; } set { MlInvoke.cveLogisticRegressionSetTermCriteria(_ptr, ref value); } } public LogisticRegression() { _ptr = MlInvoke.cveLogisticRegressionCreate(ref _statModelPtr, ref _algorithmPtr, ref _sharedPtr); } protected override void DisposeObject() { if (_ptr != IntPtr.Zero) { MlInvoke.cveLogisticRegressionRelease(ref _ptr, ref _sharedPtr); _statModelPtr = IntPtr.Zero; _algorithmPtr = IntPtr.Zero; } } } public class NormalBayesClassifier : UnmanagedObject, IStatModel, IAlgorithm { private IntPtr _sharedPtr; private IntPtr _statModelPtr; private IntPtr _algorithmPtr; IntPtr IStatModel.StatModelPtr => _statModelPtr; IntPtr IAlgorithm.AlgorithmPtr => _algorithmPtr; public NormalBayesClassifier() { _ptr = MlInvoke.cveNormalBayesClassifierDefaultCreate(ref _statModelPtr, ref _algorithmPtr, ref _sharedPtr); } protected override void DisposeObject() { if (_ptr != IntPtr.Zero) { MlInvoke.cveNormalBayesClassifierRelease(ref _ptr, ref _sharedPtr); _statModelPtr = IntPtr.Zero; _algorithmPtr = IntPtr.Zero; } } } public class RTrees : UnmanagedObject, IStatModel, IAlgorithm { private IntPtr _sharedPtr; private IntPtr _statModelPtr; private IntPtr _algorithmPtr; IntPtr IStatModel.StatModelPtr => _statModelPtr; IntPtr IAlgorithm.AlgorithmPtr => _algorithmPtr; public int MaxCategories { get { return MlInvoke.cveRTreesGetMaxCategories(_ptr); } set { MlInvoke.cveRTreesSetMaxCategories(_ptr, value); } } public int MaxDepth { get { return MlInvoke.cveRTreesGetMaxDepth(_ptr); } set { MlInvoke.cveRTreesSetMaxDepth(_ptr, value); } } public int MinSampleCount { get { return MlInvoke.cveRTreesGetMinSampleCount(_ptr); } set { MlInvoke.cveRTreesSetMinSampleCount(_ptr, value); } } public int CVFolds { get { return MlInvoke.cveRTreesGetCVFolds(_ptr); } set { MlInvoke.cveRTreesSetCVFolds(_ptr, value); } } public bool UseSurrogates { get { return MlInvoke.cveRTreesGetUseSurrogates(_ptr); } set { MlInvoke.cveRTreesSetUseSurrogates(_ptr, value); } } public bool Use1SERule { get { return MlInvoke.cveRTreesGetUse1SERule(_ptr); } set { MlInvoke.cveRTreesSetUse1SERule(_ptr, value); } } public bool TruncatePrunedTree { get { return MlInvoke.cveRTreesGetTruncatePrunedTree(_ptr); } set { MlInvoke.cveRTreesSetTruncatePrunedTree(_ptr, value); } } public float RegressionAccuracy { get { return MlInvoke.cveRTreesGetRegressionAccuracy(_ptr); } set { MlInvoke.cveRTreesSetRegressionAccuracy(_ptr, value); } } public bool CalculateVarImportance { get { return MlInvoke.cveRTreesGetCalculateVarImportance(_ptr); } set { MlInvoke.cveRTreesSetCalculateVarImportance(_ptr, value); } } public int ActiveVarCount { get { return MlInvoke.cveRTreesGetActiveVarCount(_ptr); } set { MlInvoke.cveRTreesSetActiveVarCount(_ptr, value); } } public MCvTermCriteria TermCriteria { get { MCvTermCriteria val = default(MCvTermCriteria); MlInvoke.cveRTreesGetTermCriteria(_ptr, ref val); return val; } set { MlInvoke.cveRTreesSetTermCriteria(_ptr, ref value); } } public RTrees() { _ptr = MlInvoke.cveRTreesCreate(ref _statModelPtr, ref _algorithmPtr, ref _sharedPtr); } public void GetVotes(IInputArray samples, IOutputArray results, DTrees.Flags flags) { using InputArray inputArray = samples.GetInputArray(); using OutputArray outputArray = results.GetOutputArray(); MlInvoke.cveRTreesGetVotes(_ptr, inputArray, outputArray, flags); } protected override void DisposeObject() { if (_ptr != IntPtr.Zero) { MlInvoke.cveRTreesRelease(ref _ptr, ref _sharedPtr); _statModelPtr = IntPtr.Zero; _algorithmPtr = IntPtr.Zero; } } } public interface IStatModel : IAlgorithm { IntPtr StatModelPtr { get; } } public static class StatModelExtensions { public static bool Train(this IStatModel model, IInputArray samples, DataLayoutType layoutType, IInputArray responses) { using InputArray inputArray = samples.GetInputArray(); using InputArray inputArray2 = responses.GetInputArray(); return MlInvoke.StatModelTrain(model.StatModelPtr, inputArray, layoutType, inputArray2); } public static bool Train(this IStatModel model, TrainData trainData, int flags = 0) { return MlInvoke.StatModelTrainWithData(model.StatModelPtr, trainData, flags); } public static float Predict(this IStatModel model, IInputArray samples, IOutputArray results = null, int flags = 0) { using InputArray inputArray = samples.GetInputArray(); using OutputArray outputArray = ((results == null) ? OutputArray.GetEmpty() : results.GetOutputArray()); return MlInvoke.StatModelPredict(model.StatModelPtr, inputArray, outputArray, flags); } } public struct MCvParamGrid { public double MinVal; public double MaxVal; public double Step; } public class SVM : UnmanagedObject, IStatModel, IAlgorithm { public enum SvmType { CSvc = 100, NuSvc, OneClass, EpsSvr, NuSvr } public enum SvmKernelType { Custom = -1, Linear, Poly, Rbf, Sigmoid, Chi2, Inter } public enum ParamType { C, Gamma, P, Nu, Coef, Degree } private IntPtr _sharedPtr; private IntPtr _statModelPtr; private IntPtr _algorithmPtr; IntPtr IStatModel.StatModelPtr => _statModelPtr; IntPtr IAlgorithm.AlgorithmPtr => _algorithmPtr; public SvmType Type { get { return MlInvoke.cveSVMGetType(_ptr); } set { MlInvoke.cveSVMSetType(_ptr, value); } } public double Gamma { get { return MlInvoke.cveSVMGetGamma(_ptr); } set { MlInvoke.cveSVMSetGamma(_ptr, value); } } public double Coef0 { get { return MlInvoke.cveSVMGetCoef0(_ptr); } set { MlInvoke.cveSVMSetCoef0(_ptr, value); } } public double Degree { get { return MlInvoke.cveSVMGetDegree(_ptr); } set { MlInvoke.cveSVMSetDegree(_ptr, value); } } public double C { get { return MlInvoke.cveSVMGetC(_ptr); } set { MlInvoke.cveSVMSetC(_ptr, value); } } public double Nu { get { return MlInvoke.cveSVMGetNu(_ptr); } set { MlInvoke.cveSVMSetNu(_ptr, value); } } public double P { get { return MlInvoke.cveSVMGetP(_ptr); } set { MlInvoke.cveSVMSetP(_ptr, value); } } public MCvTermCriteria TermCriteria { get { MCvTermCriteria val = default(MCvTermCriteria); MlInvoke.cveSVMGetTermCriteria(_ptr, ref val); return val; } set { MlInvoke.cveSVMSetTermCriteria(_ptr, ref value); } } public SvmKernelType KernelType => MlInvoke.cveSVMGetKernelType(_ptr); public SVM() { _ptr = MlInvoke.cveSVMDefaultCreate(ref _statModelPtr, ref _algorithmPtr, ref _sharedPtr); } protected override void DisposeObject() { if (IntPtr.Zero != _ptr) { MlInvoke.cveSVMRelease(ref _ptr, ref _sharedPtr); _statModelPtr = IntPtr.Zero; _algorithmPtr = IntPtr.Zero; } } public static MCvParamGrid GetDefaultGrid(ParamType type) { MCvParamGrid grid = default(MCvParamGrid); MlInvoke.cveSVMGetDefaultGrid(type, ref grid); return grid; } public bool TrainAuto(TrainData trainData, int kFold = 10) { return TrainAuto(trainData, kFold, GetDefaultGrid(ParamType.C), GetDefaultGrid(ParamType.Gamma), GetDefaultGrid(ParamType.P), GetDefaultGrid(ParamType.Nu), GetDefaultGrid(ParamType.Coef), GetDefaultGrid(ParamType.Degree)); } public bool TrainAuto(TrainData trainData, int kFold, MCvParamGrid cGrid, MCvParamGrid gammaGrid, MCvParamGrid pGrid, MCvParamGrid nuGrid, MCvParamGrid coefGrid, MCvParamGrid degreeGrid, bool balanced = false) { return MlInvoke.cveSVMTrainAuto(base.Ptr, trainData.Ptr, kFold, ref cGrid, ref gammaGrid, ref pGrid, ref nuGrid, ref coefGrid, ref degreeGrid, balanced); } public Mat GetSupportVectors() { Mat mat = new Mat(); MlInvoke.cveSVMGetSupportVectors(_ptr, mat); return mat; } public void SetKernel(SvmKernelType value) { MlInvoke.cveSVMSetKernel(_ptr, value); } } public class SVMSGD : UnmanagedObject, IStatModel, IAlgorithm { public enum SvmsgdType { Sgd, Asgd } public enum MarginType { SoftMargin, HardMargin } private IntPtr _sharedPtr; private IntPtr _statModelPtr; private IntPtr _algorithmPtr; IntPtr IStatModel.StatModelPtr => _statModelPtr; IntPtr IAlgorithm.AlgorithmPtr => _algorithmPtr; public SvmsgdType Type { get { return MlInvoke.cveSVMSGDGetType(_ptr); } set { MlInvoke.cveSVMSGDSetType(_ptr, value); } } public MarginType Margin { get { return MlInvoke.cveSVMSGDGetMargin(_ptr); } set { MlInvoke.cveSVMSGDSetMargin(_ptr, value); } } public float MarginRegularization { get { return MlInvoke.cveSVMSGDGetMarginRegularization(_ptr); } set { MlInvoke.cveSVMSGDSetMarginRegularization(_ptr, value); } } public float InitialStepSize { get { return MlInvoke.cveSVMSGDGetInitialStepSize(_ptr); } set { MlInvoke.cveSVMSGDSetInitialStepSize(_ptr, value); } } public float StepDecreasingPower { get { return MlInvoke.cveSVMSGDGetStepDecreasingPower(_ptr); } set { MlInvoke.cveSVMSGDSetStepDecreasingPower(_ptr, value); } } public MCvTermCriteria TermCriteria { get { MCvTermCriteria val = default(MCvTermCriteria); MlInvoke.cveSVMSGDGetTermCriteria(_ptr, ref val); return val; } set { MlInvoke.cveSVMSGDSetTermCriteria(_ptr, ref value); } } public SVMSGD() { _ptr = MlInvoke.cveSVMSGDDefaultCreate(ref _statModelPtr, ref _algorithmPtr, ref _sharedPtr); } public void SetOptimalParameters(SvmsgdType svmsgdType, MarginType marginType) { MlInvoke.cveSVMSGDSetOptimalParameters(_ptr, svmsgdType, marginType); } protected override void DisposeObject() { if (IntPtr.Zero != _ptr) { MlInvoke.cveSVMSGDRelease(ref _ptr, ref _sharedPtr); _statModelPtr = IntPtr.Zero; _algorithmPtr = IntPtr.Zero; } } } public class TrainData : SharedPtrObject { public TrainData(IInputArray samples, DataLayoutType layoutType, IInputArray response, IInputArray varIdx = null, IInputArray sampleIdx = null, IInputArray sampleWeight = null, IInputArray varType = null) { using InputArray inputArray = samples.GetInputArray(); using InputArray inputArray2 = response.GetInputArray(); using InputArray inputArray3 = ((varIdx == null) ? InputArray.GetEmpty() : varIdx.GetInputArray()); using InputArray inputArray4 = ((sampleIdx == null) ? InputArray.GetEmpty() : sampleIdx.GetInputArray()); using InputArray inputArray5 = ((sampleWeight == null) ? InputArray.GetEmpty() : sampleWeight.GetInputArray()); using InputArray inputArray6 = ((varType == null) ? InputArray.GetEmpty() : varType.GetInputArray()); _ptr = MlInvoke.cveTrainDataCreate(inputArray, layoutType, inputArray2, inputArray3, inputArray4, inputArray5, inputArray6, ref _sharedPtr); } protected override void DisposeObject() { if (IntPtr.Zero != _sharedPtr) { MlInvoke.cveTrainDataRelease(ref _sharedPtr); _ptr = IntPtr.Zero; } } } } namespace Emgu.CV.ML.MlEnum { [Flags] public enum AnnMlpTrainingFlag { Default = 0, UpdateWeights = 1, NoInputScale = 2, NoOutputScale = 4 } public enum BoostSplitCreiteria { Default = 0, Gini = 1, Misclass = 3, Sqerr = 4 } public enum BoostType { Discrete, Real, Logit, Gentle } public enum DataLayoutType { ColSample = 1, RowSample = 0 } public enum VarType { Numerical, Categorical } } namespace Emgu.CV.VideoStab { public class CaptureFrameSource : FrameSource { public CaptureFrameSource(VideoCapture capture) { _ptr = VideoStabInvoke.cveVideostabCaptureFrameSourceCreate(capture, ref FrameSourcePtr); base.CaptureSource = capture.CaptureSource; } protected override void DisposeObject() { if (_ptr != IntPtr.Zero) { VideoStabInvoke.cveVideostabCaptureFrameSourceRelease(ref _ptr); } FrameSourcePtr = IntPtr.Zero; base.DisposeObject(); } } public abstract class FrameSource : UnmanagedObject { private VideoCapture.CaptureModuleType _captureSource; public IntPtr FrameSourcePtr; public VideoCapture.CaptureModuleType CaptureSource { get { return _captureSource; } set { _captureSource = value; } } public Mat NextFrame() { Mat mat = new Mat(); if (VideoStabInvoke.cveVideostabFrameSourceGetNextFrame(FrameSourcePtr, mat)) { return mat; } mat.Dispose(); return null; } public bool NextFrame(Mat frame) { return VideoStabInvoke.cveVideostabFrameSourceGetNextFrame(FrameSourcePtr, frame); } protected override void DisposeObject() { FrameSourcePtr = IntPtr.Zero; } } public class GaussianMotionFilter : UnmanagedObject { public GaussianMotionFilter(int radius = 15, float stdev = -1f) { _ptr = VideoStabInvoke.cveGaussianMotionFilterCreate(radius, stdev); } protected override void DisposeObject() { VideoStabInvoke.cveGaussianMotionFilterRelease(ref _ptr); } } public class OnePassStabilizer : FrameSource { private IntPtr _stabilizerBase; private FrameSource _baseFrameSource; public OnePassStabilizer(FrameSource baseFrameSource) { _baseFrameSource = baseFrameSource; _ptr = VideoStabInvoke.cveOnePassStabilizerCreate(baseFrameSource.FrameSourcePtr, ref _stabilizerBase, ref FrameSourcePtr); } public void SetMotionFilter(GaussianMotionFilter motionFilter) { VideoStabInvoke.cveOnePassStabilizerSetMotionFilter(_ptr, motionFilter); } protected override void DisposeObject() { if (_ptr != IntPtr.Zero) { VideoStabInvoke.cveOnePassStabilizerRelease(ref _ptr); } _stabilizerBase = IntPtr.Zero; Dispose(); } } public class TwoPassStabilizer : FrameSource { private IntPtr _stabilizerBase; private FrameSource _baseFrameSource; public TwoPassStabilizer(FrameSource baseFrameSource) { if (baseFrameSource.CaptureSource == VideoCapture.CaptureModuleType.Camera) { throw new ArgumentException("Two pass stabilizer cannot process camera stream"); } _baseFrameSource = baseFrameSource; _ptr = VideoStabInvoke.cveTwoPassStabilizerCreate(_baseFrameSource, ref _stabilizerBase, ref FrameSourcePtr); } protected override void DisposeObject() { if (_ptr != IntPtr.Zero) { VideoStabInvoke.cveTwoPassStabilizerRelease(ref _ptr); } _stabilizerBase = IntPtr.Zero; Dispose(); } } internal static class VideoStabInvoke { static VideoStabInvoke() { CvInvoke.Init(); } public static float CalcBlurriness(Mat frame) { return cveCalcBlurriness(frame); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern float cveCalcBlurriness(IntPtr frame); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveVideostabCaptureFrameSourceCreate(IntPtr capture, ref IntPtr frameSourcePtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveVideostabCaptureFrameSourceRelease(ref IntPtr captureFrameSource); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.U1)] internal static extern bool cveVideostabFrameSourceGetNextFrame(IntPtr frameSource, IntPtr nextFrame); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveOnePassStabilizerCreate(IntPtr capture, ref IntPtr stabilizerBase, ref IntPtr frameSource); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveOnePassStabilizerSetMotionFilter(IntPtr stabalizer, IntPtr motionFilter); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveOnePassStabilizerRelease(ref IntPtr stabilizer); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveTwoPassStabilizerCreate(IntPtr capture, ref IntPtr stabilizerBase, ref IntPtr frameSource); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveTwoPassStabilizerRelease(ref IntPtr stabilizer); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveGaussianMotionFilterCreate(int radius, float stdev); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveGaussianMotionFilterRelease(ref IntPtr filter); } } namespace Emgu.CV.Superres { public class FrameSource : SharedPtrObject { protected virtual IntPtr FrameSourcePtr => _ptr; public FrameSource(string fileName, bool tryUseGpu) { using CvString cvString = new CvString(fileName); if (tryUseGpu) { try { _ptr = SuperresInvoke.cveSuperresCreateFrameSourceVideo(cvString, useGpu: true, ref _sharedPtr); return; } catch { _ptr = SuperresInvoke.cveSuperresCreateFrameSourceVideo(cvString, useGpu: false, ref _sharedPtr); return; } } _ptr = SuperresInvoke.cveSuperresCreateFrameSourceVideo(cvString, useGpu: false, ref _sharedPtr); } public FrameSource(int camIndex) { _ptr = SuperresInvoke.cveSuperresCreateFrameSourceCamera(camIndex, ref _sharedPtr); } internal FrameSource() { } public void NextFrame(IOutputArray frame) { using OutputArray outputArray = frame.GetOutputArray(); SuperresInvoke.cveSuperresFrameSourceNextFrame(FrameSourcePtr, outputArray); } protected override void DisposeObject() { if (_sharedPtr != IntPtr.Zero) { SuperresInvoke.cveSuperresFrameSourceRelease(ref _sharedPtr); _ptr = IntPtr.Zero; } } } internal static class SuperresInvoke { static SuperresInvoke() { CvInvoke.Init(); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveSuperresCreateFrameSourceVideo(IntPtr fileName, [MarshalAs(UnmanagedType.U1)] bool useGpu, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveSuperresCreateFrameSourceCamera(int deviceId, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveSuperresFrameSourceRelease(ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveSuperresFrameSourceNextFrame(IntPtr frameSource, IntPtr frame); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveSuperResolutionCreate(SuperResolution.OpticalFlowType type, IntPtr frameSource, ref IntPtr frameSourceOut, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveSuperResolutionRelease(ref IntPtr sharedPtr); } public class SuperResolution : FrameSource { public enum OpticalFlowType { Btvl, Btvl1Gpu } protected IntPtr _frameSourcePtr; protected override IntPtr FrameSourcePtr => _frameSourcePtr; public SuperResolution(OpticalFlowType type, FrameSource frameSource) { _ptr = SuperresInvoke.cveSuperResolutionCreate(type, frameSource, ref _frameSourcePtr, ref _sharedPtr); } protected override void DisposeObject() { if (_sharedPtr != IntPtr.Zero) { SuperresInvoke.cveSuperResolutionRelease(ref _sharedPtr); _frameSourcePtr = IntPtr.Zero; _ptr = IntPtr.Zero; } } } } namespace Emgu.CV.Stitching { public abstract class Blender : UnmanagedObject { protected IntPtr _blenderPtr; public IntPtr BlenderPtr => _blenderPtr; protected override void DisposeObject() { if (_blenderPtr != IntPtr.Zero) { _blenderPtr = IntPtr.Zero; } } public void Prepare(Point[] corners, Size[] sizes) { using VectorOfPoint vectorOfPoint = new VectorOfPoint(corners); using VectorOfSize vectorOfSize = new VectorOfSize(sizes); StitchingInvoke.cveBlenderPrepare(_blenderPtr, vectorOfPoint, vectorOfSize); } public void Prepare(Rectangle dstRoi) { StitchingInvoke.cveBlenderPrepare2(_blenderPtr, ref dstRoi); } public void Feed(IInputArray img, IInputArray mask, Point tl) { using InputArray inputArray = img.GetInputArray(); using InputArray inputArray2 = mask.GetInputArray(); StitchingInvoke.cveBlenderFeed(_blenderPtr, inputArray, inputArray2, ref tl); } public void Blend(IInputOutputArray dst, IInputOutputArray dstMask) { using InputOutputArray inputOutputArray = dst.GetInputOutputArray(); using InputOutputArray inputOutputArray2 = dstMask.GetInputOutputArray(); StitchingInvoke.cveBlenderBlend(_blenderPtr, inputOutputArray, inputOutputArray2); } } public static class StitchingInvoke { [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveBlenderPrepare(IntPtr blender, IntPtr corners, IntPtr sizes); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveBlenderPrepare2(IntPtr blender, ref Rectangle dstRoi); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveBlenderFeed(IntPtr blender, IntPtr img, IntPtr mask, ref Point tl); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveBlenderBlend(IntPtr blender, IntPtr dst, IntPtr dstMask); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveNoBundleAdjusterCreate(ref IntPtr bundleAdjusterPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveNoBundleAdjusterRelease(ref IntPtr bundleAdjuster); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveBundleAdjusterReprojCreate(ref IntPtr bundleAdjusterPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveBundleAdjusterReprojRelease(ref IntPtr bundleAdjuster); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveBundleAdjusterRayCreate(ref IntPtr bundleAdjusterPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveBundleAdjusterRayRelease(ref IntPtr bundleAdjuster); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveBundleAdjusterAffineCreate(ref IntPtr bundleAdjusterPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveBundleAdjusterAffineRelease(ref IntPtr bundleAdjuster); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveBundleAdjusterAffinePartialCreate(ref IntPtr bundleAdjusterPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveBundleAdjusterAffinePartialRelease(ref IntPtr bundleAdjuster); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveHomographyBasedEstimatorCreate([MarshalAs(UnmanagedType.U1)] bool isFocalsEstimated, ref IntPtr estimator); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveHomographyBasedEstimatorRelease(ref IntPtr estimator); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveAffineBasedEstimatorCreate(ref IntPtr estimator); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveAffineBasedEstimatorRelease(ref IntPtr estimator); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveNoExposureCompensatorCreate(ref IntPtr exposureCompensatorPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveNoExposureCompensatorRelease(ref IntPtr compensator); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveGainCompensatorCreate(int nrFeeds, ref IntPtr exposureCompensatorPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveGainCompensatorRelease(ref IntPtr compensator); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveChannelsCompensatorCreate(int nrFeeds, ref IntPtr exposureCompensatorPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveChannelsCompensatorRelease(ref IntPtr compensator); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveBlocksGainCompensatorCreate(int blWidth, int blHeight, int nrFeeds, ref IntPtr exposureCompensatorPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveBlocksGainCompensatorRelease(ref IntPtr compensator); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveBlocksChannelsCompensatorCreate(int blWidth, int blHeight, int nrFeeds, ref IntPtr exposureCompensatorPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveBlocksChannelsCompensatorRelease(ref IntPtr compensator); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveFeatherBlenderCreate(float sharpness, ref IntPtr blender); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveFeatherBlenderRelease(ref IntPtr blender); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveBestOf2NearestMatcherCreate([MarshalAs(UnmanagedType.U1)] bool tryUseGpu, float matchConf, int numMatchesThresh1, int numMatchesThresh2, ref IntPtr featuresMatcher); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveBestOf2NearestMatcherRelease(ref IntPtr blender); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveBestOf2NearestRangeMatcherCreate(int rangeWidth, [MarshalAs(UnmanagedType.U1)] bool tryUseGpu, float matchConf, int numMatchesThresh1, int numMatchesThresh2, ref IntPtr featuresMatcher); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveBestOf2NearestRangeMatcherRelease(ref IntPtr featuresMatcher); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveAffineBestOf2NearestMatcherCreate([MarshalAs(UnmanagedType.U1)] bool fullAffine, [MarshalAs(UnmanagedType.U1)] bool tryUseGpu, float matchConf, int numMatchesThresh1, ref IntPtr featuresMatcher); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveAffineBestOf2NearestMatcherRelease(ref IntPtr featuresMatcher); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveMultiBandBlenderCreate(int tryGpu, int numBands, DepthType weightType, ref IntPtr blender); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveMultiBandBlenderRelease(ref IntPtr blender); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveDetailPlaneWarperCreate(float scale, ref IntPtr rotationWarper); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveDetailPlaneWarperRelease(ref IntPtr warper); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveDetailCylindricalWarperCreate(float scale, ref IntPtr rotationWarper); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveDetailCylindricalWarperRelease(ref IntPtr warper); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveDetailSphericalWarperCreate(float scale, ref IntPtr rotationWarper); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveDetailSphericalWarperRelease(ref IntPtr warper); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveDetailFisheyeWarperCreate(float scale, ref IntPtr rotationWarper); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveDetailFisheyeWarperRelease(ref IntPtr warper); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveDetailStereographicWarperCreate(float scale, ref IntPtr rotationWarper); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveDetailStereographicWarperRelease(ref IntPtr warper); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveDetailCompressedRectilinearWarperCreate(float scale, ref IntPtr rotationWarper); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveDetailCompressedRectilinearWarperRelease(ref IntPtr warper); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveDetailPaniniWarperCreate(float scale, ref IntPtr rotationWarper); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveDetailPaniniWarperRelease(ref IntPtr warper); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveDetailPaniniPortraitWarperCreate(float scale, ref IntPtr rotationWarper); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveDetailPaniniPortraitWarperRelease(ref IntPtr warper); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveDetailMercatorWarperCreate(float scale, ref IntPtr rotationWarper); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveDetailMercatorWarperRelease(ref IntPtr warper); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveDetailTransverseMercatorWarperCreate(float scale, ref IntPtr rotationWarper); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveDetailTransverseMercatorWarperRelease(ref IntPtr warper); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveRotationWarperBuildMaps(IntPtr warper, ref Size srcSize, IntPtr K, IntPtr R, IntPtr xmap, IntPtr ymap, ref Rectangle boundingBox); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveRotationWarperWarp(IntPtr warper, IntPtr src, IntPtr K, IntPtr R, Inter interpMode, BorderType borderMode, IntPtr dst, ref Point corner); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveDetailPlaneWarperGpuCreate(float scale, ref IntPtr rotationWarper); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveDetailPlaneWarperGpuRelease(ref IntPtr warper); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveDetailCylindricalWarperGpuCreate(float scale, ref IntPtr rotationWarper); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveDetailCylindricalWarperGpuRelease(ref IntPtr warper); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveDetailSphericalWarperGpuCreate(float scale, ref IntPtr rotationWarper); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveDetailSphericalWarperGpuRelease(ref IntPtr warper); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveNoSeamFinderCreate(ref IntPtr seamFinderPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveNoSeamFinderRelease(ref IntPtr seamFinderPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveVoronoiSeamFinderCreate(ref IntPtr seamFinderPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveVoronoiSeamFinderRelease(ref IntPtr seamFinderPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveDpSeamFinderCreate(DpSeamFinder.CostFunction costFunc, ref IntPtr seamFinderPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveDpSeamFinderRelease(ref IntPtr seamFinderPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveGraphCutSeamFinderCreate(GraphCutSeamFinder.CostFunction costType, float terminalCost, float badRegionPenalty, ref IntPtr seamFinderPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveGraphCutSeamFinderRelease(ref IntPtr seamFinderPtr); static StitchingInvoke() { CvInvoke.Init(); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveStitcherCreate(Stitcher.Mode model, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern Stitcher.Status cveStitcherStitch(IntPtr stitcherWrapper, IntPtr images, IntPtr pano); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveStitcherSetFeaturesFinder(IntPtr stitcherWrapper, IntPtr finder); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveStitcherSetWarper(IntPtr stitcher, IntPtr creator); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveStitcherSetBlender(IntPtr stitcher, IntPtr b); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveStitcherSetExposureCompensator(IntPtr stitcher, IntPtr exposureComp); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveStitcherSetBundleAdjuster(IntPtr stitcher, IntPtr bundleAdjuster); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveStitcherSetSeamFinder(IntPtr stitcher, IntPtr seamFinder); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveStitcherSetEstimator(IntPtr stitcher, IntPtr estimator); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveStitcherSetFeaturesMatcher(IntPtr stitcher, IntPtr featuresMatcher); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveStitcherRelease(ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveStitcherSetWaveCorrection(IntPtr stitcher, [MarshalAs(UnmanagedType.U1)] bool flag); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.U1)] internal static extern bool cveStitcherGetWaveCorrection(IntPtr stitcher); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveStitcherSetWaveCorrectionKind(IntPtr stitcher, Stitcher.WaveCorrectionType kind); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern Stitcher.WaveCorrectionType cveStitcherGetWaveCorrectionKind(IntPtr stitcher); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveStitcherSetPanoConfidenceThresh(IntPtr stitcher, double confThresh); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern double cveStitcherGetPanoConfidenceThresh(IntPtr stitcher); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveStitcherSetCompositingResol(IntPtr stitcher, double resolMpx); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern double cveStitcherGetCompositingResol(IntPtr stitcher); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveStitcherSetSeamEstimationResol(IntPtr stitcher, double resolMpx); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern double cveStitcherGetSeamEstimationResol(IntPtr stitcher); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveStitcherSetRegistrationResol(IntPtr stitcher, double resolMpx); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern double cveStitcherGetRegistrationResol(IntPtr stitcher); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern Inter cveStitcherGetInterpolationFlags(IntPtr stitcher); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveStitcherSetInterpolationFlags(IntPtr stitcher, Inter interpFlags); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern Stitcher.Status cveStitcherEstimateTransform(IntPtr stitcher, IntPtr images, IntPtr masks); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern Stitcher.Status cveStitcherComposePanorama1(IntPtr stitcher, IntPtr pano); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern Stitcher.Status cveStitcherComposePanorama2(IntPtr stitcher, IntPtr images, IntPtr pano); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern double cveStitcherWorkScale(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cvePlaneWarperCreate(ref IntPtr warperCreator); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cvePlaneWarperRelease(ref IntPtr warper); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveCylindricalWarperCreate(ref IntPtr warperCreator); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveCylindricalWarperRelease(ref IntPtr warper); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveSphericalWarperCreate(ref IntPtr warperCreator); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveSphericalWarperRelease(ref IntPtr warper); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveFisheyeWarperCreate(ref IntPtr warperCreator); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveFisheyeWarperRelease(ref IntPtr warper); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveStereographicWarperCreate(ref IntPtr warperCreator); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveStereographicWarperRelease(ref IntPtr warper); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveCompressedRectilinearWarperCreate(ref IntPtr warperCreator); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveCompressedRectilinearWarperRelease(ref IntPtr warper); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cvePaniniWarperCreate(ref IntPtr warperCreator); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cvePaniniWarperRelease(ref IntPtr warper); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cvePaniniPortraitWarperCreate(ref IntPtr warperCreator); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cvePaniniPortraitWarperRelease(ref IntPtr warper); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveMercatorWarperCreate(ref IntPtr warperCreator); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveMercatorWarperRelease(ref IntPtr warper); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveTransverseMercatorWarperCreate(ref IntPtr warperCreator); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveTransverseMercatorWarperRelease(ref IntPtr warper); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cvePlaneWarperGpuCreate(ref IntPtr warperCreator); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cvePlaneWarperGpuRelease(ref IntPtr warper); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveCylindricalWarperGpuCreate(ref IntPtr warperCreator); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveCylindricalWarperGpuRelease(ref IntPtr warper); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveSphericalWarperGpuCreate(ref IntPtr warperCreator); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveSphericalWarperGpuRelease(ref IntPtr warper); } public abstract class BundleAdjusterBase : UnmanagedObject { protected IntPtr _bundleAdjusterPtr; public IntPtr BundleAdjusterPtr => _bundleAdjusterPtr; protected override void DisposeObject() { if (_bundleAdjusterPtr != IntPtr.Zero) { _bundleAdjusterPtr = IntPtr.Zero; } } } public class NoBundleAdjuster : BundleAdjusterBase { public NoBundleAdjuster() { _ptr = StitchingInvoke.cveNoBundleAdjusterCreate(ref _bundleAdjusterPtr); } protected override void DisposeObject() { base.DisposeObject(); if (_ptr != IntPtr.Zero) { StitchingInvoke.cveNoBundleAdjusterRelease(ref _ptr); } } } public class BundleAdjusterReproj : BundleAdjusterBase { public BundleAdjusterReproj() { _ptr = StitchingInvoke.cveBundleAdjusterReprojCreate(ref _bundleAdjusterPtr); } protected override void DisposeObject() { base.DisposeObject(); if (_ptr != IntPtr.Zero) { StitchingInvoke.cveBundleAdjusterReprojRelease(ref _ptr); } } } public class BundleAdjusterRay : BundleAdjusterBase { public BundleAdjusterRay() { _ptr = StitchingInvoke.cveBundleAdjusterRayCreate(ref _bundleAdjusterPtr); } protected override void DisposeObject() { base.DisposeObject(); if (_ptr != IntPtr.Zero) { StitchingInvoke.cveBundleAdjusterRayRelease(ref _ptr); } } } public class BundleAdjusterAffine : BundleAdjusterBase { public BundleAdjusterAffine() { _ptr = StitchingInvoke.cveBundleAdjusterAffineCreate(ref _bundleAdjusterPtr); } protected override void DisposeObject() { base.DisposeObject(); if (_ptr != IntPtr.Zero) { StitchingInvoke.cveBundleAdjusterAffineRelease(ref _ptr); } } } public class BundleAdjusterAffinePartial : BundleAdjusterBase { public BundleAdjusterAffinePartial() { _ptr = StitchingInvoke.cveBundleAdjusterAffinePartialCreate(ref _bundleAdjusterPtr); } protected override void DisposeObject() { base.DisposeObject(); if (_ptr != IntPtr.Zero) { StitchingInvoke.cveBundleAdjusterAffinePartialRelease(ref _ptr); } } } public abstract class Estimator : UnmanagedObject { protected IntPtr _estimatorPtr; public IntPtr EstimatorPtr => _estimatorPtr; protected override void DisposeObject() { if (_estimatorPtr != IntPtr.Zero) { _estimatorPtr = IntPtr.Zero; } } } public class HomographyBasedEstimator : Estimator { public HomographyBasedEstimator(bool isFocalsEstimated) { _ptr = StitchingInvoke.cveHomographyBasedEstimatorCreate(isFocalsEstimated, ref _estimatorPtr); } protected override void DisposeObject() { base.DisposeObject(); if (_ptr != IntPtr.Zero) { StitchingInvoke.cveHomographyBasedEstimatorRelease(ref _ptr); } } } public class AffineBasedEstimator : Estimator { public AffineBasedEstimator() { _ptr = StitchingInvoke.cveAffineBasedEstimatorCreate(ref _estimatorPtr); } protected override void DisposeObject() { base.DisposeObject(); if (_ptr != IntPtr.Zero) { StitchingInvoke.cveAffineBasedEstimatorRelease(ref _ptr); } } } public abstract class ExposureCompensator : UnmanagedObject { protected IntPtr _exposureCompensatorPtr; public IntPtr ExposureCompensatorPtr => _exposureCompensatorPtr; protected override void DisposeObject() { if (_exposureCompensatorPtr != IntPtr.Zero) { _exposureCompensatorPtr = IntPtr.Zero; } } } public class NoExposureCompensator : ExposureCompensator { public NoExposureCompensator() { _ptr = StitchingInvoke.cveNoExposureCompensatorCreate(ref _exposureCompensatorPtr); } protected override void DisposeObject() { base.DisposeObject(); if (_ptr != IntPtr.Zero) { StitchingInvoke.cveNoExposureCompensatorRelease(ref _ptr); } } } public class GainCompensator : ExposureCompensator { public GainCompensator(int nrFeeds) { _ptr = StitchingInvoke.cveGainCompensatorCreate(nrFeeds, ref _exposureCompensatorPtr); } protected override void DisposeObject() { if (_ptr != IntPtr.Zero) { StitchingInvoke.cveGainCompensatorRelease(ref _ptr); } base.DisposeObject(); } } public class ChannelsCompensator : ExposureCompensator { public ChannelsCompensator(int nrFeeds) { _ptr = StitchingInvoke.cveChannelsCompensatorCreate(nrFeeds, ref _exposureCompensatorPtr); } protected override void DisposeObject() { if (_ptr != IntPtr.Zero) { StitchingInvoke.cveChannelsCompensatorRelease(ref _ptr); } base.DisposeObject(); } } public class BlocksGainCompensator : ExposureCompensator { public BlocksGainCompensator(int blWidth = 32, int blHeight = 32, int nrFeeds = 1) { _ptr = StitchingInvoke.cveBlocksGainCompensatorCreate(blWidth, blHeight, nrFeeds, ref _exposureCompensatorPtr); } protected override void DisposeObject() { if (_ptr != IntPtr.Zero) { StitchingInvoke.cveBlocksGainCompensatorRelease(ref _ptr); } base.DisposeObject(); } } public class BlocksChannelsCompensator : ExposureCompensator { public BlocksChannelsCompensator(int blWidth = 32, int blHeight = 32, int nrFeeds = 1) { _ptr = StitchingInvoke.cveBlocksChannelsCompensatorCreate(blWidth, blHeight, nrFeeds, ref _exposureCompensatorPtr); } protected override void DisposeObject() { if (_ptr != IntPtr.Zero) { StitchingInvoke.cveBlocksChannelsCompensatorRelease(ref _ptr); } base.DisposeObject(); } } public class FeatherBlender : Blender { public FeatherBlender(float sharpness = 0.02f) { _ptr = StitchingInvoke.cveFeatherBlenderCreate(sharpness, ref _blenderPtr); } protected override void DisposeObject() { base.DisposeObject(); if (_ptr != IntPtr.Zero) { StitchingInvoke.cveFeatherBlenderRelease(ref _ptr); } } } public abstract class FeaturesMatcher : UnmanagedObject { protected IntPtr _featuresMatcherPtr; public IntPtr FeaturesMatcherPtr => _featuresMatcherPtr; protected override void DisposeObject() { if (_featuresMatcherPtr != IntPtr.Zero) { _featuresMatcherPtr = IntPtr.Zero; } } } public class BestOf2NearestMatcher : FeaturesMatcher { public BestOf2NearestMatcher(bool tryUseGpu = false, float matchConf = 0.3f, int numMatchesThresh1 = 6, int numMatchesThresh2 = 6) { _ptr = StitchingInvoke.cveBestOf2NearestMatcherCreate(tryUseGpu, matchConf, numMatchesThresh1, numMatchesThresh2, ref _featuresMatcherPtr); } protected override void DisposeObject() { base.DisposeObject(); if (_ptr != IntPtr.Zero) { StitchingInvoke.cveBestOf2NearestMatcherRelease(ref _ptr); } } } public class BestOf2NearestRangeMatcher : FeaturesMatcher { public BestOf2NearestRangeMatcher(int rangeWidth = 5, bool tryUseGpu = false, float matchConf = 0.3f, int numMatchesThresh1 = 6, int numMatchesThresh2 = 6) { _ptr = StitchingInvoke.cveBestOf2NearestRangeMatcherCreate(rangeWidth, tryUseGpu, matchConf, numMatchesThresh1, numMatchesThresh2, ref _featuresMatcherPtr); } protected override void DisposeObject() { base.DisposeObject(); if (_ptr != IntPtr.Zero) { StitchingInvoke.cveBestOf2NearestRangeMatcherRelease(ref _ptr); } } } public class AffineBestOf2NearestMatcher : FeaturesMatcher { public AffineBestOf2NearestMatcher(bool fullAffine = false, bool tryUseGpu = false, float matchConf = 0.3f, int numMatchesThresh1 = 6) { _ptr = StitchingInvoke.cveAffineBestOf2NearestMatcherCreate(fullAffine, tryUseGpu, matchConf, numMatchesThresh1, ref _featuresMatcherPtr); } protected override void DisposeObject() { base.DisposeObject(); if (_ptr != IntPtr.Zero) { StitchingInvoke.cveAffineBestOf2NearestMatcherRelease(ref _ptr); } } } public class MultiBandBlender : Blender { public MultiBandBlender(bool tryGpu = true, int numBands = 5, DepthType weightType = DepthType.Cv32F) { _ptr = StitchingInvoke.cveMultiBandBlenderCreate(tryGpu ? 1 : 0, numBands, weightType, ref _blenderPtr); } protected override void DisposeObject() { if (_ptr != IntPtr.Zero) { StitchingInvoke.cveMultiBandBlenderRelease(ref _ptr); } base.DisposeObject(); } } public abstract class RotationWarper : UnmanagedObject { protected IntPtr _rotationWarper; protected override void DisposeObject() { if (_rotationWarper != IntPtr.Zero) { _rotationWarper = IntPtr.Zero; } } public Rectangle BuildMaps(Size srcSize, IInputArray K, IInputArray R, IOutputArray xmap, IOutputArray ymap) { Rectangle boundingBox = default(Rectangle); using InputArray inputArray = K.GetInputArray(); using InputArray inputArray2 = R.GetInputArray(); using OutputArray outputArray = xmap.GetOutputArray(); using OutputArray outputArray2 = ymap.GetOutputArray(); StitchingInvoke.cveRotationWarperBuildMaps(_rotationWarper, ref srcSize, inputArray, inputArray2, outputArray, outputArray2, ref boundingBox); return boundingBox; } public Point Warp(IInputArray src, IInputArray K, IInputArray R, Inter interpMode, BorderType borderMode, IOutputArray dst) { Point corner = default(Point); using InputArray inputArray = src.GetInputArray(); using InputArray inputArray2 = K.GetInputArray(); using InputArray inputArray3 = R.GetInputArray(); using OutputArray outputArray = dst.GetOutputArray(); StitchingInvoke.cveRotationWarperWarp(_rotationWarper, inputArray, inputArray2, inputArray3, interpMode, borderMode, outputArray, ref corner); return corner; } } public class DetailPlaneWarper : RotationWarper { public DetailPlaneWarper(float scale) { _ptr = StitchingInvoke.cveDetailPlaneWarperCreate(scale, ref _rotationWarper); } protected override void DisposeObject() { base.DisposeObject(); if (_ptr != IntPtr.Zero) { StitchingInvoke.cveDetailPlaneWarperRelease(ref _ptr); } } } public class DetailCylindricalWarper : RotationWarper { public DetailCylindricalWarper(float scale) { _ptr = StitchingInvoke.cveDetailCylindricalWarperCreate(scale, ref _rotationWarper); } protected override void DisposeObject() { base.DisposeObject(); if (_ptr != IntPtr.Zero) { StitchingInvoke.cveDetailCylindricalWarperRelease(ref _ptr); } } } public class DetailSphericalWarper : RotationWarper { public DetailSphericalWarper(float scale) { _ptr = StitchingInvoke.cveDetailSphericalWarperCreate(scale, ref _rotationWarper); } protected override void DisposeObject() { base.DisposeObject(); if (_ptr != IntPtr.Zero) { StitchingInvoke.cveDetailSphericalWarperRelease(ref _ptr); } } } public class DetailFisheyeWarper : RotationWarper { public DetailFisheyeWarper(float scale) { _ptr = StitchingInvoke.cveDetailFisheyeWarperCreate(scale, ref _rotationWarper); } protected override void DisposeObject() { base.DisposeObject(); if (_ptr != IntPtr.Zero) { StitchingInvoke.cveDetailFisheyeWarperRelease(ref _ptr); } } } public class DetailStereographicWarper : RotationWarper { public DetailStereographicWarper(float scale) { _ptr = StitchingInvoke.cveDetailStereographicWarperCreate(scale, ref _rotationWarper); } protected override void DisposeObject() { base.DisposeObject(); if (_ptr != IntPtr.Zero) { StitchingInvoke.cveDetailStereographicWarperRelease(ref _ptr); } } } public class DetailCompressedRectilinearWarper : RotationWarper { public DetailCompressedRectilinearWarper(float scale) { _ptr = StitchingInvoke.cveDetailCompressedRectilinearWarperCreate(scale, ref _rotationWarper); } protected override void DisposeObject() { base.DisposeObject(); if (_ptr != IntPtr.Zero) { StitchingInvoke.cveDetailCompressedRectilinearWarperRelease(ref _ptr); } } } public class DetailPaniniWarper : RotationWarper { public DetailPaniniWarper(float scale) { _ptr = StitchingInvoke.cveDetailPaniniWarperCreate(scale, ref _rotationWarper); } protected override void DisposeObject() { base.DisposeObject(); if (_ptr != IntPtr.Zero) { StitchingInvoke.cveDetailPaniniWarperRelease(ref _ptr); } } } public class DetailPaniniPortraitWarper : RotationWarper { public DetailPaniniPortraitWarper(float scale) { _ptr = StitchingInvoke.cveDetailPaniniPortraitWarperCreate(scale, ref _rotationWarper); } protected override void DisposeObject() { base.DisposeObject(); if (_ptr != IntPtr.Zero) { StitchingInvoke.cveDetailPaniniPortraitWarperRelease(ref _ptr); } } } public class DetailMercatorWarper : RotationWarper { public DetailMercatorWarper(float scale) { _ptr = StitchingInvoke.cveDetailMercatorWarperCreate(scale, ref _rotationWarper); } protected override void DisposeObject() { base.DisposeObject(); if (_ptr != IntPtr.Zero) { StitchingInvoke.cveDetailMercatorWarperRelease(ref _ptr); } } } public class DetailTransverseMercatorWarper : RotationWarper { public DetailTransverseMercatorWarper(float scale) { _ptr = StitchingInvoke.cveDetailTransverseMercatorWarperCreate(scale, ref _rotationWarper); } protected override void DisposeObject() { base.DisposeObject(); if (_ptr != IntPtr.Zero) { StitchingInvoke.cveDetailTransverseMercatorWarperRelease(ref _ptr); } } } public class DetailPlaneWarperGpu : RotationWarper { public DetailPlaneWarperGpu(float scale) { _ptr = StitchingInvoke.cveDetailPlaneWarperGpuCreate(scale, ref _rotationWarper); } protected override void DisposeObject() { base.DisposeObject(); if (_ptr != IntPtr.Zero) { StitchingInvoke.cveDetailPlaneWarperGpuRelease(ref _ptr); } } } public class DetailCylindricalWarperGpu : RotationWarper { public DetailCylindricalWarperGpu(float scale) { _ptr = StitchingInvoke.cveDetailCylindricalWarperGpuCreate(scale, ref _rotationWarper); } protected override void DisposeObject() { base.DisposeObject(); if (_ptr != IntPtr.Zero) { StitchingInvoke.cveDetailCylindricalWarperGpuRelease(ref _ptr); } } } public class DetailSphericalWarperGpu : RotationWarper { public DetailSphericalWarperGpu(float scale) { _ptr = StitchingInvoke.cveDetailSphericalWarperGpuCreate(scale, ref _rotationWarper); } protected override void DisposeObject() { base.DisposeObject(); if (_ptr != IntPtr.Zero) { StitchingInvoke.cveDetailSphericalWarperGpuRelease(ref _ptr); } } } public abstract class SeamFinder : UnmanagedObject { protected IntPtr _seamFinderPtr; public IntPtr SeamFinderPtr => _seamFinderPtr; protected override void DisposeObject() { if (_seamFinderPtr != IntPtr.Zero) { _seamFinderPtr = IntPtr.Zero; } } } public class NoSeamFinder : SeamFinder { public NoSeamFinder() { _ptr = StitchingInvoke.cveNoSeamFinderCreate(ref _seamFinderPtr); } protected override void DisposeObject() { base.DisposeObject(); if (_ptr != IntPtr.Zero) { StitchingInvoke.cveNoSeamFinderRelease(ref _ptr); } } } public class VoronoiSeamFinder : SeamFinder { public VoronoiSeamFinder() { _ptr = StitchingInvoke.cveVoronoiSeamFinderCreate(ref _seamFinderPtr); } protected override void DisposeObject() { base.DisposeObject(); if (_ptr != IntPtr.Zero) { StitchingInvoke.cveVoronoiSeamFinderRelease(ref _ptr); } } } public class DpSeamFinder : SeamFinder { public enum CostFunction { Color, ColorGrad } public DpSeamFinder(CostFunction costFunc = CostFunction.Color) { _ptr = StitchingInvoke.cveDpSeamFinderCreate(costFunc, ref _seamFinderPtr); } protected override void DisposeObject() { base.DisposeObject(); if (_ptr != IntPtr.Zero) { StitchingInvoke.cveDpSeamFinderRelease(ref _ptr); } } } public class GraphCutSeamFinder : SeamFinder { public enum CostFunction { Color, ColorGrad } public GraphCutSeamFinder(CostFunction costFunc = CostFunction.Color, float terminalCost = 1f, float badRegionPenalty = 1f) { _ptr = StitchingInvoke.cveGraphCutSeamFinderCreate(costFunc, terminalCost, badRegionPenalty, ref _seamFinderPtr); } protected override void DisposeObject() { base.DisposeObject(); if (_ptr != IntPtr.Zero) { StitchingInvoke.cveGraphCutSeamFinderRelease(ref _ptr); } } } public class Stitcher : SharedPtrObject { public enum Status { Ok, ErrNeedMoreImgs, ErrHomographyEstFail, ErrCameraParamsAdjustFail } public enum WaveCorrectionType { Horiz, Vert } public enum Mode { Panorama, Scans } public bool WaveCorrection { get { return StitchingInvoke.cveStitcherGetWaveCorrection(_ptr); } set { StitchingInvoke.cveStitcherSetWaveCorrection(_ptr, value); } } public WaveCorrectionType WaveCorrectionKind { get { return StitchingInvoke.cveStitcherGetWaveCorrectionKind(_ptr); } set { StitchingInvoke.cveStitcherSetWaveCorrectionKind(_ptr, value); } } public double PanoConfidenceThresh { get { return StitchingInvoke.cveStitcherGetPanoConfidenceThresh(_ptr); } set { StitchingInvoke.cveStitcherSetPanoConfidenceThresh(_ptr, value); } } public double CompositingResol { get { return StitchingInvoke.cveStitcherGetCompositingResol(_ptr); } set { StitchingInvoke.cveStitcherSetCompositingResol(_ptr, value); } } public double SeamEstimationResol { get { return StitchingInvoke.cveStitcherGetSeamEstimationResol(_ptr); } set { StitchingInvoke.cveStitcherSetSeamEstimationResol(_ptr, value); } } public double RegistrationResol { get { return StitchingInvoke.cveStitcherGetRegistrationResol(_ptr); } set { StitchingInvoke.cveStitcherSetRegistrationResol(_ptr, value); } } public Inter InterpolationFlags { get { return StitchingInvoke.cveStitcherGetInterpolationFlags(_ptr); } set { StitchingInvoke.cveStitcherSetInterpolationFlags(_ptr, value); } } public double WorkScale => StitchingInvoke.cveStitcherWorkScale(_ptr); public Stitcher(Mode mode = Mode.Panorama) { _ptr = StitchingInvoke.cveStitcherCreate(mode, ref _sharedPtr); } public Status Stitch(IInputArray images, IOutputArray pano) { using InputArray inputArray = images.GetInputArray(); using OutputArray outputArray = pano.GetOutputArray(); return StitchingInvoke.cveStitcherStitch(_ptr, inputArray, outputArray); } public Status EstimateTransform(IInputArrayOfArrays images, IInputArrayOfArrays masks = null) { using InputArray inputArray = images.GetInputArray(); using InputArray inputArray2 = ((masks == null) ? InputArray.GetEmpty() : masks.GetInputArray()); return StitchingInvoke.cveStitcherEstimateTransform(_ptr, inputArray, inputArray2); } public Status ComposePanorama(IOutputArray pano) { using OutputArray outputArray = pano.GetOutputArray(); return StitchingInvoke.cveStitcherComposePanorama1(_ptr, outputArray); } public Status ComposePanorama(IInputArrayOfArrays images, IOutputArray pano) { using InputArray inputArray = images.GetInputArray(); using OutputArray outputArray = pano.GetOutputArray(); return StitchingInvoke.cveStitcherComposePanorama2(_ptr, inputArray, outputArray); } public void SetFeaturesFinder(Feature2D finder) { StitchingInvoke.cveStitcherSetFeaturesFinder(_ptr, finder.Feature2DPtr); } public void SetExposureCompensator(ExposureCompensator exposureCompensator) { StitchingInvoke.cveStitcherSetExposureCompensator(_ptr, exposureCompensator.ExposureCompensatorPtr); } public void SetBundleAdjusterCompensator(BundleAdjusterBase bundleAdjuster) { StitchingInvoke.cveStitcherSetBundleAdjuster(_ptr, bundleAdjuster.BundleAdjusterPtr); } public void SetSeamFinder(SeamFinder seamFinder) { StitchingInvoke.cveStitcherSetSeamFinder(_ptr, seamFinder.SeamFinderPtr); } public void SetEstimator(Estimator estimator) { StitchingInvoke.cveStitcherSetEstimator(_ptr, estimator.EstimatorPtr); } public void SetFeaturesMatcher(FeaturesMatcher featuresMatcher) { StitchingInvoke.cveStitcherSetFeaturesMatcher(_ptr, featuresMatcher.FeaturesMatcherPtr); } public void SetWarper(WarperCreator warperCreator) { StitchingInvoke.cveStitcherSetWarper(_ptr, warperCreator.WarperCreatorPtr); } public void SetBlender(Blender blender) { StitchingInvoke.cveStitcherSetBlender(_ptr, blender.BlenderPtr); } protected override void DisposeObject() { if (_sharedPtr != IntPtr.Zero) { StitchingInvoke.cveStitcherRelease(ref _sharedPtr); _ptr = IntPtr.Zero; } } } public abstract class WarperCreator : UnmanagedObject { protected IntPtr _warperCreator; public IntPtr WarperCreatorPtr => _warperCreator; protected override void DisposeObject() { if (_warperCreator != IntPtr.Zero) { _warperCreator = IntPtr.Zero; } } } public class PlaneWarper : WarperCreator { public PlaneWarper() { _ptr = StitchingInvoke.cvePlaneWarperCreate(ref _warperCreator); } protected override void DisposeObject() { base.DisposeObject(); if (_ptr != IntPtr.Zero) { StitchingInvoke.cvePlaneWarperRelease(ref _ptr); } } } public class CylindricalWarper : WarperCreator { public CylindricalWarper() { _ptr = StitchingInvoke.cveCylindricalWarperCreate(ref _warperCreator); } protected override void DisposeObject() { base.DisposeObject(); if (_ptr != IntPtr.Zero) { StitchingInvoke.cveCylindricalWarperRelease(ref _ptr); } } } public class SphericalWarper : WarperCreator { public SphericalWarper() { _ptr = StitchingInvoke.cveSphericalWarperCreate(ref _warperCreator); } protected override void DisposeObject() { base.DisposeObject(); if (_ptr != IntPtr.Zero) { StitchingInvoke.cveSphericalWarperRelease(ref _ptr); } } } public class FisheyeWarper : WarperCreator { public FisheyeWarper() { _ptr = StitchingInvoke.cveFisheyeWarperCreate(ref _warperCreator); } protected override void DisposeObject() { base.DisposeObject(); if (_ptr != IntPtr.Zero) { StitchingInvoke.cveFisheyeWarperRelease(ref _ptr); } } } public class StereographicWarper : WarperCreator { public StereographicWarper() { _ptr = StitchingInvoke.cveStereographicWarperCreate(ref _warperCreator); } protected override void DisposeObject() { base.DisposeObject(); if (_ptr != IntPtr.Zero) { StitchingInvoke.cveStereographicWarperRelease(ref _ptr); } } } public class CompressedRectilinearWarper : WarperCreator { public CompressedRectilinearWarper() { _ptr = StitchingInvoke.cveCompressedRectilinearWarperCreate(ref _warperCreator); } protected override void DisposeObject() { base.DisposeObject(); if (_ptr != IntPtr.Zero) { StitchingInvoke.cveCompressedRectilinearWarperRelease(ref _ptr); } } } public class PaniniWarper : WarperCreator { public PaniniWarper() { _ptr = StitchingInvoke.cvePaniniWarperCreate(ref _warperCreator); } protected override void DisposeObject() { base.DisposeObject(); if (_ptr != IntPtr.Zero) { StitchingInvoke.cvePaniniWarperRelease(ref _ptr); } } } public class PaniniPortraitWarper : WarperCreator { public PaniniPortraitWarper() { _ptr = StitchingInvoke.cvePaniniPortraitWarperCreate(ref _warperCreator); } protected override void DisposeObject() { base.DisposeObject(); if (_ptr != IntPtr.Zero) { StitchingInvoke.cvePaniniPortraitWarperRelease(ref _ptr); } } } public class MercatorWarper : WarperCreator { public MercatorWarper() { _ptr = StitchingInvoke.cveMercatorWarperCreate(ref _warperCreator); } protected override void DisposeObject() { base.DisposeObject(); if (_ptr != IntPtr.Zero) { StitchingInvoke.cveMercatorWarperRelease(ref _ptr); } } } public class TransverseMercatorWarper : WarperCreator { public TransverseMercatorWarper() { _ptr = StitchingInvoke.cveTransverseMercatorWarperCreate(ref _warperCreator); } protected override void DisposeObject() { base.DisposeObject(); if (_ptr != IntPtr.Zero) { StitchingInvoke.cveTransverseMercatorWarperRelease(ref _ptr); } } } public class PlaneWarperGpu : WarperCreator { public PlaneWarperGpu() { _ptr = StitchingInvoke.cvePlaneWarperGpuCreate(ref _warperCreator); } protected override void DisposeObject() { base.DisposeObject(); if (_ptr != IntPtr.Zero) { StitchingInvoke.cvePlaneWarperGpuRelease(ref _ptr); } } } public class CylindricalWarperGpu : WarperCreator { public CylindricalWarperGpu() { _ptr = StitchingInvoke.cveCylindricalWarperGpuCreate(ref _warperCreator); } protected override void DisposeObject() { base.DisposeObject(); if (_ptr != IntPtr.Zero) { StitchingInvoke.cveCylindricalWarperGpuRelease(ref _ptr); } } } public class SphericalWarperGpu : WarperCreator { public SphericalWarperGpu() { _ptr = StitchingInvoke.cveSphericalWarperGpuCreate(ref _warperCreator); } protected override void DisposeObject() { base.DisposeObject(); if (_ptr != IntPtr.Zero) { StitchingInvoke.cveSphericalWarperGpuRelease(ref _ptr); } } } } namespace Emgu.CV.Shape { public abstract class HistogramCostExtractor : SharedPtrObject { protected override void DisposeObject() { if (_ptr != IntPtr.Zero) { ShapeInvoke.cveHistogramCostExtractorRelease(ref _sharedPtr); } } } public class NormHistogramCostExtractor : HistogramCostExtractor { public NormHistogramCostExtractor(Emgu.CV.CvEnum.DistType flag = Emgu.CV.CvEnum.DistType.L2, int nDummies = 25, float defaultCost = 0.2f) { _ptr = ShapeInvoke.cveNormHistogramCostExtractorCreate(flag, nDummies, defaultCost, ref _sharedPtr); } } public class EMDHistogramCostExtractor : HistogramCostExtractor { public EMDHistogramCostExtractor(Emgu.CV.CvEnum.DistType flag = Emgu.CV.CvEnum.DistType.L2, int nDummies = 25, float defaultCost = 0.2f) { _ptr = ShapeInvoke.cveEMDHistogramCostExtractorCreate(flag, nDummies, defaultCost, ref _sharedPtr); } } public class ChiHistogramCostExtractor : HistogramCostExtractor { public ChiHistogramCostExtractor(int nDummies = 25, float defaultCost = 0.2f) { _ptr = ShapeInvoke.cveChiHistogramCostExtractorCreate(nDummies, defaultCost, ref _sharedPtr); } } public class EMDL1HistogramCostExtractor : HistogramCostExtractor { public EMDL1HistogramCostExtractor(int nDummies = 25, float defaultCost = 0.2f) { _ptr = ShapeInvoke.cveEMDL1HistogramCostExtractorCreate(nDummies, defaultCost, ref _sharedPtr); } } public static class ShapeInvoke { static ShapeInvoke() { CvInvoke.Init(); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveNormHistogramCostExtractorCreate(Emgu.CV.CvEnum.DistType flag, int nDummies, float defaultCost, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveEMDHistogramCostExtractorCreate(Emgu.CV.CvEnum.DistType flag, int nDummies, float defaultCost, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveChiHistogramCostExtractorCreate(int nDummies, float defaultCost, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveEMDL1HistogramCostExtractorCreate(int nDummies, float defaultCost, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveHistogramCostExtractorRelease(ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int cveShapeContextDistanceExtractorGetIterations(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveShapeContextDistanceExtractorSetIterations(IntPtr obj, int val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int cveShapeContextDistanceExtractorGetAngularBins(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveShapeContextDistanceExtractorSetAngularBins(IntPtr obj, int val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int cveShapeContextDistanceExtractorGetRadialBins(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveShapeContextDistanceExtractorSetRadialBins(IntPtr obj, int val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern float cveShapeContextDistanceExtractorGetInnerRadius(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveShapeContextDistanceExtractorSetInnerRadius(IntPtr obj, float val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern float cveShapeContextDistanceExtractorGetOuterRadius(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveShapeContextDistanceExtractorSetOuterRadius(IntPtr obj, float val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.U1)] internal static extern bool cveShapeContextDistanceExtractorGetRotationInvariant(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveShapeContextDistanceExtractorSetRotationInvariant(IntPtr obj, [MarshalAs(UnmanagedType.U1)] bool val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern float cveShapeContextDistanceExtractorGetShapeContextWeight(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveShapeContextDistanceExtractorSetShapeContextWeight(IntPtr obj, float val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern float cveShapeContextDistanceExtractorGetImageAppearanceWeight(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveShapeContextDistanceExtractorSetImageAppearanceWeight(IntPtr obj, float val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern float cveShapeContextDistanceExtractorGetBendingEnergyWeight(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveShapeContextDistanceExtractorSetBendingEnergyWeight(IntPtr obj, float val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern float cveShapeContextDistanceExtractorGetStdDev(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveShapeContextDistanceExtractorSetStdDev(IntPtr obj, float val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveShapeContextDistanceExtractorCreate(int nAngularBins, int nRadialBins, float innerRadius, float outerRadius, int iterations, IntPtr comparer, IntPtr transformer, ref IntPtr shapeDistanceExtractor, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveShapeContextDistanceExtractorRelease(ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveHausdorffDistanceExtractorCreate(Emgu.CV.CvEnum.DistType distanceFlag, float rankProp, ref IntPtr shapeDistanceExtractor, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveHausdorffDistanceExtractorRelease(ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern float cveShapeDistanceExtractorComputeDistance(IntPtr extractor, IntPtr contour1, IntPtr contour2); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveAffineTransformerCreate([MarshalAs(UnmanagedType.U1)] bool fullAffine, ref IntPtr transformer, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveAffineTransformerRelease(ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveThinPlateSplineShapeTransformerCreate(double regularizationParameter, ref IntPtr transformer, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveThinPlateSplineShapeTransformerRelease(ref IntPtr sharedPtr); public static void EstimateTransformation(this IShapeTransformer transformer, IInputArray transformingShape, IInputArray targetShape, VectorOfDMatch matches) { using InputArray inputArray = transformingShape.GetInputArray(); using InputArray inputArray2 = targetShape.GetInputArray(); cveShapeTransformerEstimateTransformation(transformer.ShapeTransformerPtr, inputArray, inputArray2, matches); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveShapeTransformerEstimateTransformation(IntPtr transformer, IntPtr transformingShape, IntPtr targetShape, IntPtr matches); public static float ApplyTransformation(this IShapeTransformer transformer, IInputArray input, IOutputArray output = null) { using InputArray inputArray = input.GetInputArray(); using OutputArray outputArray = ((output == null) ? OutputArray.GetEmpty() : output.GetOutputArray()); return cveShapeTransformerApplyTransformation(transformer.ShapeTransformerPtr, inputArray, outputArray); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern float cveShapeTransformerApplyTransformation(IntPtr transformer, IntPtr input, IntPtr output); public static void WarpImage(this IShapeTransformer transformer, IInputArray transformingImage, IOutputArray output, Inter flags = Inter.Linear, BorderType boarderMode = BorderType.Constant, MCvScalar borderValue = default(MCvScalar)) { using InputArray inputArray = transformingImage.GetInputArray(); using OutputArray outputArray = output.GetOutputArray(); cveShapeTransformerWarpImage(transformer.ShapeTransformerPtr, inputArray, outputArray, flags, boarderMode, ref borderValue); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveShapeTransformerWarpImage(IntPtr transformer, IntPtr transformingImage, IntPtr output, Inter flags, BorderType borderMode, ref MCvScalar borderValue); } public class ShapeContextDistanceExtractor : ShapeDistanceExtractor { public int Iterations { get { return ShapeInvoke.cveShapeContextDistanceExtractorGetIterations(_ptr); } set { ShapeInvoke.cveShapeContextDistanceExtractorSetIterations(_ptr, value); } } public int AngularBins { get { return ShapeInvoke.cveShapeContextDistanceExtractorGetAngularBins(_ptr); } set { ShapeInvoke.cveShapeContextDistanceExtractorSetAngularBins(_ptr, value); } } public int RadialBins { get { return ShapeInvoke.cveShapeContextDistanceExtractorGetRadialBins(_ptr); } set { ShapeInvoke.cveShapeContextDistanceExtractorSetRadialBins(_ptr, value); } } public float InnerRadius { get { return ShapeInvoke.cveShapeContextDistanceExtractorGetInnerRadius(_ptr); } set { ShapeInvoke.cveShapeContextDistanceExtractorSetInnerRadius(_ptr, value); } } public float OuterRadius { get { return ShapeInvoke.cveShapeContextDistanceExtractorGetOuterRadius(_ptr); } set { ShapeInvoke.cveShapeContextDistanceExtractorSetOuterRadius(_ptr, value); } } public bool RotationInvariant { get { return ShapeInvoke.cveShapeContextDistanceExtractorGetRotationInvariant(_ptr); } set { ShapeInvoke.cveShapeContextDistanceExtractorSetRotationInvariant(_ptr, value); } } public float ShapeContextWeight { get { return ShapeInvoke.cveShapeContextDistanceExtractorGetShapeContextWeight(_ptr); } set { ShapeInvoke.cveShapeContextDistanceExtractorSetShapeContextWeight(_ptr, value); } } public float ImageAppearanceWeight { get { return ShapeInvoke.cveShapeContextDistanceExtractorGetImageAppearanceWeight(_ptr); } set { ShapeInvoke.cveShapeContextDistanceExtractorSetImageAppearanceWeight(_ptr, value); } } public float BendingEnergyWeight { get { return ShapeInvoke.cveShapeContextDistanceExtractorGetBendingEnergyWeight(_ptr); } set { ShapeInvoke.cveShapeContextDistanceExtractorSetBendingEnergyWeight(_ptr, value); } } public float StdDev { get { return ShapeInvoke.cveShapeContextDistanceExtractorGetStdDev(_ptr); } set { ShapeInvoke.cveShapeContextDistanceExtractorSetStdDev(_ptr, value); } } public ShapeContextDistanceExtractor(HistogramCostExtractor comparer, IShapeTransformer transformer, int nAngularBins = 12, int nRadialBins = 4, float innerRadius = 0.2f, float outerRadius = 3f, int iterations = 3) { _ptr = ShapeInvoke.cveShapeContextDistanceExtractorCreate(nAngularBins, nRadialBins, innerRadius, outerRadius, iterations, comparer, transformer.ShapeTransformerPtr, ref _shapeDistanceExtractorPtr, ref _sharedPtr); } protected override void DisposeObject() { if (IntPtr.Zero != _ptr) { ShapeInvoke.cveShapeContextDistanceExtractorRelease(ref _sharedPtr); } base.DisposeObject(); } } public abstract class ShapeDistanceExtractor : SharedPtrObject { protected IntPtr _shapeDistanceExtractorPtr; public float ComputeDistance(Point[] contour1, Point[] contour2) { using VectorOfPoint contour3 = new VectorOfPoint(contour1); using VectorOfPoint contour4 = new VectorOfPoint(contour2); return ComputeDistance(contour3, contour4); } public float ComputeDistance(IInputArray contour1, IInputArray contour2) { using InputArray inputArray = contour1.GetInputArray(); using InputArray inputArray2 = contour2.GetInputArray(); return ShapeInvoke.cveShapeDistanceExtractorComputeDistance(_shapeDistanceExtractorPtr, inputArray, inputArray2); } protected override void DisposeObject() { _shapeDistanceExtractorPtr = IntPtr.Zero; } } public class HausdorffDistanceExtractor : ShapeDistanceExtractor { public HausdorffDistanceExtractor(Emgu.CV.CvEnum.DistType distanceFlag = Emgu.CV.CvEnum.DistType.L2, float rankProp = 0.6f) { _ptr = ShapeInvoke.cveHausdorffDistanceExtractorCreate(distanceFlag, rankProp, ref _shapeDistanceExtractorPtr, ref _sharedPtr); } protected override void DisposeObject() { if (_sharedPtr != IntPtr.Zero) { ShapeInvoke.cveHausdorffDistanceExtractorRelease(ref _sharedPtr); _ptr = IntPtr.Zero; } base.DisposeObject(); } } public interface IShapeTransformer { IntPtr ShapeTransformerPtr { get; } } public class ThinPlateSplineShapeTransformer : SharedPtrObject, IShapeTransformer { private IntPtr _shapeTransformerPtr; public IntPtr ShapeTransformerPtr => _shapeTransformerPtr; public ThinPlateSplineShapeTransformer(double regularizationParameter = 0.0) { _ptr = ShapeInvoke.cveThinPlateSplineShapeTransformerCreate(regularizationParameter, ref _shapeTransformerPtr, ref _sharedPtr); } protected override void DisposeObject() { if (_sharedPtr != IntPtr.Zero) { ShapeInvoke.cveThinPlateSplineShapeTransformerRelease(ref _sharedPtr); _ptr = IntPtr.Zero; _shapeTransformerPtr = IntPtr.Zero; } } } public class AffineTransformer : SharedPtrObject, IShapeTransformer { private IntPtr _shapeTransformerPtr; public IntPtr ShapeTransformerPtr => _shapeTransformerPtr; public AffineTransformer(bool fullAffine) { _ptr = ShapeInvoke.cveAffineTransformerCreate(fullAffine, ref _shapeTransformerPtr, ref _sharedPtr); } protected override void DisposeObject() { if (_sharedPtr != IntPtr.Zero) { ShapeInvoke.cveAffineTransformerRelease(ref _sharedPtr); _ptr = IntPtr.Zero; _shapeTransformerPtr = IntPtr.Zero; } } } } namespace Emgu.CV.Structure { [ColorInfo(ConversionCodename = "Bgr")] public struct Bgr : IColor, IEquatable { private MCvScalar _scalar; [DisplayColor(255, 0, 0)] public double Blue { get { return _scalar.V0; } set { _scalar.V0 = value; } } [DisplayColor(0, 255, 0)] public double Green { get { return _scalar.V1; } set { _scalar.V1 = value; } } [DisplayColor(0, 0, 255)] public double Red { get { return _scalar.V2; } set { _scalar.V2 = value; } } public int Dimension => 3; public MCvScalar MCvScalar { get { return _scalar; } set { _scalar = value; } } public Bgr(double blue, double green, double red) { _scalar = new MCvScalar(blue, green, red); } public Bgr(Color winColor) { _scalar = new MCvScalar((int)winColor.B, (int)winColor.G, (int)winColor.R); } public bool Equals(Bgr other) { return MCvScalar.Equals(other.MCvScalar); } public override string ToString() { return $"[{Blue},{Green},{Red}]"; } } [ColorInfo(ConversionCodename = "Bgra")] public struct Bgra : IColor, IEquatable { private MCvScalar _scalar; [DisplayColor(255, 0, 0)] public double Blue { get { return _scalar.V0; } set { _scalar.V0 = value; } } [DisplayColor(0, 255, 0)] public double Green { get { return _scalar.V1; } set { _scalar.V1 = value; } } [DisplayColor(0, 0, 255)] public double Red { get { return _scalar.V2; } set { _scalar.V2 = value; } } [DisplayColor(122, 122, 122)] public double Alpha { get { return _scalar.V3; } set { _scalar.V3 = value; } } public int Dimension => 4; public MCvScalar MCvScalar { get { return _scalar; } set { _scalar = value; } } public Bgra(double blue, double green, double red, double alpha) { _scalar = new MCvScalar(blue, green, red, alpha); } public bool Equals(Bgra other) { return MCvScalar.Equals(other.MCvScalar); } public override string ToString() { return $"[{Blue},{Green},{Red},{Alpha}]"; } } [ColorInfo(ConversionCodename = "Gray")] public struct Gray : IColor, IEquatable { private MCvScalar _scalar; [DisplayColor(122, 122, 122)] public double Intensity { get { return _scalar.V0; } set { _scalar.V0 = value; } } public int Dimension => 1; public MCvScalar MCvScalar { get { return _scalar; } set { _scalar = value; } } public Gray(double intensity) { _scalar = new MCvScalar(intensity); } public override int GetHashCode() { return Intensity.GetHashCode(); } public bool Equals(Gray other) { return MCvScalar.Equals(other.MCvScalar); } public override string ToString() { return $"[{Intensity}]"; } } [ColorInfo(ConversionCodename = "Hls")] public struct Hls : IColor, IEquatable { private MCvScalar _scalar; [DisplayColor(255, 0, 0)] public double Hue { get { return _scalar.V0; } set { _scalar.V0 = value; } } [DisplayColor(122, 122, 122)] public double Lightness { get { return _scalar.V1; } set { _scalar.V1 = value; } } [DisplayColor(122, 122, 122)] public double Satuation { get { return _scalar.V2; } set { _scalar.V2 = value; } } public int Dimension => 3; public MCvScalar MCvScalar { get { return _scalar; } set { _scalar = value; } } public Hls(double hue, double lightness, double satuation) { _scalar = new MCvScalar(hue, lightness, satuation); } public bool Equals(Hls other) { return MCvScalar.Equals(other.MCvScalar); } public override string ToString() { return $"[{Hue},{Lightness},{Satuation}]"; } } [ColorInfo(ConversionCodename = "Hsv")] public struct Hsv : IColor, IEquatable { private MCvScalar _scalar; [DisplayColor(122, 122, 122)] public double Hue { get { return _scalar.V0; } set { _scalar.V0 = value; } } [DisplayColor(122, 122, 122)] public double Satuation { get { return _scalar.V1; } set { _scalar.V1 = value; } } [DisplayColor(122, 122, 122)] public double Value { get { return _scalar.V2; } set { _scalar.V2 = value; } } public int Dimension => 3; public MCvScalar MCvScalar { get { return _scalar; } set { _scalar = value; } } public Hsv(double hue, double satuation, double value) { _scalar = new MCvScalar(hue, satuation, value); } public bool Equals(Hsv other) { return MCvScalar.Equals(other.MCvScalar); } public override string ToString() { return $"[{Hue},{Satuation},{Value}]"; } } [ColorInfo(ConversionCodename = "Lab")] public struct Lab : IColor, IEquatable { private MCvScalar _scalar; [DisplayColor(122, 122, 122)] public double X { get { return _scalar.V0; } set { _scalar.V0 = value; } } [DisplayColor(122, 122, 122)] public double Y { get { return _scalar.V1; } set { _scalar.V1 = value; } } [DisplayColor(122, 122, 122)] public double Z { get { return _scalar.V2; } set { _scalar.V2 = value; } } public int Dimension => 3; public MCvScalar MCvScalar { get { return _scalar; } set { _scalar = value; } } public Lab(double x, double y, double z) { _scalar = new MCvScalar(x, y, z); } public bool Equals(Lab other) { return MCvScalar.Equals(other.MCvScalar); } public override string ToString() { return $"[{X},{Y},{Z}]"; } } [ColorInfo(ConversionCodename = "Luv")] public struct Luv : IColor, IEquatable { private MCvScalar _scalar; [DisplayColor(122, 122, 122)] public double X { get { return _scalar.V0; } set { _scalar.V0 = value; } } [DisplayColor(122, 122, 122)] public double Y { get { return _scalar.V1; } set { _scalar.V1 = value; } } [DisplayColor(122, 122, 122)] public double Z { get { return _scalar.V2; } set { _scalar.V2 = value; } } public int Dimension => 3; public MCvScalar MCvScalar { get { return _scalar; } set { _scalar = value; } } public Luv(double x, double y, double z) { _scalar = new MCvScalar(x, y, z); } public bool Equals(Luv other) { return MCvScalar.Equals(other.MCvScalar); } public override string ToString() { return $"[{X},{Y},{Z}]"; } } [ColorInfo(ConversionCodename = "Rgb")] public struct Rgb : IColor, IEquatable { private MCvScalar _scalar; [DisplayColor(0, 0, 255)] public double Red { get { return _scalar.V0; } set { _scalar.V0 = value; } } [DisplayColor(0, 255, 0)] public double Green { get { return _scalar.V1; } set { _scalar.V1 = value; } } [DisplayColor(255, 0, 0)] public double Blue { get { return _scalar.V2; } set { _scalar.V2 = value; } } public int Dimension => 3; public MCvScalar MCvScalar { get { return _scalar; } set { _scalar = value; } } public Rgb(double red, double green, double blue) { _scalar = new MCvScalar(red, green, blue); } public Rgb(Color winColor) : this((int)winColor.R, (int)winColor.G, (int)winColor.B) { } public bool Equals(Rgb other) { return MCvScalar.Equals(other.MCvScalar); } public override string ToString() { return $"[{Red},{Green},{Blue}]"; } } [ColorInfo(ConversionCodename = "Bgr565")] public struct Bgr565 : IColor, IEquatable { private MCvScalar _scalar; [DisplayColor(0, 0, 255)] public double Red { get { return _scalar.V0; } set { _scalar.V0 = value; } } [DisplayColor(0, 255, 0)] public double Green { get { return _scalar.V1; } set { _scalar.V1 = value; } } [DisplayColor(255, 0, 0)] public double Blue { get { return _scalar.V2; } set { _scalar.V2 = value; } } public int Dimension => 2; public MCvScalar MCvScalar { get { return _scalar; } set { _scalar = value; } } public Bgr565(double red, double green, double blue) { throw new NotImplementedException("Not implemented"); } public Bgr565(Color winColor) : this((int)winColor.R, (int)winColor.G, (int)winColor.B) { } public bool Equals(Bgr565 other) { return MCvScalar.Equals(other.MCvScalar); } public override string ToString() { return $"[{Red},{Green},{Blue}]"; } } [ColorInfo(ConversionCodename = "Rgba")] public struct Rgba : IColor, IEquatable { private MCvScalar _scalar; [DisplayColor(0, 0, 255)] public double Red { get { return _scalar.V0; } set { _scalar.V0 = value; } } [DisplayColor(0, 255, 0)] public double Green { get { return _scalar.V1; } set { _scalar.V1 = value; } } [DisplayColor(255, 0, 0)] public double Blue { get { return _scalar.V2; } set { _scalar.V2 = value; } } [DisplayColor(122, 122, 122)] public double Alpha { get { return _scalar.V3; } set { _scalar.V3 = value; } } public int Dimension => 4; public MCvScalar MCvScalar { get { return _scalar; } set { _scalar = value; } } public Rgba(double red, double green, double blue, double alpha) { _scalar = new MCvScalar(red, green, blue, alpha); } public bool Equals(Rgba other) { return MCvScalar.Equals(other.MCvScalar); } public override string ToString() { return $"[{Red},{Green},{Blue},{Alpha}]"; } } [ColorInfo(ConversionCodename = "Xyz")] public struct Xyz : IColor, IEquatable { private MCvScalar _scalar; [DisplayColor(122, 122, 122)] public double X { get { return _scalar.V0; } set { _scalar.V0 = value; } } [DisplayColor(122, 122, 122)] public double Y { get { return _scalar.V1; } set { _scalar.V1 = value; } } [DisplayColor(122, 122, 122)] public double Z { get { return _scalar.V2; } set { _scalar.V2 = value; } } public int Dimension => 3; public MCvScalar MCvScalar { get { return _scalar; } set { _scalar = value; } } public Xyz(double x, double y, double z) { _scalar = new MCvScalar(x, y, z); } public bool Equals(Xyz other) { return MCvScalar.Equals(other.MCvScalar); } public override string ToString() { return $"[{X},{Y},{Z}]"; } } [ColorInfo(ConversionCodename = "YCrCb")] public struct Ycc : IColor, IEquatable { private MCvScalar _scalar; [DisplayColor(122, 122, 122)] public double Y { get { return _scalar.V0; } set { _scalar.V0 = value; } } [DisplayColor(122, 122, 122)] public double Cr { get { return _scalar.V1; } set { _scalar.V1 = value; } } [DisplayColor(122, 122, 122)] public double Cb { get { return _scalar.V2; } set { _scalar.V2 = value; } } public int Dimension => 3; public MCvScalar MCvScalar { get { return _scalar; } set { _scalar = value; } } public Ycc(double y, double cr, double cb) { _scalar = new MCvScalar(y, cr, cb); } public bool Equals(Ycc other) { return MCvScalar.Equals(other.MCvScalar); } public override string ToString() { return $"[{Y},{Cr},{Cb}]"; } } public struct LineSegment2D { private Point _p1; private Point _p2; public Point P1 { get { return _p1; } set { _p1 = value; } } public Point P2 { get { return _p2; } set { _p2 = value; } } public PointF Direction { get { int num = P1.X - P2.X; int num2 = P1.Y - P2.Y; float num3 = (float)Math.Sqrt(num * num + num2 * num2); return new PointF((float)num / num3, (float)num2 / num3); } } public double Length { get { int num = P1.X - P2.X; int num2 = P1.Y - P2.Y; return Math.Sqrt(num * num + num2 * num2); } } public LineSegment2D(Point p1, Point p2) { _p1 = p1; _p2 = p2; } public int Side(Point point) { float num = (P2.X - P1.X) * (point.Y - P1.Y) - (point.X - P1.X) * (P2.Y - P1.Y); if (!(num > 0f)) { if (!(num < 0f)) { return 0; } return -1; } return 1; } public double GetExteriorAngleDegree(LineSegment2D otherLine) { PointF direction = Direction; PointF direction2 = otherLine.Direction; double num = (Math.Atan2(direction2.Y, direction2.X) - Math.Atan2(direction.Y, direction.X)) * (180.0 / Math.PI); if (!(num <= -180.0)) { if (!(num > 180.0)) { return num; } return num - 360.0; } return num + 360.0; } } public struct LineSegment2DF { private PointF _p1; private PointF _p2; public PointF P1 { get { return _p1; } set { _p1 = value; } } public PointF P2 { get { return _p2; } set { _p2 = value; } } public double Length { get { float num = P1.X - P2.X; float num2 = P1.Y - P2.Y; return Math.Sqrt(num * num + num2 * num2); } } public PointF Direction { get { float num = P2.X - P1.X; float num2 = P2.Y - P1.Y; float num3 = (float)Math.Sqrt(num * num + num2 * num2); return new PointF(num / num3, num2 / num3); } } public LineSegment2DF(PointF p1, PointF p2) { _p1 = p1; _p2 = p2; } public float YByX(float x) { PointF p = _p1; PointF direction = Direction; return (x - p.X) / direction.X * direction.Y + p.Y; } public int Side(PointF point) { float num = (P2.X - P1.X) * (point.Y - P1.Y) - (point.X - P1.X) * (P2.Y - P1.Y); if (!(num > 0f)) { if (!(num < 0f)) { return 0; } return -1; } return 1; } public double GetExteriorAngleDegree(LineSegment2DF otherLine) { PointF direction = Direction; PointF direction2 = otherLine.Direction; double num = (Math.Atan2(direction2.Y, direction2.X) - Math.Atan2(direction.Y, direction.X)) * (180.0 / Math.PI); if (!(num <= -180.0)) { if (!(num > 180.0)) { return num; } return num - 360.0; } return num + 360.0; } } public struct LineSegment3DF { private MCvPoint3D32f _p1; private MCvPoint3D32f _p2; public MCvPoint3D32f P1 { get { return _p1; } set { _p1 = value; } } public MCvPoint3D32f P2 { get { return _p2; } set { _p2 = value; } } public double Length { get { float num = P1.X - P2.X; float num2 = P1.Y - P2.Y; float num3 = P1.Z - P2.Z; return Math.Sqrt(num * num + num2 * num2 + num3 * num3); } } public LineSegment3DF(MCvPoint3D32f p1, MCvPoint3D32f p2) { _p1 = p1; _p2 = p2; } } [Serializable] public struct CircleF : IEquatable { private PointF _center; private float _radius; public PointF Center { get { return _center; } set { _center = value; } } [XmlAttribute("Radius")] public float Radius { get { return _radius; } set { _radius = value; } } public double Area => (double)(_radius * _radius) * Math.PI; public CircleF(PointF center, float radius) { _center = center; _radius = radius; } public bool Equals(CircleF circle2) { if (Center.Equals((object?)circle2.Center)) { return Radius.Equals(circle2.Radius); } return false; } } public struct ColorPoint { public MCvPoint3D32f Position; public byte Blue; public byte Green; public byte Red; } [Serializable] public struct Cross2DF { private PointF _center; private SizeF _size; public PointF Center { get { return _center; } set { _center = value; } } public SizeF Size { get { return _size; } set { _size = value; } } public LineSegment2DF Horizontal => new LineSegment2DF(new PointF(_center.X - _size.Width / 2f, _center.Y), new PointF(_center.X + _size.Width / 2f, _center.Y)); public LineSegment2DF Vertical => new LineSegment2DF(new PointF(_center.X, _center.Y - _size.Height / 2f), new PointF(_center.X, _center.Y + _size.Height / 2f)); public Cross2DF(PointF center, float width, float height) { _center = center; _size = new SizeF(width, height); } } [Serializable] public struct Cuboid { public MCvPoint3D64f Min; public MCvPoint3D64f Max; public MCvPoint3D64f Centroid => (Min + Max) * 0.5; public bool Contains(MCvPoint3D64f point) { if (point.X >= Min.X && point.Y >= Min.Y && point.Z >= Min.Z && point.X <= Max.X && point.Y <= Max.Y) { return point.Z <= Max.Z; } return false; } } public struct CvStructSizes { public int CvPoint; public int CvPoint2D32f; public int CvPoint3D32f; public int CvSize; public int CvSize2D32f; public int CvScalar; public int CvRect; public int CvBox2D; public int CvMat; public int CvMatND; public int CvTermCriteria; public int IplImage; } public struct Ellipse { private RotatedRect _box2D; public RotatedRect RotatedRect { get { return _box2D; } set { _box2D = value; } } public Ellipse(PointF center, SizeF size, float angle) { _box2D = new RotatedRect(center, size, angle); } public Ellipse(RotatedRect box2d) { _box2D = box2d; } } [Serializable] public struct MCvAvgComp { public Rectangle Rect; public int Neighbors; } public struct MCvMat { public int Type; public int Step; public IntPtr Refcount; public int HdrRefcount; public IntPtr Data; public int Rows; public int Cols; public int Width => Cols; public int Height => Rows; public int NumberOfChannels => ((Type & 0x1F8) >> 3) + 1; } internal static class MCvMatConstants { public static readonly int TypeOffset = (int)Marshal.OffsetOf("Type"); } public struct MCvMatND { public struct Dimension { private int _size; private int _step; public int Size { get { return _size; } set { _size = value; } } public int Step { get { return _step; } set { _step = value; } } } public int type; public int dims; public IntPtr refcount; public int hdr_refcount; public IntPtr data; public Dimension dim0; public Dimension dim1; public Dimension dim2; public Dimension dim3; public Dimension dim4; public Dimension dim5; public Dimension dim6; public Dimension dim7; public Dimension dim8; public Dimension dim9; public Dimension dim10; public Dimension dim11; public Dimension dim12; public Dimension dim13; public Dimension dim14; public Dimension dim15; public Dimension dim16; public Dimension dim17; public Dimension dim18; public Dimension dim19; public Dimension dim20; public Dimension dim21; public Dimension dim22; public Dimension dim23; public Dimension dim24; public Dimension dim25; public Dimension dim26; public Dimension dim27; public Dimension dim28; public Dimension dim29; public Dimension dim30; public Dimension dim31; public Dimension[] dim => new Dimension[32] { dim0, dim1, dim2, dim3, dim4, dim5, dim6, dim7, dim8, dim9, dim10, dim11, dim12, dim13, dim14, dim15, dim16, dim17, dim18, dim19, dim20, dim21, dim22, dim23, dim24, dim25, dim26, dim27, dim28, dim29, dim30, dim31 }; } [Serializable] public struct MCvObjectDetection { public Rectangle Rect; public float Score; public int ClassId; } [Serializable] public struct MCvPoint2D64f : IEquatable, IInterpolatable { public double X; public double Y; double IInterpolatable.InterpolationIndex => X; public MCvPoint2D64f(double x, double y) { X = x; Y = y; } public static MCvPoint2D64f operator +(MCvPoint2D64f p1, MCvPoint2D64f p2) { return new MCvPoint2D64f(p1.X + p2.X, p1.Y + p2.Y); } public static MCvPoint2D64f operator -(MCvPoint2D64f p1, MCvPoint2D64f p2) { return new MCvPoint2D64f(p1.X - p2.X, p1.Y - p2.Y); } public static MCvPoint2D64f operator *(MCvPoint2D64f p, double scale) { return new MCvPoint2D64f(p.X * scale, p.Y * scale); } public static MCvPoint2D64f operator *(double scale, MCvPoint2D64f p) { return p * scale; } public bool Equals(MCvPoint2D64f other) { if (X.Equals(other.X)) { return Y.Equals(other.Y); } return false; } MCvPoint2D64f IInterpolatable.LinearInterpolate(MCvPoint2D64f other, double index) { double num = (other.X - index) / (other.X - X); double num2 = 1.0 - num; return new MCvPoint2D64f(X * num + other.X * num2, Y * num + other.Y * num2); } } [Serializable] public struct MCvPoint3D32f : IEquatable { public float X; public float Y; public float Z; public double Norm => Math.Sqrt(X * X + Y * Y + Z * Z); public MCvPoint3D32f(float x, float y, float z) { X = x; Y = y; Z = z; } public MCvPoint3D32f CrossProduct(MCvPoint3D32f point) { return new MCvPoint3D32f(Y * point.Z - Z * point.Y, Z * point.X - X * point.Z, X * point.Y - Y * point.X); } public float DotProduct(MCvPoint3D32f point) { return X * point.X + Y * point.Y + Z * point.Z; } public MCvPoint3D32f GetNormalizedPoint() { float num = (float)Norm; return new MCvPoint3D32f(X / num, Y / num, Z / num); } public static implicit operator MCvPoint3D64f(MCvPoint3D32f point) { return new MCvPoint3D64f(point.X, point.Y, point.Z); } public static MCvPoint3D32f operator -(MCvPoint3D32f p1, MCvPoint3D32f p2) { return new MCvPoint3D32f(p1.X - p2.X, p1.Y - p2.Y, p1.Z - p2.Z); } public static MCvPoint3D32f operator +(MCvPoint3D32f p1, MCvPoint3D32f p2) { return new MCvPoint3D32f(p1.X + p2.X, p1.Y + p2.Y, p1.Z + p2.Z); } public static MCvPoint3D32f operator *(MCvPoint3D32f p, float scale) { return new MCvPoint3D32f(p.X * scale, p.Y * scale, p.Z * scale); } public static MCvPoint3D32f operator *(float scale, MCvPoint3D32f p) { return p * scale; } public bool Equals(MCvPoint3D32f other) { if (X.Equals(other.X) && Y.Equals(other.Y)) { return Z.Equals(other.Z); } return false; } } [Serializable] public struct MCvPoint3D64f : IEquatable { public double X; public double Y; public double Z; public MCvPoint3D64f(double x, double y, double z) { X = x; Y = y; Z = z; } public MCvPoint3D64f CrossProduct(MCvPoint3D64f point) { return new MCvPoint3D64f(Y * point.Z - Z * point.Y, Z * point.X - X * point.Z, X * point.Y - Y * point.X); } public double DotProduct(MCvPoint3D64f point) { return X * point.X + Y * point.Y + Z * point.Z; } public static MCvPoint3D64f operator +(MCvPoint3D64f p1, MCvPoint3D64f p2) { return new MCvPoint3D64f(p1.X + p2.X, p1.Y + p2.Y, p1.Z + p2.Z); } public static MCvPoint3D64f operator -(MCvPoint3D64f p1, MCvPoint3D64f p2) { return new MCvPoint3D64f(p1.X - p2.X, p1.Y - p2.Y, p1.Z - p2.Z); } public static MCvPoint3D64f operator *(MCvPoint3D64f p, double scale) { return new MCvPoint3D64f(p.X * scale, p.Y * scale, p.Z * scale); } public static MCvPoint3D64f operator *(double scale, MCvPoint3D64f p) { return p * scale; } public bool Equals(MCvPoint3D64f other) { if (X.Equals(other.X) && Y.Equals(other.Y)) { return Z.Equals(other.Z); } return false; } } [Serializable] public struct MCvScalar : ICodeGenerable, IEquatable { public double V0; public double V1; public double V2; public double V3; public double[] ToArray() { return new double[4] { V0, V1, V2, V3 }; } public MCvScalar(double v0) { V0 = v0; V1 = 0.0; V2 = 0.0; V3 = 0.0; } public MCvScalar(double v0, double v1) { V0 = v0; V1 = v1; V2 = 0.0; V3 = 0.0; } public MCvScalar(double v0, double v1, double v2) { V0 = v0; V1 = v1; V2 = v2; V3 = 0.0; } public MCvScalar(double v0, double v1, double v2, double v3) { V0 = v0; V1 = v1; V2 = v2; V3 = v3; } public string ToCode(ProgrammingLanguage language) { if (language != 0 && language != ProgrammingLanguage.CPlusPlus) { return ToString(); } return $"new MCvScalar({V0}, {V1}, {V2}, {V3})"; } public bool Equals(MCvScalar other) { if (V0.Equals(other.V0) && V1.Equals(other.V1) && V2.Equals(other.V2)) { return V3.Equals(other.V3); } return false; } } [Serializable] public struct MCvSlice { public int start_index; public int end_index; public static MCvSlice WholeSeq => new MCvSlice(0, 1073741823); public MCvSlice(int start, int end) { start_index = start; end_index = end; } } [Serializable] public struct MCvTermCriteria { public TermCritType Type; public int MaxIter; public double Epsilon; public MCvTermCriteria(int maxIteration) { MaxIter = maxIteration; Epsilon = 0.0; Type = TermCritType.Iter; } public MCvTermCriteria(double eps) { MaxIter = 0; Epsilon = eps; Type = TermCritType.Eps; } public MCvTermCriteria(int maxIteration, double eps) { MaxIter = maxIteration; Epsilon = eps; Type = TermCritType.Iter | TermCritType.Eps; } } [Serializable] public struct MDMatch { public int QueryIdx; public int TrainIdx; public int ImgIdx; public float Distance; } public struct MIplImage { public int NSize; public int ID; public int NChannels; public int AlphaChannel; public IplDepth Depth; public byte ColorModel0; public byte ColorModel1; public byte ColorModel2; public byte ColorModel3; public byte ChannelSeq0; public byte ChannelSeq1; public byte ChannelSeq2; public byte ChannelSeq3; public int DataOrder; public int Origin; public int Align; public int Width; public int Height; public IntPtr Roi; public IntPtr MaskROI; public IntPtr ImageId; public IntPtr TileInfo; public int ImageSize; public IntPtr ImageData; public int WidthStep; public int BorderMode0; public int BorderMode1; public int BorderMode2; public int BorderMode3; public int BorderConst0; public int BorderConst1; public int BorderConst2; public int BorderConst3; public IntPtr ImageDataOrigin; } [Serializable] public struct MKeyPoint { public PointF Point; public float Size; public float Angle; public float Response; public int Octave; public int ClassId; } [Serializable] public struct Range : IEquatable { private static Range _all; private int _start; private int _end; public static Range All => _all; public int Start { get { return _start; } set { _start = value; } } public int End { get { return _end; } set { _end = value; } } static Range() { CvInvoke.cveGetRangeAll(ref _all); } public Range(int start, int end) { _start = start; _end = end; } public bool Equals(Range other) { if (Start.Equals(other.Start)) { return End.Equals(other.End); } return false; } } [Serializable] public struct RangeF : IEquatable { private float _min; private float _max; public float Min { get { return _min; } set { _min = value; } } public float Max { get { return _max; } set { _max = value; } } public RangeF(float min, float max) { _min = min; _max = max; } public bool Equals(RangeF other) { if (Min.Equals(other.Min)) { return Max.Equals(other.Max); } return false; } } [Serializable] public struct RotatedRect : IConvexPolygonF, IEquatable { public PointF Center; public SizeF Size; public float Angle; public static RotatedRect Empty => default(RotatedRect); public RotatedRect(PointF center, SizeF size, float angle) { Center = center; Size = size; Angle = angle; } public void Offset(int x, int y) { Center.X += x; Center.Y += y; } public PointF[] GetVertices() { return CvInvoke.BoxPoints(this); } public Rectangle MinAreaRect() { PointF[] array = CvInvoke.BoxPoints(this); int num = (int)Math.Round(Math.Min(Math.Min(array[0].X, array[1].X), Math.Min(array[2].X, array[3].X))); int num2 = (int)Math.Round(Math.Max(Math.Max(array[0].X, array[1].X), Math.Max(array[2].X, array[3].X))); int num3 = (int)Math.Round(Math.Min(Math.Min(array[0].Y, array[1].Y), Math.Min(array[2].Y, array[3].Y))); int num4 = (int)Math.Round(Math.Max(Math.Max(array[0].Y, array[1].Y), Math.Max(array[2].Y, array[3].Y))); return new Rectangle(num, num3, num2 - num, num4 - num3); } public bool Equals(RotatedRect other) { if (Center.Equals((object?)other.Center) && Size.Equals((object?)other.Size)) { return Angle.Equals(other.Angle); } return false; } public static implicit operator RotatedRect(RectangleF rectangle) { return new RotatedRect(new PointF(rectangle.Location.X + rectangle.Width * 0.5f, rectangle.Location.Y + rectangle.Height * 0.5f), rectangle.Size, 0f); } } [Serializable] public struct Triangle2DF : IConvexPolygonF, IEquatable { private PointF _v0; private PointF _v1; private PointF _v2; public PointF V0 { get { return _v0; } set { _v0 = value; } } public PointF V1 { get { return _v1; } set { _v1 = value; } } public PointF V2 { get { return _v2; } set { _v2 = value; } } public double Area { get { float num = ((V1.X - V0.X) * (V2.Y - V0.Y) - (V1.Y - V0.Y) * (V2.X - V0.X)) * 0.5f; return (num < 0f) ? (0f - num) : num; } } public PointF Centeroid => new PointF((V0.X + V1.X + V2.X) / 3f, (V0.Y + V1.Y + V2.Y) / 3f); public Triangle2DF(PointF v0, PointF v1, PointF v2) { _v0 = v0; _v1 = v1; _v2 = v2; } public bool Equals(Triangle2DF tri) { if ((V0.Equals((object?)tri.V0) || V0.Equals((object?)tri.V1) || V0.Equals((object?)tri.V2)) && (V1.Equals((object?)tri.V0) || V1.Equals((object?)tri.V1) || V1.Equals((object?)tri.V2))) { if (!V2.Equals((object?)tri.V0) && !V2.Equals((object?)tri.V1)) { return V2.Equals((object?)tri.V2); } return true; } return false; } public PointF[] GetVertices() { return new PointF[3] { V0, V1, V2 }; } } [Serializable] public struct Triangle3DF : IEquatable { private MCvPoint3D32f _v0; private MCvPoint3D32f _v1; private MCvPoint3D32f _v2; public MCvPoint3D32f V0 { get { return _v0; } set { _v0 = value; } } public MCvPoint3D32f V1 { get { return _v1; } set { _v1 = value; } } public MCvPoint3D32f V2 { get { return _v2; } set { _v2 = value; } } public double Area { get { double length = new LineSegment3DF(V0, V1).Length; double length2 = new LineSegment3DF(V1, V2).Length; double length3 = new LineSegment3DF(V2, V0).Length; double num = (length + length2 + length3) / 2.0; return Math.Sqrt(num * (num - length) * (num - length2) * (num - length3)); } } public MCvPoint3D32f Normal => (V1 - V0).CrossProduct(V2 - V1).GetNormalizedPoint(); public MCvPoint3D32f Centeroid => new MCvPoint3D32f((V0.X + V1.X + V2.X) / 3f, (V0.Y + V1.Y + V2.Y) / 3f, (V0.Z + V1.Z + V2.Z) / 3f); public Triangle3DF(MCvPoint3D32f v0, MCvPoint3D32f v1, MCvPoint3D32f v2) { _v0 = v0; _v1 = v1; _v2 = v2; } public bool Equals(Triangle3DF tri) { if ((V0.Equals(tri.V0) || V0.Equals(tri.V1) || V0.Equals(tri.V2)) && (V1.Equals(tri.V0) || V1.Equals(tri.V1) || V1.Equals(tri.V2))) { if (!V2.Equals(tri.V0) && !V2.Equals(tri.V1)) { return V2.Equals(tri.V2); } return true; } return false; } } } namespace Emgu.CV.Util { public class BinaryFileStorage : IEnumerable, IEnumerable where T : struct { private static int _elementSize = Toolbox.SizeOf(); private int _trunkSize; private const int _defaultTrunkSize = 4096; protected FileInfo _fileInfo; public string FileName => _fileInfo.FullName; public BinaryFileStorage(string fileName) : this(fileName, 4096) { } public BinaryFileStorage(string fileName, int trunkSize) { _fileInfo = new FileInfo(fileName); _trunkSize = ((trunkSize <= 0) ? 4096 : trunkSize); } public BinaryFileStorage(string fileName, IEnumerable samples) : this(fileName) { Clear(); Append(samples); } public void Append(IEnumerable samples) { int num = _trunkSize / _elementSize; if (num <= 0) { num = 1; } byte[] array = new byte[num * _elementSize]; int num2 = 0; using PinnedArray pinnedArray = new PinnedArray(num); using FileStream stream = _fileInfo.Open(FileMode.Append, FileAccess.Write); using BufferedStream bufferedStream = new BufferedStream(stream, _trunkSize); IntPtr source = pinnedArray.AddrOfPinnedObject(); foreach (T sample in samples) { pinnedArray.Array[num2++] = sample; if (num2 == pinnedArray.Array.Length) { int num3 = num2 * _elementSize; Marshal.Copy(source, array, 0, num3); bufferedStream.Write(array, 0, num3); num2 = 0; } } if (num2 != 0) { int num4 = num2 * _elementSize; Marshal.Copy(source, array, 0, num4); bufferedStream.Write(array, 0, num4); } } public void Clear() { if (_fileInfo.Exists) { _fileInfo.Delete(); } } public int EstimateSize() { if (!_fileInfo.Exists) { return 0; } return (int)(_fileInfo.Length / _elementSize); } public T Peek() { using FileStream fileStream = _fileInfo.OpenRead(); using PinnedArray pinnedArray = new PinnedArray(_elementSize); return (T)((fileStream.Read(pinnedArray.Array, 0, _elementSize) > 0) ? ((ValueType)Marshal.PtrToStructure(pinnedArray.AddrOfPinnedObject())) : ((ValueType)new T())); } public IEnumerable GetSubsamples(int subsampleRate) { if (!_fileInfo.Exists) { yield break; } int bufferSize = _elementSize * subsampleRate; using FileStream stream = _fileInfo.OpenRead(); using BufferedStream bufferStream = new BufferedStream(stream, _trunkSize); using PinnedArray buffer = new PinnedArray(bufferSize); using PinnedArray structure = new PinnedArray(subsampleRate); IntPtr structAddr = structure.AddrOfPinnedObject(); IntPtr addr = buffer.AddrOfPinnedObject(); while (bufferStream.Read(buffer.Array, 0, bufferSize) > 0) { CvToolbox.Memcpy(structAddr, addr, bufferSize); yield return structure.Array[0]; } } public IEnumerator GetEnumerator() { if (!_fileInfo.Exists) { yield break; } int num = _trunkSize / _elementSize; if (num <= 0) { num = 1; } byte[] buffer = new byte[_elementSize * num]; using FileStream stream = _fileInfo.OpenRead(); using BufferedStream bufferStream = new BufferedStream(stream, _trunkSize); using PinnedArray structures = new PinnedArray(num); IntPtr structAddr = structures.AddrOfPinnedObject(); int num2; while ((num2 = bufferStream.Read(buffer, 0, buffer.Length)) > 0) { Marshal.Copy(buffer, 0, structAddr, num2); int elementsRead = num2 / _elementSize; for (int i = 0; i < elementsRead; i++) { yield return structures.Array[i]; } } } IEnumerator IEnumerable.GetEnumerator() { return GetEnumerator(); } } [Serializable] public class CvException : Exception { private int _status; private string _functionName; private string _errMsg; private string _fileName; private int _line; public int Status { get { return _status; } set { _status = value; } } public string ErrorStr => CvInvoke.ErrorStr(Status); public string FunctionName { get { return _functionName; } set { _functionName = value; } } public string ErrorMessage { get { return _errMsg; } set { _errMsg = value; } } public string FileName { get { return _fileName; } set { _fileName = value; } } public int Line { get { return _line; } set { _line = value; } } private CvException() { } public CvException(int status, string funcName, string errMsg, string fileName, int line) : base("OpenCV: " + errMsg) { _status = status; _functionName = funcName; _errMsg = errMsg; _fileName = fileName; _line = line; } } public static class CvToolbox { private static Dictionary> _lookupTable = new Dictionary>(); public static Matrix GetMatrixFromArrays(T[][] data) where T : struct { int num = data.Length; int cols = data[0].Length; Matrix matrix = new Matrix(num, cols); MCvMat mCvMat = matrix.MCvMat; long num2 = mCvMat.Data.ToInt64(); int num3 = 0; while (num3 < num) { CopyVector(data[num3], new IntPtr(num2)); num3++; num2 += mCvMat.Step; } return matrix; } public static Matrix GetMatrixFromPoints(MCvPoint2D64f[][] points) { int num = points.Length; int cols = points[0].Length; Matrix matrix = new Matrix(num, cols, 2); MCvMat mCvMat = matrix.MCvMat; for (int i = 0; i < num; i++) { CopyVector(dest: new IntPtr(mCvMat.Data.ToInt64() + mCvMat.Step * i), src: points[i]); } return matrix; } public static void GetMinMax(IEnumerable points, out MCvPoint3D64f min, out MCvPoint3D64f max) { min = default(MCvPoint3D64f); min.X = (min.Y = (min.Z = double.MaxValue)); max = default(MCvPoint3D64f); max.X = (max.Y = (max.Z = double.MinValue)); foreach (MCvPoint3D64f point in points) { min.X = Math.Min(min.X, point.X); min.Y = Math.Min(min.Y, point.Y); min.Z = Math.Min(min.Z, point.Z); max.X = Math.Max(max.X, point.X); max.Y = Math.Max(max.Y, point.Y); max.Z = Math.Max(max.Z, point.Z); } } public static int CopyVector(TData[] src, IntPtr dest, int bytesToCopy = -1) { int num = ((bytesToCopy >= 0) ? bytesToCopy : (Toolbox.SizeOf() * src.Length)); GCHandle gCHandle = GCHandle.Alloc(src, GCHandleType.Pinned); Memcpy(dest, gCHandle.AddrOfPinnedObject(), num); gCHandle.Free(); return num; } public static void CopyMatrix(TData[][] source, IntPtr dest) { long num = dest.ToInt64(); for (int i = 0; i < source.Length; i++) { int num2 = CopyVector(source[i], new IntPtr(num)); num += num2; } } public static void CopyMatrix(IntPtr src, D[][] dest) { int num = Toolbox.SizeOf() * dest[0].Length; long num2 = src.ToInt64(); int num3 = 0; while (num3 < dest.Length) { GCHandle gCHandle = GCHandle.Alloc(dest[num3], GCHandleType.Pinned); Memcpy(gCHandle.AddrOfPinnedObject(), new IntPtr(num2), num); gCHandle.Free(); num3++; num2 += num; } } public static void Memcpy(IntPtr dest, IntPtr src, int len) { CvInvoke.cveMemcpy(dest, src, len); } private static ColorConversion GetCode(Type srcType, Type destType) { string value = $"{GetConversionCodenameFromType(srcType)}2{GetConversionCodenameFromType(destType)}"; return (ColorConversion)Enum.Parse(typeof(ColorConversion), value, ignoreCase: true); } private static string GetConversionCodenameFromType(Type colorType) { return ((ColorInfoAttribute)colorType.GetCustomAttributes(typeof(ColorInfoAttribute), inherit: true)[0]).ConversionCodename; } public static ColorConversion GetColorCvtCode(Type srcColorType, Type destColorType) { lock (_lookupTable) { Dictionary dictionary3; if (!_lookupTable.ContainsKey(srcColorType)) { Dictionary dictionary2 = (_lookupTable[srcColorType] = new Dictionary()); dictionary3 = dictionary2; } else { dictionary3 = _lookupTable[srcColorType]; } Dictionary dictionary4 = dictionary3; ColorConversion result; if (!dictionary4.ContainsKey(destColorType)) { ColorConversion colorConversion = (dictionary4[destColorType] = GetCode(srcColorType, destColorType)); result = colorConversion; } else { result = dictionary4[destColorType]; } return result; } } } public class DataLogger : UnmanagedObject { private int _loggerId; public event EventHandler> OnDataReceived; public DataLogger(int logLevel) { lock (typeof(DataLoggerHelper)) { _loggerId = DataLoggerHelper.TotalLoggerCount; DataLoggerHelper.TotalLoggerCount++; } _ptr = CvInvoke.DataLoggerCreate(logLevel, _loggerId); CvInvoke.DataLoggerRegisterCallback(_ptr, DataLoggerHelper.Handler); DataLoggerHelper.OnDataReceived += HelperDataHandler; } private void HelperDataHandler(IntPtr data, int loggerId) { if (loggerId == _loggerId && this.OnDataReceived != null) { this.OnDataReceived(this, new EventArgs(data)); } } public void Log(IntPtr data, int logLevel) { CvInvoke.DataLoggerLog(_ptr, data, logLevel); } protected override void DisposeObject() { CvInvoke.DataLoggerRelease(ref _ptr); DataLoggerHelper.OnDataReceived -= HelperDataHandler; } } public class DataLogger : DisposableObject { private DataLogger _logger; private EventHandler> _handler; public IntPtr Ptr => _logger.Ptr; public event EventHandler> OnDataReceived; public DataLogger(int logLevel) { _logger = new DataLogger(logLevel); _handler = DataHandler; _logger.OnDataReceived += _handler; } public void Log(T data, int logLevel) { if (typeof(T) == typeof(string)) { IntPtr intPtr = Marshal.StringToHGlobalAnsi(data as string); _logger.Log(intPtr, logLevel); Marshal.FreeHGlobal(intPtr); } else { IntPtr intPtr2 = Marshal.AllocHGlobal(Toolbox.SizeOf()); Marshal.StructureToPtr(data, intPtr2, fDeleteOld: false); _logger.Log(intPtr2, logLevel); Marshal.FreeHGlobal(intPtr2); } } private void DataHandler(object sender, EventArgs e) { if (this.OnDataReceived != null) { T value = (T)((!(typeof(T) == typeof(string))) ? ((object)Marshal.PtrToStructure(e.Value)) : ((object)(T)(object)Marshal.PtrToStringAnsi(e.Value))); this.OnDataReceived(this, new EventArgs(value)); } } public static implicit operator IntPtr(DataLogger obj) { return obj?.Ptr ?? IntPtr.Zero; } protected override void DisposeObject() { _logger.OnDataReceived -= _handler; _logger.Dispose(); } } internal static class DataLoggerHelper { [UnmanagedFunctionPointer(CallingConvention.Cdecl)] public delegate void DataCallback(IntPtr data, int loggerId); public static DataCallback Handler = DataHandler; public static volatile int TotalLoggerCount = 0; public static event DataCallback OnDataReceived; public static void DataHandler(IntPtr data, int loggerId) { if (DataLoggerHelper.OnDataReceived != null) { DataLoggerHelper.OnDataReceived(data, loggerId); } } } public abstract class SharedPtrObject : UnmanagedObject { protected IntPtr _sharedPtr; public IntPtr SharedPtr => _sharedPtr; } public static class StructSize { private static readonly int _PointF; private static readonly int _RangF; private static readonly int _MCvMat; private static readonly int _MIplImage; private static readonly int _MCvPoint3D32f; private static readonly int _MCvMatND; private static readonly int _MCvPoint2D64f; public static int PointF => _PointF; public static int RangF => _RangF; public static int MCvPoint2D64f => _MCvPoint2D64f; public static int MCvMat => _MCvMat; public static int MIplImage => _MIplImage; public static int MCvPoint3D32f => _MCvPoint3D32f; public static int MCvMatND => _MCvMatND; static StructSize() { _PointF = Toolbox.SizeOf(); _RangF = Toolbox.SizeOf(); _MCvMat = Toolbox.SizeOf(); _MIplImage = Toolbox.SizeOf(); _MCvPoint3D32f = Toolbox.SizeOf(); _MCvMatND = Toolbox.SizeOf(); _MCvPoint2D64f = Toolbox.SizeOf(); } } public class TbbTaskScheduler : UnmanagedObject { public TbbTaskScheduler() { _ptr = CvInvoke.tbbTaskSchedulerInit(); } protected override void DisposeObject() { CvInvoke.tbbTaskSchedulerRelease(ref _ptr); } } public abstract class UnmanagedVector : System.IO.Stream { private long _position; private bool _disposed; protected IntPtr _ptr; public abstract IntPtr StartAddress { get; } public abstract int Size { get; } public override long Position { get { return _position; } set { if (value > Length) { throw new IndexOutOfRangeException($"Position ({value}) is beyond the stream boundary ({Length})"); } _position = value; } } public override long Length { get; } public override bool CanRead => true; public override bool CanWrite => false; public override bool CanSeek => false; public IntPtr Ptr => _ptr; public override int Read(byte[] buffer, int offset, int count) { long num = StartAddress.ToInt64(); long val = num + Length; IntPtr source = new IntPtr(num + _position + offset); IntPtr intPtr = new IntPtr(Math.Min(source.ToInt64() + count, val)); int num2 = (int)Math.Min(buffer.Length, intPtr.ToInt64() - source.ToInt64()); Marshal.Copy(source, buffer, 0, num2); _position = source.ToInt64() + num2 - num; return num2; } public override void SetLength(long value) { throw new NotSupportedException("Set length is not supported"); } public override long Seek(long offset, SeekOrigin origin) { throw new NotSupportedException("Seek is not supported"); } public override void Write(byte[] buffer, int offset, int count) { throw new NotSupportedException("Write is not supported"); } public override void Flush() { throw new NotSupportedException("Flush is not supported"); } public new void Dispose() { Dispose(disposing: true); GC.SuppressFinalize(this); } protected override void Dispose(bool disposing) { if (!_disposed) { _disposed = true; if (disposing) { ReleaseManagedResources(); } DisposeObject(); } } protected virtual void ReleaseManagedResources() { } protected abstract void DisposeObject(); ~UnmanagedVector() { Dispose(disposing: false); } public static implicit operator IntPtr(UnmanagedVector obj) { return obj?._ptr ?? IntPtr.Zero; } } [Serializable] [DebuggerTypeProxy(typeof(DebuggerProxy))] public class VectorOfByte : UnmanagedVector, ISerializable, IInputOutputArray, IInputArray, IDisposable, IOutputArray, IInputArrayOfArrays, IOutputArrayOfArrays { internal class DebuggerProxy { private VectorOfByte _v; public byte[] Values => _v.ToArray(); public DebuggerProxy(VectorOfByte v) { _v = v; } } private readonly bool _needDispose; public override int Size => VectorOfByteGetSize(_ptr); public override IntPtr StartAddress => VectorOfByteGetStartAddress(_ptr); public override long Length => VectorOfByteGetMemorySize(_ptr); public byte this[int index] { get { byte element = 0; VectorOfByteGetItem(_ptr, index, ref element); return element; } } public static int SizeOfItemInBytes => VectorOfByteSizeOfItemInBytes(); static VectorOfByte() { CvInvoke.Init(); } public VectorOfByte(SerializationInfo info, StreamingContext context) : this() { Push((byte[])info.GetValue("ByteArray", typeof(byte[]))); } public void GetObjectData(SerializationInfo info, StreamingContext context) { info.AddValue("ByteArray", ToArray()); } public VectorOfByte() : this(VectorOfByteCreate(), needDispose: true) { } internal VectorOfByte(IntPtr ptr, bool needDispose) { _ptr = ptr; _needDispose = needDispose; } public VectorOfByte(int size) : this(VectorOfByteCreateSize(size), needDispose: true) { } public VectorOfByte(byte[] values) : this() { Push(values); } public void Push(byte[] value) { if (value.Length != 0) { GCHandle gCHandle = GCHandle.Alloc(value, GCHandleType.Pinned); VectorOfBytePushMulti(_ptr, gCHandle.AddrOfPinnedObject(), value.Length); gCHandle.Free(); } } public void Push(VectorOfByte other) { VectorOfBytePushVector(_ptr, other); } public byte[] ToArray() { byte[] array = new byte[Size]; if (array.Length != 0) { GCHandle gCHandle = GCHandle.Alloc(array, GCHandleType.Pinned); VectorOfByteCopyData(_ptr, gCHandle.AddrOfPinnedObject()); gCHandle.Free(); } return array; } public void Clear() { VectorOfByteClear(_ptr); } protected override void DisposeObject() { if (_needDispose && _ptr != IntPtr.Zero) { VectorOfByteRelease(ref _ptr); } } public InputArray GetInputArray() { return new InputArray(cveInputArrayFromVectorOfByte(_ptr), this); } public OutputArray GetOutputArray() { return new OutputArray(cveOutputArrayFromVectorOfByte(_ptr), this); } public InputOutputArray GetInputOutputArray() { return new InputOutputArray(cveInputOutputArrayFromVectorOfByte(_ptr), this); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr VectorOfByteCreate(); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr VectorOfByteCreateSize(int size); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfByteRelease(ref IntPtr v); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int VectorOfByteGetSize(IntPtr v); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfByteCopyData(IntPtr v, IntPtr data); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr VectorOfByteGetStartAddress(IntPtr v); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern long VectorOfByteGetMemorySize(IntPtr v); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfBytePushMulti(IntPtr v, IntPtr values, int count); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfBytePushVector(IntPtr ptr, IntPtr otherPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfByteClear(IntPtr v); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfByteGetItem(IntPtr vec, int index, ref byte element); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int VectorOfByteSizeOfItemInBytes(); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveInputArrayFromVectorOfByte(IntPtr vec); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveOutputArrayFromVectorOfByte(IntPtr vec); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveInputOutputArrayFromVectorOfByte(IntPtr vec); void IDisposable.Dispose() { Dispose(); } } [Serializable] [DebuggerTypeProxy(typeof(DebuggerProxy))] public class VectorOfColorPoint : UnmanagedVector, ISerializable, IInputOutputArray, IInputArray, IDisposable, IOutputArray, IInputArrayOfArrays, IOutputArrayOfArrays { internal class DebuggerProxy { private VectorOfColorPoint _v; public ColorPoint[] Values => _v.ToArray(); public DebuggerProxy(VectorOfColorPoint v) { _v = v; } } private readonly bool _needDispose; public override int Size => VectorOfColorPointGetSize(_ptr); public override IntPtr StartAddress => VectorOfColorPointGetStartAddress(_ptr); public override long Length => VectorOfColorPointGetMemorySize(_ptr); public ColorPoint this[int index] { get { ColorPoint element = default(ColorPoint); VectorOfColorPointGetItem(_ptr, index, ref element); return element; } } public static int SizeOfItemInBytes => VectorOfColorPointSizeOfItemInBytes(); static VectorOfColorPoint() { CvInvoke.Init(); } public VectorOfColorPoint(SerializationInfo info, StreamingContext context) : this() { Push((ColorPoint[])info.GetValue("ColorPointArray", typeof(ColorPoint[]))); } public void GetObjectData(SerializationInfo info, StreamingContext context) { info.AddValue("ColorPointArray", ToArray()); } public VectorOfColorPoint() : this(VectorOfColorPointCreate(), needDispose: true) { } internal VectorOfColorPoint(IntPtr ptr, bool needDispose) { _ptr = ptr; _needDispose = needDispose; } public VectorOfColorPoint(int size) : this(VectorOfColorPointCreateSize(size), needDispose: true) { } public VectorOfColorPoint(ColorPoint[] values) : this() { Push(values); } public void Push(ColorPoint[] value) { if (value.Length != 0) { GCHandle gCHandle = GCHandle.Alloc(value, GCHandleType.Pinned); VectorOfColorPointPushMulti(_ptr, gCHandle.AddrOfPinnedObject(), value.Length); gCHandle.Free(); } } public void Push(VectorOfColorPoint other) { VectorOfColorPointPushVector(_ptr, other); } public ColorPoint[] ToArray() { ColorPoint[] array = new ColorPoint[Size]; if (array.Length != 0) { GCHandle gCHandle = GCHandle.Alloc(array, GCHandleType.Pinned); VectorOfColorPointCopyData(_ptr, gCHandle.AddrOfPinnedObject()); gCHandle.Free(); } return array; } public void Clear() { VectorOfColorPointClear(_ptr); } protected override void DisposeObject() { if (_needDispose && _ptr != IntPtr.Zero) { VectorOfColorPointRelease(ref _ptr); } } public InputArray GetInputArray() { return new InputArray(cveInputArrayFromVectorOfColorPoint(_ptr), this); } public OutputArray GetOutputArray() { return new OutputArray(cveOutputArrayFromVectorOfColorPoint(_ptr), this); } public InputOutputArray GetInputOutputArray() { return new InputOutputArray(cveInputOutputArrayFromVectorOfColorPoint(_ptr), this); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr VectorOfColorPointCreate(); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr VectorOfColorPointCreateSize(int size); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfColorPointRelease(ref IntPtr v); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int VectorOfColorPointGetSize(IntPtr v); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfColorPointCopyData(IntPtr v, IntPtr data); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr VectorOfColorPointGetStartAddress(IntPtr v); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern long VectorOfColorPointGetMemorySize(IntPtr v); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfColorPointPushMulti(IntPtr v, IntPtr values, int count); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfColorPointPushVector(IntPtr ptr, IntPtr otherPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfColorPointClear(IntPtr v); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfColorPointGetItem(IntPtr vec, int index, ref ColorPoint element); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int VectorOfColorPointSizeOfItemInBytes(); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveInputArrayFromVectorOfColorPoint(IntPtr vec); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveOutputArrayFromVectorOfColorPoint(IntPtr vec); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveInputOutputArrayFromVectorOfColorPoint(IntPtr vec); void IDisposable.Dispose() { Dispose(); } } [Serializable] [DebuggerTypeProxy(typeof(DebuggerProxy))] public class VectorOfCvString : UnmanagedVector, IInputOutputArray, IInputArray, IDisposable, IOutputArray, IInputArrayOfArrays, IOutputArrayOfArrays { internal class DebuggerProxy { private VectorOfCvString _v; public CvString[] Values { get { CvString[] array = new CvString[_v.Size]; for (int i = 0; i < array.Length; i++) { array[i] = _v[i]; } return array; } } public DebuggerProxy(VectorOfCvString v) { _v = v; } } private readonly bool _needDispose; public override int Size => VectorOfCvStringGetSize(_ptr); public override IntPtr StartAddress => VectorOfCvStringGetStartAddress(_ptr); public override long Length => VectorOfCvStringGetMemorySize(_ptr); public CvString this[int index] { get { IntPtr element = IntPtr.Zero; VectorOfCvStringGetItemPtr(_ptr, index, ref element); return new CvString(element, needDispose: false); } } public static int SizeOfItemInBytes => VectorOfCvStringSizeOfItemInBytes(); static VectorOfCvString() { CvInvoke.Init(); } public VectorOfCvString() : this(VectorOfCvStringCreate(), needDispose: true) { } internal VectorOfCvString(IntPtr ptr, bool needDispose) { _ptr = ptr; _needDispose = needDispose; } public VectorOfCvString(int size) : this(VectorOfCvStringCreateSize(size), needDispose: true) { } public VectorOfCvString(params CvString[] values) : this() { Push(values); } public void Clear() { VectorOfCvStringClear(_ptr); } public void Push(CvString value) { VectorOfCvStringPush(_ptr, value.Ptr); } public void Push(CvString[] values) { foreach (CvString value in values) { Push(value); } } public void Push(VectorOfCvString other) { VectorOfCvStringPushVector(_ptr, other); } protected override void DisposeObject() { if (_needDispose && _ptr != IntPtr.Zero) { VectorOfCvStringRelease(ref _ptr); } } public InputArray GetInputArray() { return new InputArray(cveInputArrayFromVectorOfCvString(_ptr), this); } public OutputArray GetOutputArray() { return new OutputArray(cveOutputArrayFromVectorOfCvString(_ptr), this); } public InputOutputArray GetInputOutputArray() { return new InputOutputArray(cveInputOutputArrayFromVectorOfCvString(_ptr), this); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr VectorOfCvStringCreate(); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr VectorOfCvStringCreateSize(int size); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfCvStringRelease(ref IntPtr v); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int VectorOfCvStringGetSize(IntPtr v); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr VectorOfCvStringGetStartAddress(IntPtr v); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern long VectorOfCvStringGetMemorySize(IntPtr v); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfCvStringPush(IntPtr v, IntPtr value); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfCvStringPushVector(IntPtr ptr, IntPtr otherPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfCvStringClear(IntPtr v); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfCvStringGetItemPtr(IntPtr vec, int index, ref IntPtr element); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int VectorOfCvStringSizeOfItemInBytes(); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveInputArrayFromVectorOfCvString(IntPtr vec); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveOutputArrayFromVectorOfCvString(IntPtr vec); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveInputOutputArrayFromVectorOfCvString(IntPtr vec); public string[] ToArray() { string[] array = new string[Size]; for (int i = 0; i < array.Length; i++) { array[i] = this[i].ToString(); } return array; } public VectorOfCvString(string[] strings) : this() { for (int i = 0; i < strings.Length; i++) { using CvString value = new CvString(strings[i]); Push(value); } } void IDisposable.Dispose() { Dispose(); } } [Serializable] [DebuggerTypeProxy(typeof(DebuggerProxy))] public class VectorOfDMatch : UnmanagedVector, ISerializable, IInputOutputArray, IInputArray, IDisposable, IOutputArray, IInputArrayOfArrays, IOutputArrayOfArrays { internal class DebuggerProxy { private VectorOfDMatch _v; public MDMatch[] Values => _v.ToArray(); public DebuggerProxy(VectorOfDMatch v) { _v = v; } } private readonly bool _needDispose; public override int Size => VectorOfDMatchGetSize(_ptr); public override IntPtr StartAddress => VectorOfDMatchGetStartAddress(_ptr); public override long Length => VectorOfDMatchGetMemorySize(_ptr); public MDMatch this[int index] { get { MDMatch element = default(MDMatch); VectorOfDMatchGetItem(_ptr, index, ref element); return element; } } public static int SizeOfItemInBytes => VectorOfDMatchSizeOfItemInBytes(); static VectorOfDMatch() { CvInvoke.Init(); } public VectorOfDMatch(SerializationInfo info, StreamingContext context) : this() { Push((MDMatch[])info.GetValue("DMatchArray", typeof(MDMatch[]))); } public void GetObjectData(SerializationInfo info, StreamingContext context) { info.AddValue("DMatchArray", ToArray()); } public VectorOfDMatch() : this(VectorOfDMatchCreate(), needDispose: true) { } internal VectorOfDMatch(IntPtr ptr, bool needDispose) { _ptr = ptr; _needDispose = needDispose; } public VectorOfDMatch(int size) : this(VectorOfDMatchCreateSize(size), needDispose: true) { } public VectorOfDMatch(MDMatch[] values) : this() { Push(values); } public void Push(MDMatch[] value) { if (value.Length != 0) { GCHandle gCHandle = GCHandle.Alloc(value, GCHandleType.Pinned); VectorOfDMatchPushMulti(_ptr, gCHandle.AddrOfPinnedObject(), value.Length); gCHandle.Free(); } } public void Push(VectorOfDMatch other) { VectorOfDMatchPushVector(_ptr, other); } public MDMatch[] ToArray() { MDMatch[] array = new MDMatch[Size]; if (array.Length != 0) { GCHandle gCHandle = GCHandle.Alloc(array, GCHandleType.Pinned); VectorOfDMatchCopyData(_ptr, gCHandle.AddrOfPinnedObject()); gCHandle.Free(); } return array; } public void Clear() { VectorOfDMatchClear(_ptr); } protected override void DisposeObject() { if (_needDispose && _ptr != IntPtr.Zero) { VectorOfDMatchRelease(ref _ptr); } } public InputArray GetInputArray() { return new InputArray(cveInputArrayFromVectorOfDMatch(_ptr), this); } public OutputArray GetOutputArray() { return new OutputArray(cveOutputArrayFromVectorOfDMatch(_ptr), this); } public InputOutputArray GetInputOutputArray() { return new InputOutputArray(cveInputOutputArrayFromVectorOfDMatch(_ptr), this); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr VectorOfDMatchCreate(); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr VectorOfDMatchCreateSize(int size); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfDMatchRelease(ref IntPtr v); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int VectorOfDMatchGetSize(IntPtr v); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfDMatchCopyData(IntPtr v, IntPtr data); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr VectorOfDMatchGetStartAddress(IntPtr v); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern long VectorOfDMatchGetMemorySize(IntPtr v); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfDMatchPushMulti(IntPtr v, IntPtr values, int count); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfDMatchPushVector(IntPtr ptr, IntPtr otherPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfDMatchClear(IntPtr v); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfDMatchGetItem(IntPtr vec, int index, ref MDMatch element); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int VectorOfDMatchSizeOfItemInBytes(); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveInputArrayFromVectorOfDMatch(IntPtr vec); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveOutputArrayFromVectorOfDMatch(IntPtr vec); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveInputOutputArrayFromVectorOfDMatch(IntPtr vec); void IDisposable.Dispose() { Dispose(); } } [Serializable] [DebuggerTypeProxy(typeof(DebuggerProxy))] public class VectorOfDouble : UnmanagedVector, ISerializable, IInputOutputArray, IInputArray, IDisposable, IOutputArray, IInputArrayOfArrays, IOutputArrayOfArrays { internal class DebuggerProxy { private VectorOfDouble _v; public double[] Values => _v.ToArray(); public DebuggerProxy(VectorOfDouble v) { _v = v; } } private readonly bool _needDispose; public override int Size => VectorOfDoubleGetSize(_ptr); public override IntPtr StartAddress => VectorOfDoubleGetStartAddress(_ptr); public override long Length => VectorOfDoubleGetMemorySize(_ptr); public double this[int index] { get { double element = 0.0; VectorOfDoubleGetItem(_ptr, index, ref element); return element; } } public static int SizeOfItemInBytes => VectorOfDoubleSizeOfItemInBytes(); static VectorOfDouble() { CvInvoke.Init(); } public VectorOfDouble(SerializationInfo info, StreamingContext context) : this() { Push((double[])info.GetValue("DoubleArray", typeof(double[]))); } public void GetObjectData(SerializationInfo info, StreamingContext context) { info.AddValue("DoubleArray", ToArray()); } public VectorOfDouble() : this(VectorOfDoubleCreate(), needDispose: true) { } internal VectorOfDouble(IntPtr ptr, bool needDispose) { _ptr = ptr; _needDispose = needDispose; } public VectorOfDouble(int size) : this(VectorOfDoubleCreateSize(size), needDispose: true) { } public VectorOfDouble(double[] values) : this() { Push(values); } public void Push(double[] value) { if (value.Length != 0) { GCHandle gCHandle = GCHandle.Alloc(value, GCHandleType.Pinned); VectorOfDoublePushMulti(_ptr, gCHandle.AddrOfPinnedObject(), value.Length); gCHandle.Free(); } } public void Push(VectorOfDouble other) { VectorOfDoublePushVector(_ptr, other); } public double[] ToArray() { double[] array = new double[Size]; if (array.Length != 0) { GCHandle gCHandle = GCHandle.Alloc(array, GCHandleType.Pinned); VectorOfDoubleCopyData(_ptr, gCHandle.AddrOfPinnedObject()); gCHandle.Free(); } return array; } public void Clear() { VectorOfDoubleClear(_ptr); } protected override void DisposeObject() { if (_needDispose && _ptr != IntPtr.Zero) { VectorOfDoubleRelease(ref _ptr); } } public InputArray GetInputArray() { return new InputArray(cveInputArrayFromVectorOfDouble(_ptr), this); } public OutputArray GetOutputArray() { return new OutputArray(cveOutputArrayFromVectorOfDouble(_ptr), this); } public InputOutputArray GetInputOutputArray() { return new InputOutputArray(cveInputOutputArrayFromVectorOfDouble(_ptr), this); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr VectorOfDoubleCreate(); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr VectorOfDoubleCreateSize(int size); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfDoubleRelease(ref IntPtr v); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int VectorOfDoubleGetSize(IntPtr v); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfDoubleCopyData(IntPtr v, IntPtr data); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr VectorOfDoubleGetStartAddress(IntPtr v); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern long VectorOfDoubleGetMemorySize(IntPtr v); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfDoublePushMulti(IntPtr v, IntPtr values, int count); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfDoublePushVector(IntPtr ptr, IntPtr otherPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfDoubleClear(IntPtr v); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfDoubleGetItem(IntPtr vec, int index, ref double element); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int VectorOfDoubleSizeOfItemInBytes(); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveInputArrayFromVectorOfDouble(IntPtr vec); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveOutputArrayFromVectorOfDouble(IntPtr vec); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveInputOutputArrayFromVectorOfDouble(IntPtr vec); void IDisposable.Dispose() { Dispose(); } } [Serializable] [DebuggerTypeProxy(typeof(DebuggerProxy))] public class VectorOfFloat : UnmanagedVector, ISerializable, IInputOutputArray, IInputArray, IDisposable, IOutputArray, IInputArrayOfArrays, IOutputArrayOfArrays { internal class DebuggerProxy { private VectorOfFloat _v; public float[] Values => _v.ToArray(); public DebuggerProxy(VectorOfFloat v) { _v = v; } } private readonly bool _needDispose; public override int Size => VectorOfFloatGetSize(_ptr); public override IntPtr StartAddress => VectorOfFloatGetStartAddress(_ptr); public override long Length => VectorOfFloatGetMemorySize(_ptr); public float this[int index] { get { float element = 0f; VectorOfFloatGetItem(_ptr, index, ref element); return element; } } public static int SizeOfItemInBytes => VectorOfFloatSizeOfItemInBytes(); static VectorOfFloat() { CvInvoke.Init(); } public VectorOfFloat(SerializationInfo info, StreamingContext context) : this() { Push((float[])info.GetValue("FloatArray", typeof(float[]))); } public void GetObjectData(SerializationInfo info, StreamingContext context) { info.AddValue("FloatArray", ToArray()); } public VectorOfFloat() : this(VectorOfFloatCreate(), needDispose: true) { } internal VectorOfFloat(IntPtr ptr, bool needDispose) { _ptr = ptr; _needDispose = needDispose; } public VectorOfFloat(int size) : this(VectorOfFloatCreateSize(size), needDispose: true) { } public VectorOfFloat(float[] values) : this() { Push(values); } public void Push(float[] value) { if (value.Length != 0) { GCHandle gCHandle = GCHandle.Alloc(value, GCHandleType.Pinned); VectorOfFloatPushMulti(_ptr, gCHandle.AddrOfPinnedObject(), value.Length); gCHandle.Free(); } } public void Push(VectorOfFloat other) { VectorOfFloatPushVector(_ptr, other); } public float[] ToArray() { float[] array = new float[Size]; if (array.Length != 0) { GCHandle gCHandle = GCHandle.Alloc(array, GCHandleType.Pinned); VectorOfFloatCopyData(_ptr, gCHandle.AddrOfPinnedObject()); gCHandle.Free(); } return array; } public void Clear() { VectorOfFloatClear(_ptr); } protected override void DisposeObject() { if (_needDispose && _ptr != IntPtr.Zero) { VectorOfFloatRelease(ref _ptr); } } public InputArray GetInputArray() { return new InputArray(cveInputArrayFromVectorOfFloat(_ptr), this); } public OutputArray GetOutputArray() { return new OutputArray(cveOutputArrayFromVectorOfFloat(_ptr), this); } public InputOutputArray GetInputOutputArray() { return new InputOutputArray(cveInputOutputArrayFromVectorOfFloat(_ptr), this); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr VectorOfFloatCreate(); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr VectorOfFloatCreateSize(int size); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfFloatRelease(ref IntPtr v); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int VectorOfFloatGetSize(IntPtr v); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfFloatCopyData(IntPtr v, IntPtr data); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr VectorOfFloatGetStartAddress(IntPtr v); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern long VectorOfFloatGetMemorySize(IntPtr v); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfFloatPushMulti(IntPtr v, IntPtr values, int count); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfFloatPushVector(IntPtr ptr, IntPtr otherPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfFloatClear(IntPtr v); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfFloatGetItem(IntPtr vec, int index, ref float element); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int VectorOfFloatSizeOfItemInBytes(); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveInputArrayFromVectorOfFloat(IntPtr vec); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveOutputArrayFromVectorOfFloat(IntPtr vec); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveInputOutputArrayFromVectorOfFloat(IntPtr vec); void IDisposable.Dispose() { Dispose(); } } [Serializable] [DebuggerTypeProxy(typeof(DebuggerProxy))] public class VectorOfGMat : UnmanagedVector { internal class DebuggerProxy { private VectorOfGMat _v; public GMat[] Values { get { GMat[] array = new GMat[_v.Size]; for (int i = 0; i < array.Length; i++) { array[i] = _v[i]; } return array; } } public DebuggerProxy(VectorOfGMat v) { _v = v; } } private readonly bool _needDispose; public override int Size => VectorOfGMatGetSize(_ptr); public override IntPtr StartAddress => VectorOfGMatGetStartAddress(_ptr); public override long Length => VectorOfGMatGetMemorySize(_ptr); public GMat this[int index] { get { IntPtr element = IntPtr.Zero; VectorOfGMatGetItemPtr(_ptr, index, ref element); return new GMat(element, needDispose: false); } } public static int SizeOfItemInBytes => VectorOfGMatSizeOfItemInBytes(); static VectorOfGMat() { CvInvoke.Init(); } public VectorOfGMat() : this(VectorOfGMatCreate(), needDispose: true) { } internal VectorOfGMat(IntPtr ptr, bool needDispose) { _ptr = ptr; _needDispose = needDispose; } public VectorOfGMat(int size) : this(VectorOfGMatCreateSize(size), needDispose: true) { } public VectorOfGMat(params GMat[] values) : this() { Push(values); } public void Clear() { VectorOfGMatClear(_ptr); } public void Push(GMat value) { VectorOfGMatPush(_ptr, value.Ptr); } public void Push(GMat[] values) { foreach (GMat value in values) { Push(value); } } public void Push(VectorOfGMat other) { VectorOfGMatPushVector(_ptr, other); } protected override void DisposeObject() { if (_needDispose && _ptr != IntPtr.Zero) { VectorOfGMatRelease(ref _ptr); } } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr VectorOfGMatCreate(); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr VectorOfGMatCreateSize(int size); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfGMatRelease(ref IntPtr v); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int VectorOfGMatGetSize(IntPtr v); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr VectorOfGMatGetStartAddress(IntPtr v); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern long VectorOfGMatGetMemorySize(IntPtr v); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfGMatPush(IntPtr v, IntPtr value); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfGMatPushVector(IntPtr ptr, IntPtr otherPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfGMatClear(IntPtr v); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfGMatGetItemPtr(IntPtr vec, int index, ref IntPtr element); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int VectorOfGMatSizeOfItemInBytes(); } [Serializable] [DebuggerTypeProxy(typeof(DebuggerProxy))] public class VectorOfInt : UnmanagedVector, ISerializable, IInputOutputArray, IInputArray, IDisposable, IOutputArray, IInputArrayOfArrays, IOutputArrayOfArrays { internal class DebuggerProxy { private VectorOfInt _v; public int[] Values => _v.ToArray(); public DebuggerProxy(VectorOfInt v) { _v = v; } } private readonly bool _needDispose; public override int Size => VectorOfIntGetSize(_ptr); public override IntPtr StartAddress => VectorOfIntGetStartAddress(_ptr); public override long Length => VectorOfIntGetMemorySize(_ptr); public int this[int index] { get { int element = 0; VectorOfIntGetItem(_ptr, index, ref element); return element; } } public static int SizeOfItemInBytes => VectorOfIntSizeOfItemInBytes(); static VectorOfInt() { CvInvoke.Init(); } public VectorOfInt(SerializationInfo info, StreamingContext context) : this() { Push((int[])info.GetValue("IntArray", typeof(int[]))); } public void GetObjectData(SerializationInfo info, StreamingContext context) { info.AddValue("IntArray", ToArray()); } public VectorOfInt() : this(VectorOfIntCreate(), needDispose: true) { } internal VectorOfInt(IntPtr ptr, bool needDispose) { _ptr = ptr; _needDispose = needDispose; } public VectorOfInt(int size) : this(VectorOfIntCreateSize(size), needDispose: true) { } public VectorOfInt(int[] values) : this() { Push(values); } public void Push(int[] value) { if (value.Length != 0) { GCHandle gCHandle = GCHandle.Alloc(value, GCHandleType.Pinned); VectorOfIntPushMulti(_ptr, gCHandle.AddrOfPinnedObject(), value.Length); gCHandle.Free(); } } public void Push(VectorOfInt other) { VectorOfIntPushVector(_ptr, other); } public int[] ToArray() { int[] array = new int[Size]; if (array.Length != 0) { GCHandle gCHandle = GCHandle.Alloc(array, GCHandleType.Pinned); VectorOfIntCopyData(_ptr, gCHandle.AddrOfPinnedObject()); gCHandle.Free(); } return array; } public void Clear() { VectorOfIntClear(_ptr); } protected override void DisposeObject() { if (_needDispose && _ptr != IntPtr.Zero) { VectorOfIntRelease(ref _ptr); } } public InputArray GetInputArray() { return new InputArray(cveInputArrayFromVectorOfInt(_ptr), this); } public OutputArray GetOutputArray() { return new OutputArray(cveOutputArrayFromVectorOfInt(_ptr), this); } public InputOutputArray GetInputOutputArray() { return new InputOutputArray(cveInputOutputArrayFromVectorOfInt(_ptr), this); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr VectorOfIntCreate(); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr VectorOfIntCreateSize(int size); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfIntRelease(ref IntPtr v); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int VectorOfIntGetSize(IntPtr v); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfIntCopyData(IntPtr v, IntPtr data); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr VectorOfIntGetStartAddress(IntPtr v); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern long VectorOfIntGetMemorySize(IntPtr v); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfIntPushMulti(IntPtr v, IntPtr values, int count); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfIntPushVector(IntPtr ptr, IntPtr otherPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfIntClear(IntPtr v); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfIntGetItem(IntPtr vec, int index, ref int element); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int VectorOfIntSizeOfItemInBytes(); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveInputArrayFromVectorOfInt(IntPtr vec); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveOutputArrayFromVectorOfInt(IntPtr vec); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveInputOutputArrayFromVectorOfInt(IntPtr vec); void IDisposable.Dispose() { Dispose(); } } [Serializable] [DebuggerTypeProxy(typeof(DebuggerProxy))] public class VectorOfIntPtr : UnmanagedVector, ISerializable { internal class DebuggerProxy { private VectorOfIntPtr _v; public IntPtr[] Values => _v.ToArray(); public DebuggerProxy(VectorOfIntPtr v) { _v = v; } } private readonly bool _needDispose; public override int Size => VectorOfIntPtrGetSize(_ptr); public override IntPtr StartAddress => VectorOfIntPtrGetStartAddress(_ptr); public override long Length => VectorOfIntPtrGetMemorySize(_ptr); public IntPtr this[int index] { get { IntPtr element = default(IntPtr); VectorOfIntPtrGetItem(_ptr, index, ref element); return element; } } public static int SizeOfItemInBytes => VectorOfIntPtrSizeOfItemInBytes(); static VectorOfIntPtr() { CvInvoke.Init(); } public VectorOfIntPtr(SerializationInfo info, StreamingContext context) : this() { Push((IntPtr[])info.GetValue("IntPtrArray", typeof(IntPtr[]))); } public void GetObjectData(SerializationInfo info, StreamingContext context) { info.AddValue("IntPtrArray", ToArray()); } public VectorOfIntPtr() : this(VectorOfIntPtrCreate(), needDispose: true) { } internal VectorOfIntPtr(IntPtr ptr, bool needDispose) { _ptr = ptr; _needDispose = needDispose; } public VectorOfIntPtr(int size) : this(VectorOfIntPtrCreateSize(size), needDispose: true) { } public VectorOfIntPtr(IntPtr[] values) : this() { Push(values); } public void Push(IntPtr[] value) { if (value.Length != 0) { GCHandle gCHandle = GCHandle.Alloc(value, GCHandleType.Pinned); VectorOfIntPtrPushMulti(_ptr, gCHandle.AddrOfPinnedObject(), value.Length); gCHandle.Free(); } } public void Push(VectorOfIntPtr other) { VectorOfIntPtrPushVector(_ptr, other); } public IntPtr[] ToArray() { IntPtr[] array = new IntPtr[Size]; if (array.Length != 0) { GCHandle gCHandle = GCHandle.Alloc(array, GCHandleType.Pinned); VectorOfIntPtrCopyData(_ptr, gCHandle.AddrOfPinnedObject()); gCHandle.Free(); } return array; } public void Clear() { VectorOfIntPtrClear(_ptr); } protected override void DisposeObject() { if (_needDispose && _ptr != IntPtr.Zero) { VectorOfIntPtrRelease(ref _ptr); } } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr VectorOfIntPtrCreate(); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr VectorOfIntPtrCreateSize(int size); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfIntPtrRelease(ref IntPtr v); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int VectorOfIntPtrGetSize(IntPtr v); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfIntPtrCopyData(IntPtr v, IntPtr data); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr VectorOfIntPtrGetStartAddress(IntPtr v); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern long VectorOfIntPtrGetMemorySize(IntPtr v); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfIntPtrPushMulti(IntPtr v, IntPtr values, int count); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfIntPtrPushVector(IntPtr ptr, IntPtr otherPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfIntPtrClear(IntPtr v); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfIntPtrGetItem(IntPtr vec, int index, ref IntPtr element); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int VectorOfIntPtrSizeOfItemInBytes(); } [Serializable] [DebuggerTypeProxy(typeof(DebuggerProxy))] public class VectorOfKeyPoint : UnmanagedVector, ISerializable, IInputOutputArray, IInputArray, IDisposable, IOutputArray, IInputArrayOfArrays, IOutputArrayOfArrays { internal class DebuggerProxy { private VectorOfKeyPoint _v; public MKeyPoint[] Values => _v.ToArray(); public DebuggerProxy(VectorOfKeyPoint v) { _v = v; } } private readonly bool _needDispose; public override int Size => VectorOfKeyPointGetSize(_ptr); public override IntPtr StartAddress => VectorOfKeyPointGetStartAddress(_ptr); public override long Length => VectorOfKeyPointGetMemorySize(_ptr); public MKeyPoint this[int index] { get { MKeyPoint element = default(MKeyPoint); VectorOfKeyPointGetItem(_ptr, index, ref element); return element; } } public static int SizeOfItemInBytes => VectorOfKeyPointSizeOfItemInBytes(); static VectorOfKeyPoint() { CvInvoke.Init(); } public VectorOfKeyPoint(SerializationInfo info, StreamingContext context) : this() { Push((MKeyPoint[])info.GetValue("KeyPointArray", typeof(MKeyPoint[]))); } public void GetObjectData(SerializationInfo info, StreamingContext context) { info.AddValue("KeyPointArray", ToArray()); } public VectorOfKeyPoint() : this(VectorOfKeyPointCreate(), needDispose: true) { } internal VectorOfKeyPoint(IntPtr ptr, bool needDispose) { _ptr = ptr; _needDispose = needDispose; } public VectorOfKeyPoint(int size) : this(VectorOfKeyPointCreateSize(size), needDispose: true) { } public VectorOfKeyPoint(MKeyPoint[] values) : this() { Push(values); } public void Push(MKeyPoint[] value) { if (value.Length != 0) { GCHandle gCHandle = GCHandle.Alloc(value, GCHandleType.Pinned); VectorOfKeyPointPushMulti(_ptr, gCHandle.AddrOfPinnedObject(), value.Length); gCHandle.Free(); } } public void Push(VectorOfKeyPoint other) { VectorOfKeyPointPushVector(_ptr, other); } public MKeyPoint[] ToArray() { MKeyPoint[] array = new MKeyPoint[Size]; if (array.Length != 0) { GCHandle gCHandle = GCHandle.Alloc(array, GCHandleType.Pinned); VectorOfKeyPointCopyData(_ptr, gCHandle.AddrOfPinnedObject()); gCHandle.Free(); } return array; } public void Clear() { VectorOfKeyPointClear(_ptr); } protected override void DisposeObject() { if (_needDispose && _ptr != IntPtr.Zero) { VectorOfKeyPointRelease(ref _ptr); } } public InputArray GetInputArray() { return new InputArray(cveInputArrayFromVectorOfKeyPoint(_ptr), this); } public OutputArray GetOutputArray() { return new OutputArray(cveOutputArrayFromVectorOfKeyPoint(_ptr), this); } public InputOutputArray GetInputOutputArray() { return new InputOutputArray(cveInputOutputArrayFromVectorOfKeyPoint(_ptr), this); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr VectorOfKeyPointCreate(); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr VectorOfKeyPointCreateSize(int size); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfKeyPointRelease(ref IntPtr v); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int VectorOfKeyPointGetSize(IntPtr v); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfKeyPointCopyData(IntPtr v, IntPtr data); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr VectorOfKeyPointGetStartAddress(IntPtr v); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern long VectorOfKeyPointGetMemorySize(IntPtr v); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfKeyPointPushMulti(IntPtr v, IntPtr values, int count); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfKeyPointPushVector(IntPtr ptr, IntPtr otherPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfKeyPointClear(IntPtr v); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfKeyPointGetItem(IntPtr vec, int index, ref MKeyPoint element); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int VectorOfKeyPointSizeOfItemInBytes(); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveInputArrayFromVectorOfKeyPoint(IntPtr vec); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveOutputArrayFromVectorOfKeyPoint(IntPtr vec); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveInputOutputArrayFromVectorOfKeyPoint(IntPtr vec); public void FilterByImageBorder(Size imageSize, int borderSize) { VectorOfKeyPointFilterByImageBorder(base.Ptr, imageSize, borderSize); } public void FilterByKeypointSize(float minSize, float maxSize) { VectorOfKeyPointFilterByKeypointSize(base.Ptr, minSize, maxSize); } public void FilterByPixelsMask(Image mask) { VectorOfKeyPointFilterByPixelsMask(base.Ptr, mask); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfKeyPointFilterByImageBorder(IntPtr keypoints, Size imageSize, int borderSize); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfKeyPointFilterByKeypointSize(IntPtr keypoints, float minSize, float maxSize); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfKeyPointFilterByPixelsMask(IntPtr keypoints, IntPtr mask); void IDisposable.Dispose() { Dispose(); } } [Serializable] [DebuggerTypeProxy(typeof(DebuggerProxy))] public class VectorOfMat : UnmanagedVector, IInputOutputArray, IInputArray, IDisposable, IOutputArray, IInputArrayOfArrays, IOutputArrayOfArrays { internal class DebuggerProxy { private VectorOfMat _v; public Mat[] Values { get { Mat[] array = new Mat[_v.Size]; for (int i = 0; i < array.Length; i++) { array[i] = _v[i]; } return array; } } public DebuggerProxy(VectorOfMat v) { _v = v; } } private readonly bool _needDispose; public override int Size => VectorOfMatGetSize(_ptr); public override IntPtr StartAddress => VectorOfMatGetStartAddress(_ptr); public override long Length => VectorOfMatGetMemorySize(_ptr); public Mat this[int index] { get { IntPtr element = IntPtr.Zero; VectorOfMatGetItemPtr(_ptr, index, ref element); return new Mat(element, needDispose: false); } } public static int SizeOfItemInBytes => VectorOfMatSizeOfItemInBytes(); static VectorOfMat() { CvInvoke.Init(); } public VectorOfMat() : this(VectorOfMatCreate(), needDispose: true) { } internal VectorOfMat(IntPtr ptr, bool needDispose) { _ptr = ptr; _needDispose = needDispose; } public VectorOfMat(int size) : this(VectorOfMatCreateSize(size), needDispose: true) { } public VectorOfMat(params Mat[] values) : this() { Push(values); } public void Clear() { VectorOfMatClear(_ptr); } public void Push(Mat value) { VectorOfMatPush(_ptr, value.Ptr); } public void Push(Mat[] values) { foreach (Mat value in values) { Push(value); } } public void Push(VectorOfMat other) { VectorOfMatPushVector(_ptr, other); } protected override void DisposeObject() { if (_needDispose && _ptr != IntPtr.Zero) { VectorOfMatRelease(ref _ptr); } } public InputArray GetInputArray() { return new InputArray(cveInputArrayFromVectorOfMat(_ptr), this); } public OutputArray GetOutputArray() { return new OutputArray(cveOutputArrayFromVectorOfMat(_ptr), this); } public InputOutputArray GetInputOutputArray() { return new InputOutputArray(cveInputOutputArrayFromVectorOfMat(_ptr), this); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr VectorOfMatCreate(); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr VectorOfMatCreateSize(int size); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfMatRelease(ref IntPtr v); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int VectorOfMatGetSize(IntPtr v); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr VectorOfMatGetStartAddress(IntPtr v); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern long VectorOfMatGetMemorySize(IntPtr v); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfMatPush(IntPtr v, IntPtr value); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfMatPushVector(IntPtr ptr, IntPtr otherPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfMatClear(IntPtr v); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfMatGetItemPtr(IntPtr vec, int index, ref IntPtr element); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int VectorOfMatSizeOfItemInBytes(); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveInputArrayFromVectorOfMat(IntPtr vec); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveOutputArrayFromVectorOfMat(IntPtr vec); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveInputOutputArrayFromVectorOfMat(IntPtr vec); public void Push(CvArray cvArray) where TDepth : new() { Push(cvArray.Mat); } public void Push(CvArray[] values) where TDepth : new() { foreach (CvArray cvArray in values) { Push(cvArray); } } void IDisposable.Dispose() { Dispose(); } } [Serializable] [DebuggerTypeProxy(typeof(DebuggerProxy))] public class VectorOfOclPlatformInfo : UnmanagedVector, IInputOutputArray, IInputArray, IDisposable, IOutputArray, IInputArrayOfArrays, IOutputArrayOfArrays { internal class DebuggerProxy { private VectorOfOclPlatformInfo _v; public PlatformInfo[] Values { get { PlatformInfo[] array = new PlatformInfo[_v.Size]; for (int i = 0; i < array.Length; i++) { array[i] = _v[i]; } return array; } } public DebuggerProxy(VectorOfOclPlatformInfo v) { _v = v; } } private readonly bool _needDispose; public override int Size => VectorOfOclPlatformInfoGetSize(_ptr); public override IntPtr StartAddress => VectorOfOclPlatformInfoGetStartAddress(_ptr); public override long Length => VectorOfOclPlatformInfoGetMemorySize(_ptr); public PlatformInfo this[int index] { get { IntPtr element = IntPtr.Zero; VectorOfOclPlatformInfoGetItemPtr(_ptr, index, ref element); return new PlatformInfo(element, needDispose: false); } } public static int SizeOfItemInBytes => VectorOfOclPlatformInfoSizeOfItemInBytes(); static VectorOfOclPlatformInfo() { CvInvoke.Init(); } public VectorOfOclPlatformInfo() : this(VectorOfOclPlatformInfoCreate(), needDispose: true) { } internal VectorOfOclPlatformInfo(IntPtr ptr, bool needDispose) { _ptr = ptr; _needDispose = needDispose; } public VectorOfOclPlatformInfo(int size) : this(VectorOfOclPlatformInfoCreateSize(size), needDispose: true) { } public VectorOfOclPlatformInfo(params PlatformInfo[] values) : this() { Push(values); } public void Clear() { VectorOfOclPlatformInfoClear(_ptr); } public void Push(PlatformInfo value) { VectorOfOclPlatformInfoPush(_ptr, value.Ptr); } public void Push(PlatformInfo[] values) { foreach (PlatformInfo value in values) { Push(value); } } public void Push(VectorOfOclPlatformInfo other) { VectorOfOclPlatformInfoPushVector(_ptr, other); } protected override void DisposeObject() { if (_needDispose && _ptr != IntPtr.Zero) { VectorOfOclPlatformInfoRelease(ref _ptr); } } public InputArray GetInputArray() { return new InputArray(cveInputArrayFromVectorOfOclPlatformInfo(_ptr), this); } public OutputArray GetOutputArray() { return new OutputArray(cveOutputArrayFromVectorOfOclPlatformInfo(_ptr), this); } public InputOutputArray GetInputOutputArray() { return new InputOutputArray(cveInputOutputArrayFromVectorOfOclPlatformInfo(_ptr), this); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr VectorOfOclPlatformInfoCreate(); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr VectorOfOclPlatformInfoCreateSize(int size); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfOclPlatformInfoRelease(ref IntPtr v); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int VectorOfOclPlatformInfoGetSize(IntPtr v); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr VectorOfOclPlatformInfoGetStartAddress(IntPtr v); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern long VectorOfOclPlatformInfoGetMemorySize(IntPtr v); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfOclPlatformInfoPush(IntPtr v, IntPtr value); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfOclPlatformInfoPushVector(IntPtr ptr, IntPtr otherPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfOclPlatformInfoClear(IntPtr v); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfOclPlatformInfoGetItemPtr(IntPtr vec, int index, ref IntPtr element); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int VectorOfOclPlatformInfoSizeOfItemInBytes(); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveInputArrayFromVectorOfOclPlatformInfo(IntPtr vec); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveOutputArrayFromVectorOfOclPlatformInfo(IntPtr vec); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveInputOutputArrayFromVectorOfOclPlatformInfo(IntPtr vec); void IDisposable.Dispose() { Dispose(); } } [Serializable] [DebuggerTypeProxy(typeof(DebuggerProxy))] public class VectorOfPoint : UnmanagedVector, ISerializable, IInputOutputArray, IInputArray, IDisposable, IOutputArray, IInputArrayOfArrays, IOutputArrayOfArrays { internal class DebuggerProxy { private VectorOfPoint _v; public Point[] Values => _v.ToArray(); public DebuggerProxy(VectorOfPoint v) { _v = v; } } private readonly bool _needDispose; public override int Size => VectorOfPointGetSize(_ptr); public override IntPtr StartAddress => VectorOfPointGetStartAddress(_ptr); public override long Length => VectorOfPointGetMemorySize(_ptr); public Point this[int index] { get { Point element = default(Point); VectorOfPointGetItem(_ptr, index, ref element); return element; } } public static int SizeOfItemInBytes => VectorOfPointSizeOfItemInBytes(); static VectorOfPoint() { CvInvoke.Init(); } public VectorOfPoint(SerializationInfo info, StreamingContext context) : this() { Push((Point[])info.GetValue("PointArray", typeof(Point[]))); } public void GetObjectData(SerializationInfo info, StreamingContext context) { info.AddValue("PointArray", ToArray()); } public VectorOfPoint() : this(VectorOfPointCreate(), needDispose: true) { } internal VectorOfPoint(IntPtr ptr, bool needDispose) { _ptr = ptr; _needDispose = needDispose; } public VectorOfPoint(int size) : this(VectorOfPointCreateSize(size), needDispose: true) { } public VectorOfPoint(Point[] values) : this() { Push(values); } public void Push(Point[] value) { if (value.Length != 0) { GCHandle gCHandle = GCHandle.Alloc(value, GCHandleType.Pinned); VectorOfPointPushMulti(_ptr, gCHandle.AddrOfPinnedObject(), value.Length); gCHandle.Free(); } } public void Push(VectorOfPoint other) { VectorOfPointPushVector(_ptr, other); } public Point[] ToArray() { Point[] array = new Point[Size]; if (array.Length != 0) { GCHandle gCHandle = GCHandle.Alloc(array, GCHandleType.Pinned); VectorOfPointCopyData(_ptr, gCHandle.AddrOfPinnedObject()); gCHandle.Free(); } return array; } public void Clear() { VectorOfPointClear(_ptr); } protected override void DisposeObject() { if (_needDispose && _ptr != IntPtr.Zero) { VectorOfPointRelease(ref _ptr); } } public InputArray GetInputArray() { return new InputArray(cveInputArrayFromVectorOfPoint(_ptr), this); } public OutputArray GetOutputArray() { return new OutputArray(cveOutputArrayFromVectorOfPoint(_ptr), this); } public InputOutputArray GetInputOutputArray() { return new InputOutputArray(cveInputOutputArrayFromVectorOfPoint(_ptr), this); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr VectorOfPointCreate(); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr VectorOfPointCreateSize(int size); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfPointRelease(ref IntPtr v); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int VectorOfPointGetSize(IntPtr v); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfPointCopyData(IntPtr v, IntPtr data); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr VectorOfPointGetStartAddress(IntPtr v); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern long VectorOfPointGetMemorySize(IntPtr v); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfPointPushMulti(IntPtr v, IntPtr values, int count); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfPointPushVector(IntPtr ptr, IntPtr otherPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfPointClear(IntPtr v); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfPointGetItem(IntPtr vec, int index, ref Point element); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int VectorOfPointSizeOfItemInBytes(); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveInputArrayFromVectorOfPoint(IntPtr vec); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveOutputArrayFromVectorOfPoint(IntPtr vec); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveInputOutputArrayFromVectorOfPoint(IntPtr vec); void IDisposable.Dispose() { Dispose(); } } [Serializable] [DebuggerTypeProxy(typeof(DebuggerProxy))] public class VectorOfPoint3D32F : UnmanagedVector, ISerializable, IInputOutputArray, IInputArray, IDisposable, IOutputArray, IInputArrayOfArrays, IOutputArrayOfArrays { internal class DebuggerProxy { private VectorOfPoint3D32F _v; public MCvPoint3D32f[] Values => _v.ToArray(); public DebuggerProxy(VectorOfPoint3D32F v) { _v = v; } } private readonly bool _needDispose; public override int Size => VectorOfPoint3D32FGetSize(_ptr); public override IntPtr StartAddress => VectorOfPoint3D32FGetStartAddress(_ptr); public override long Length => VectorOfPoint3D32FGetMemorySize(_ptr); public MCvPoint3D32f this[int index] { get { MCvPoint3D32f element = default(MCvPoint3D32f); VectorOfPoint3D32FGetItem(_ptr, index, ref element); return element; } } public static int SizeOfItemInBytes => VectorOfPoint3D32FSizeOfItemInBytes(); static VectorOfPoint3D32F() { CvInvoke.Init(); } public VectorOfPoint3D32F(SerializationInfo info, StreamingContext context) : this() { Push((MCvPoint3D32f[])info.GetValue("Point3D32FArray", typeof(MCvPoint3D32f[]))); } public void GetObjectData(SerializationInfo info, StreamingContext context) { info.AddValue("Point3D32FArray", ToArray()); } public VectorOfPoint3D32F() : this(VectorOfPoint3D32FCreate(), needDispose: true) { } internal VectorOfPoint3D32F(IntPtr ptr, bool needDispose) { _ptr = ptr; _needDispose = needDispose; } public VectorOfPoint3D32F(int size) : this(VectorOfPoint3D32FCreateSize(size), needDispose: true) { } public VectorOfPoint3D32F(MCvPoint3D32f[] values) : this() { Push(values); } public void Push(MCvPoint3D32f[] value) { if (value.Length != 0) { GCHandle gCHandle = GCHandle.Alloc(value, GCHandleType.Pinned); VectorOfPoint3D32FPushMulti(_ptr, gCHandle.AddrOfPinnedObject(), value.Length); gCHandle.Free(); } } public void Push(VectorOfPoint3D32F other) { VectorOfPoint3D32FPushVector(_ptr, other); } public MCvPoint3D32f[] ToArray() { MCvPoint3D32f[] array = new MCvPoint3D32f[Size]; if (array.Length != 0) { GCHandle gCHandle = GCHandle.Alloc(array, GCHandleType.Pinned); VectorOfPoint3D32FCopyData(_ptr, gCHandle.AddrOfPinnedObject()); gCHandle.Free(); } return array; } public void Clear() { VectorOfPoint3D32FClear(_ptr); } protected override void DisposeObject() { if (_needDispose && _ptr != IntPtr.Zero) { VectorOfPoint3D32FRelease(ref _ptr); } } public InputArray GetInputArray() { return new InputArray(cveInputArrayFromVectorOfPoint3D32F(_ptr), this); } public OutputArray GetOutputArray() { return new OutputArray(cveOutputArrayFromVectorOfPoint3D32F(_ptr), this); } public InputOutputArray GetInputOutputArray() { return new InputOutputArray(cveInputOutputArrayFromVectorOfPoint3D32F(_ptr), this); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr VectorOfPoint3D32FCreate(); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr VectorOfPoint3D32FCreateSize(int size); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfPoint3D32FRelease(ref IntPtr v); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int VectorOfPoint3D32FGetSize(IntPtr v); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfPoint3D32FCopyData(IntPtr v, IntPtr data); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr VectorOfPoint3D32FGetStartAddress(IntPtr v); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern long VectorOfPoint3D32FGetMemorySize(IntPtr v); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfPoint3D32FPushMulti(IntPtr v, IntPtr values, int count); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfPoint3D32FPushVector(IntPtr ptr, IntPtr otherPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfPoint3D32FClear(IntPtr v); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfPoint3D32FGetItem(IntPtr vec, int index, ref MCvPoint3D32f element); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int VectorOfPoint3D32FSizeOfItemInBytes(); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveInputArrayFromVectorOfPoint3D32F(IntPtr vec); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveOutputArrayFromVectorOfPoint3D32F(IntPtr vec); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveInputOutputArrayFromVectorOfPoint3D32F(IntPtr vec); void IDisposable.Dispose() { Dispose(); } } [Serializable] [DebuggerTypeProxy(typeof(DebuggerProxy))] public class VectorOfPointF : UnmanagedVector, ISerializable, IInputOutputArray, IInputArray, IDisposable, IOutputArray, IInputArrayOfArrays, IOutputArrayOfArrays { internal class DebuggerProxy { private VectorOfPointF _v; public PointF[] Values => _v.ToArray(); public DebuggerProxy(VectorOfPointF v) { _v = v; } } private readonly bool _needDispose; public override int Size => VectorOfPointFGetSize(_ptr); public override IntPtr StartAddress => VectorOfPointFGetStartAddress(_ptr); public override long Length => VectorOfPointFGetMemorySize(_ptr); public PointF this[int index] { get { PointF element = default(PointF); VectorOfPointFGetItem(_ptr, index, ref element); return element; } } public static int SizeOfItemInBytes => VectorOfPointFSizeOfItemInBytes(); static VectorOfPointF() { CvInvoke.Init(); } public VectorOfPointF(SerializationInfo info, StreamingContext context) : this() { Push((PointF[])info.GetValue("PointFArray", typeof(PointF[]))); } public void GetObjectData(SerializationInfo info, StreamingContext context) { info.AddValue("PointFArray", ToArray()); } public VectorOfPointF() : this(VectorOfPointFCreate(), needDispose: true) { } internal VectorOfPointF(IntPtr ptr, bool needDispose) { _ptr = ptr; _needDispose = needDispose; } public VectorOfPointF(int size) : this(VectorOfPointFCreateSize(size), needDispose: true) { } public VectorOfPointF(PointF[] values) : this() { Push(values); } public void Push(PointF[] value) { if (value.Length != 0) { GCHandle gCHandle = GCHandle.Alloc(value, GCHandleType.Pinned); VectorOfPointFPushMulti(_ptr, gCHandle.AddrOfPinnedObject(), value.Length); gCHandle.Free(); } } public void Push(VectorOfPointF other) { VectorOfPointFPushVector(_ptr, other); } public PointF[] ToArray() { PointF[] array = new PointF[Size]; if (array.Length != 0) { GCHandle gCHandle = GCHandle.Alloc(array, GCHandleType.Pinned); VectorOfPointFCopyData(_ptr, gCHandle.AddrOfPinnedObject()); gCHandle.Free(); } return array; } public void Clear() { VectorOfPointFClear(_ptr); } protected override void DisposeObject() { if (_needDispose && _ptr != IntPtr.Zero) { VectorOfPointFRelease(ref _ptr); } } public InputArray GetInputArray() { return new InputArray(cveInputArrayFromVectorOfPointF(_ptr), this); } public OutputArray GetOutputArray() { return new OutputArray(cveOutputArrayFromVectorOfPointF(_ptr), this); } public InputOutputArray GetInputOutputArray() { return new InputOutputArray(cveInputOutputArrayFromVectorOfPointF(_ptr), this); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr VectorOfPointFCreate(); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr VectorOfPointFCreateSize(int size); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfPointFRelease(ref IntPtr v); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int VectorOfPointFGetSize(IntPtr v); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfPointFCopyData(IntPtr v, IntPtr data); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr VectorOfPointFGetStartAddress(IntPtr v); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern long VectorOfPointFGetMemorySize(IntPtr v); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfPointFPushMulti(IntPtr v, IntPtr values, int count); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfPointFPushVector(IntPtr ptr, IntPtr otherPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfPointFClear(IntPtr v); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfPointFGetItem(IntPtr vec, int index, ref PointF element); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int VectorOfPointFSizeOfItemInBytes(); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveInputArrayFromVectorOfPointF(IntPtr vec); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveOutputArrayFromVectorOfPointF(IntPtr vec); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveInputOutputArrayFromVectorOfPointF(IntPtr vec); void IDisposable.Dispose() { Dispose(); } } [Serializable] [DebuggerTypeProxy(typeof(DebuggerProxy))] public class VectorOfRect : UnmanagedVector, ISerializable, IInputOutputArray, IInputArray, IDisposable, IOutputArray, IInputArrayOfArrays, IOutputArrayOfArrays { internal class DebuggerProxy { private VectorOfRect _v; public Rectangle[] Values => _v.ToArray(); public DebuggerProxy(VectorOfRect v) { _v = v; } } private readonly bool _needDispose; public override int Size => VectorOfRectGetSize(_ptr); public override IntPtr StartAddress => VectorOfRectGetStartAddress(_ptr); public override long Length => VectorOfRectGetMemorySize(_ptr); public Rectangle this[int index] { get { Rectangle element = default(Rectangle); VectorOfRectGetItem(_ptr, index, ref element); return element; } } public static int SizeOfItemInBytes => VectorOfRectSizeOfItemInBytes(); static VectorOfRect() { CvInvoke.Init(); } public VectorOfRect(SerializationInfo info, StreamingContext context) : this() { Push((Rectangle[])info.GetValue("RectArray", typeof(Rectangle[]))); } public void GetObjectData(SerializationInfo info, StreamingContext context) { info.AddValue("RectArray", ToArray()); } public VectorOfRect() : this(VectorOfRectCreate(), needDispose: true) { } internal VectorOfRect(IntPtr ptr, bool needDispose) { _ptr = ptr; _needDispose = needDispose; } public VectorOfRect(int size) : this(VectorOfRectCreateSize(size), needDispose: true) { } public VectorOfRect(Rectangle[] values) : this() { Push(values); } public void Push(Rectangle[] value) { if (value.Length != 0) { GCHandle gCHandle = GCHandle.Alloc(value, GCHandleType.Pinned); VectorOfRectPushMulti(_ptr, gCHandle.AddrOfPinnedObject(), value.Length); gCHandle.Free(); } } public void Push(VectorOfRect other) { VectorOfRectPushVector(_ptr, other); } public Rectangle[] ToArray() { Rectangle[] array = new Rectangle[Size]; if (array.Length != 0) { GCHandle gCHandle = GCHandle.Alloc(array, GCHandleType.Pinned); VectorOfRectCopyData(_ptr, gCHandle.AddrOfPinnedObject()); gCHandle.Free(); } return array; } public void Clear() { VectorOfRectClear(_ptr); } protected override void DisposeObject() { if (_needDispose && _ptr != IntPtr.Zero) { VectorOfRectRelease(ref _ptr); } } public InputArray GetInputArray() { return new InputArray(cveInputArrayFromVectorOfRect(_ptr), this); } public OutputArray GetOutputArray() { return new OutputArray(cveOutputArrayFromVectorOfRect(_ptr), this); } public InputOutputArray GetInputOutputArray() { return new InputOutputArray(cveInputOutputArrayFromVectorOfRect(_ptr), this); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr VectorOfRectCreate(); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr VectorOfRectCreateSize(int size); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfRectRelease(ref IntPtr v); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int VectorOfRectGetSize(IntPtr v); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfRectCopyData(IntPtr v, IntPtr data); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr VectorOfRectGetStartAddress(IntPtr v); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern long VectorOfRectGetMemorySize(IntPtr v); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfRectPushMulti(IntPtr v, IntPtr values, int count); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfRectPushVector(IntPtr ptr, IntPtr otherPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfRectClear(IntPtr v); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfRectGetItem(IntPtr vec, int index, ref Rectangle element); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int VectorOfRectSizeOfItemInBytes(); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveInputArrayFromVectorOfRect(IntPtr vec); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveOutputArrayFromVectorOfRect(IntPtr vec); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveInputOutputArrayFromVectorOfRect(IntPtr vec); void IDisposable.Dispose() { Dispose(); } } [Serializable] [DebuggerTypeProxy(typeof(DebuggerProxy))] public class VectorOfRotatedRect : UnmanagedVector, ISerializable, IInputOutputArray, IInputArray, IDisposable, IOutputArray, IInputArrayOfArrays, IOutputArrayOfArrays { internal class DebuggerProxy { private VectorOfRotatedRect _v; public RotatedRect[] Values => _v.ToArray(); public DebuggerProxy(VectorOfRotatedRect v) { _v = v; } } private readonly bool _needDispose; public override int Size => VectorOfRotatedRectGetSize(_ptr); public override IntPtr StartAddress => VectorOfRotatedRectGetStartAddress(_ptr); public override long Length => VectorOfRotatedRectGetMemorySize(_ptr); public RotatedRect this[int index] { get { RotatedRect element = default(RotatedRect); VectorOfRotatedRectGetItem(_ptr, index, ref element); return element; } } public static int SizeOfItemInBytes => VectorOfRotatedRectSizeOfItemInBytes(); static VectorOfRotatedRect() { CvInvoke.Init(); } public VectorOfRotatedRect(SerializationInfo info, StreamingContext context) : this() { Push((RotatedRect[])info.GetValue("RotatedRectArray", typeof(RotatedRect[]))); } public void GetObjectData(SerializationInfo info, StreamingContext context) { info.AddValue("RotatedRectArray", ToArray()); } public VectorOfRotatedRect() : this(VectorOfRotatedRectCreate(), needDispose: true) { } internal VectorOfRotatedRect(IntPtr ptr, bool needDispose) { _ptr = ptr; _needDispose = needDispose; } public VectorOfRotatedRect(int size) : this(VectorOfRotatedRectCreateSize(size), needDispose: true) { } public VectorOfRotatedRect(RotatedRect[] values) : this() { Push(values); } public void Push(RotatedRect[] value) { if (value.Length != 0) { GCHandle gCHandle = GCHandle.Alloc(value, GCHandleType.Pinned); VectorOfRotatedRectPushMulti(_ptr, gCHandle.AddrOfPinnedObject(), value.Length); gCHandle.Free(); } } public void Push(VectorOfRotatedRect other) { VectorOfRotatedRectPushVector(_ptr, other); } public RotatedRect[] ToArray() { RotatedRect[] array = new RotatedRect[Size]; if (array.Length != 0) { GCHandle gCHandle = GCHandle.Alloc(array, GCHandleType.Pinned); VectorOfRotatedRectCopyData(_ptr, gCHandle.AddrOfPinnedObject()); gCHandle.Free(); } return array; } public void Clear() { VectorOfRotatedRectClear(_ptr); } protected override void DisposeObject() { if (_needDispose && _ptr != IntPtr.Zero) { VectorOfRotatedRectRelease(ref _ptr); } } public InputArray GetInputArray() { return new InputArray(cveInputArrayFromVectorOfRotatedRect(_ptr), this); } public OutputArray GetOutputArray() { return new OutputArray(cveOutputArrayFromVectorOfRotatedRect(_ptr), this); } public InputOutputArray GetInputOutputArray() { return new InputOutputArray(cveInputOutputArrayFromVectorOfRotatedRect(_ptr), this); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr VectorOfRotatedRectCreate(); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr VectorOfRotatedRectCreateSize(int size); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfRotatedRectRelease(ref IntPtr v); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int VectorOfRotatedRectGetSize(IntPtr v); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfRotatedRectCopyData(IntPtr v, IntPtr data); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr VectorOfRotatedRectGetStartAddress(IntPtr v); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern long VectorOfRotatedRectGetMemorySize(IntPtr v); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfRotatedRectPushMulti(IntPtr v, IntPtr values, int count); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfRotatedRectPushVector(IntPtr ptr, IntPtr otherPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfRotatedRectClear(IntPtr v); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfRotatedRectGetItem(IntPtr vec, int index, ref RotatedRect element); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int VectorOfRotatedRectSizeOfItemInBytes(); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveInputArrayFromVectorOfRotatedRect(IntPtr vec); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveOutputArrayFromVectorOfRotatedRect(IntPtr vec); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveInputOutputArrayFromVectorOfRotatedRect(IntPtr vec); void IDisposable.Dispose() { Dispose(); } } [Serializable] [DebuggerTypeProxy(typeof(DebuggerProxy))] public class VectorOfSize : UnmanagedVector, ISerializable, IInputOutputArray, IInputArray, IDisposable, IOutputArray, IInputArrayOfArrays, IOutputArrayOfArrays { internal class DebuggerProxy { private VectorOfSize _v; public Size[] Values => _v.ToArray(); public DebuggerProxy(VectorOfSize v) { _v = v; } } private readonly bool _needDispose; public override int Size => VectorOfSizeGetSize(_ptr); public override IntPtr StartAddress => VectorOfSizeGetStartAddress(_ptr); public override long Length => VectorOfSizeGetMemorySize(_ptr); public Size this[int index] { get { Size element = default(Size); VectorOfSizeGetItem(_ptr, index, ref element); return element; } } public static int SizeOfItemInBytes => VectorOfSizeSizeOfItemInBytes(); static VectorOfSize() { CvInvoke.Init(); } public VectorOfSize(SerializationInfo info, StreamingContext context) : this() { Push((Size[])info.GetValue("SizeArray", typeof(Size[]))); } public void GetObjectData(SerializationInfo info, StreamingContext context) { info.AddValue("SizeArray", ToArray()); } public VectorOfSize() : this(VectorOfSizeCreate(), needDispose: true) { } internal VectorOfSize(IntPtr ptr, bool needDispose) { _ptr = ptr; _needDispose = needDispose; } public VectorOfSize(int size) : this(VectorOfSizeCreateSize(size), needDispose: true) { } public VectorOfSize(Size[] values) : this() { Push(values); } public void Push(Size[] value) { if (value.Length != 0) { GCHandle gCHandle = GCHandle.Alloc(value, GCHandleType.Pinned); VectorOfSizePushMulti(_ptr, gCHandle.AddrOfPinnedObject(), value.Length); gCHandle.Free(); } } public void Push(VectorOfSize other) { VectorOfSizePushVector(_ptr, other); } public Size[] ToArray() { Size[] array = new Size[Size]; if (array.Length != 0) { GCHandle gCHandle = GCHandle.Alloc(array, GCHandleType.Pinned); VectorOfSizeCopyData(_ptr, gCHandle.AddrOfPinnedObject()); gCHandle.Free(); } return array; } public void Clear() { VectorOfSizeClear(_ptr); } protected override void DisposeObject() { if (_needDispose && _ptr != IntPtr.Zero) { VectorOfSizeRelease(ref _ptr); } } public InputArray GetInputArray() { return new InputArray(cveInputArrayFromVectorOfSize(_ptr), this); } public OutputArray GetOutputArray() { return new OutputArray(cveOutputArrayFromVectorOfSize(_ptr), this); } public InputOutputArray GetInputOutputArray() { return new InputOutputArray(cveInputOutputArrayFromVectorOfSize(_ptr), this); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr VectorOfSizeCreate(); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr VectorOfSizeCreateSize(int size); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfSizeRelease(ref IntPtr v); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int VectorOfSizeGetSize(IntPtr v); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfSizeCopyData(IntPtr v, IntPtr data); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr VectorOfSizeGetStartAddress(IntPtr v); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern long VectorOfSizeGetMemorySize(IntPtr v); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfSizePushMulti(IntPtr v, IntPtr values, int count); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfSizePushVector(IntPtr ptr, IntPtr otherPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfSizeClear(IntPtr v); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfSizeGetItem(IntPtr vec, int index, ref Size element); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int VectorOfSizeSizeOfItemInBytes(); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveInputArrayFromVectorOfSize(IntPtr vec); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveOutputArrayFromVectorOfSize(IntPtr vec); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveInputOutputArrayFromVectorOfSize(IntPtr vec); void IDisposable.Dispose() { Dispose(); } } [Serializable] [DebuggerTypeProxy(typeof(DebuggerProxy))] public class VectorOfTriangle2DF : UnmanagedVector, ISerializable, IInputOutputArray, IInputArray, IDisposable, IOutputArray, IInputArrayOfArrays, IOutputArrayOfArrays { internal class DebuggerProxy { private VectorOfTriangle2DF _v; public Triangle2DF[] Values => _v.ToArray(); public DebuggerProxy(VectorOfTriangle2DF v) { _v = v; } } private readonly bool _needDispose; public override int Size => VectorOfTriangle2DFGetSize(_ptr); public override IntPtr StartAddress => VectorOfTriangle2DFGetStartAddress(_ptr); public override long Length => VectorOfTriangle2DFGetMemorySize(_ptr); public Triangle2DF this[int index] { get { Triangle2DF element = default(Triangle2DF); VectorOfTriangle2DFGetItem(_ptr, index, ref element); return element; } } public static int SizeOfItemInBytes => VectorOfTriangle2DFSizeOfItemInBytes(); static VectorOfTriangle2DF() { CvInvoke.Init(); } public VectorOfTriangle2DF(SerializationInfo info, StreamingContext context) : this() { Push((Triangle2DF[])info.GetValue("Triangle2DFArray", typeof(Triangle2DF[]))); } public void GetObjectData(SerializationInfo info, StreamingContext context) { info.AddValue("Triangle2DFArray", ToArray()); } public VectorOfTriangle2DF() : this(VectorOfTriangle2DFCreate(), needDispose: true) { } internal VectorOfTriangle2DF(IntPtr ptr, bool needDispose) { _ptr = ptr; _needDispose = needDispose; } public VectorOfTriangle2DF(int size) : this(VectorOfTriangle2DFCreateSize(size), needDispose: true) { } public VectorOfTriangle2DF(Triangle2DF[] values) : this() { Push(values); } public void Push(Triangle2DF[] value) { if (value.Length != 0) { GCHandle gCHandle = GCHandle.Alloc(value, GCHandleType.Pinned); VectorOfTriangle2DFPushMulti(_ptr, gCHandle.AddrOfPinnedObject(), value.Length); gCHandle.Free(); } } public void Push(VectorOfTriangle2DF other) { VectorOfTriangle2DFPushVector(_ptr, other); } public Triangle2DF[] ToArray() { Triangle2DF[] array = new Triangle2DF[Size]; if (array.Length != 0) { GCHandle gCHandle = GCHandle.Alloc(array, GCHandleType.Pinned); VectorOfTriangle2DFCopyData(_ptr, gCHandle.AddrOfPinnedObject()); gCHandle.Free(); } return array; } public void Clear() { VectorOfTriangle2DFClear(_ptr); } protected override void DisposeObject() { if (_needDispose && _ptr != IntPtr.Zero) { VectorOfTriangle2DFRelease(ref _ptr); } } public InputArray GetInputArray() { return new InputArray(cveInputArrayFromVectorOfTriangle2DF(_ptr), this); } public OutputArray GetOutputArray() { return new OutputArray(cveOutputArrayFromVectorOfTriangle2DF(_ptr), this); } public InputOutputArray GetInputOutputArray() { return new InputOutputArray(cveInputOutputArrayFromVectorOfTriangle2DF(_ptr), this); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr VectorOfTriangle2DFCreate(); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr VectorOfTriangle2DFCreateSize(int size); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfTriangle2DFRelease(ref IntPtr v); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int VectorOfTriangle2DFGetSize(IntPtr v); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfTriangle2DFCopyData(IntPtr v, IntPtr data); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr VectorOfTriangle2DFGetStartAddress(IntPtr v); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern long VectorOfTriangle2DFGetMemorySize(IntPtr v); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfTriangle2DFPushMulti(IntPtr v, IntPtr values, int count); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfTriangle2DFPushVector(IntPtr ptr, IntPtr otherPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfTriangle2DFClear(IntPtr v); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfTriangle2DFGetItem(IntPtr vec, int index, ref Triangle2DF element); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int VectorOfTriangle2DFSizeOfItemInBytes(); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveInputArrayFromVectorOfTriangle2DF(IntPtr vec); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveOutputArrayFromVectorOfTriangle2DF(IntPtr vec); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveInputOutputArrayFromVectorOfTriangle2DF(IntPtr vec); void IDisposable.Dispose() { Dispose(); } } [Serializable] [DebuggerTypeProxy(typeof(DebuggerProxy))] public class VectorOfUMat : UnmanagedVector, IInputOutputArray, IInputArray, IDisposable, IOutputArray, IInputArrayOfArrays, IOutputArrayOfArrays { internal class DebuggerProxy { private VectorOfUMat _v; public UMat[] Values { get { UMat[] array = new UMat[_v.Size]; for (int i = 0; i < array.Length; i++) { array[i] = _v[i]; } return array; } } public DebuggerProxy(VectorOfUMat v) { _v = v; } } private readonly bool _needDispose; public override int Size => VectorOfUMatGetSize(_ptr); public override IntPtr StartAddress => VectorOfUMatGetStartAddress(_ptr); public override long Length => VectorOfUMatGetMemorySize(_ptr); public UMat this[int index] { get { IntPtr element = IntPtr.Zero; VectorOfUMatGetItemPtr(_ptr, index, ref element); return new UMat(element, needDispose: false); } } public static int SizeOfItemInBytes => VectorOfUMatSizeOfItemInBytes(); static VectorOfUMat() { CvInvoke.Init(); } public VectorOfUMat() : this(VectorOfUMatCreate(), needDispose: true) { } internal VectorOfUMat(IntPtr ptr, bool needDispose) { _ptr = ptr; _needDispose = needDispose; } public VectorOfUMat(int size) : this(VectorOfUMatCreateSize(size), needDispose: true) { } public VectorOfUMat(params UMat[] values) : this() { Push(values); } public void Clear() { VectorOfUMatClear(_ptr); } public void Push(UMat value) { VectorOfUMatPush(_ptr, value.Ptr); } public void Push(UMat[] values) { foreach (UMat value in values) { Push(value); } } public void Push(VectorOfUMat other) { VectorOfUMatPushVector(_ptr, other); } protected override void DisposeObject() { if (_needDispose && _ptr != IntPtr.Zero) { VectorOfUMatRelease(ref _ptr); } } public InputArray GetInputArray() { return new InputArray(cveInputArrayFromVectorOfUMat(_ptr), this); } public OutputArray GetOutputArray() { return new OutputArray(cveOutputArrayFromVectorOfUMat(_ptr), this); } public InputOutputArray GetInputOutputArray() { return new InputOutputArray(cveInputOutputArrayFromVectorOfUMat(_ptr), this); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr VectorOfUMatCreate(); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr VectorOfUMatCreateSize(int size); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfUMatRelease(ref IntPtr v); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int VectorOfUMatGetSize(IntPtr v); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr VectorOfUMatGetStartAddress(IntPtr v); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern long VectorOfUMatGetMemorySize(IntPtr v); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfUMatPush(IntPtr v, IntPtr value); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfUMatPushVector(IntPtr ptr, IntPtr otherPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfUMatClear(IntPtr v); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfUMatGetItemPtr(IntPtr vec, int index, ref IntPtr element); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int VectorOfUMatSizeOfItemInBytes(); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveInputArrayFromVectorOfUMat(IntPtr vec); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveOutputArrayFromVectorOfUMat(IntPtr vec); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveInputOutputArrayFromVectorOfUMat(IntPtr vec); void IDisposable.Dispose() { Dispose(); } } [Serializable] [DebuggerTypeProxy(typeof(DebuggerProxy))] public class VectorOfVectorOfByte : UnmanagedVector, IInputOutputArray, IInputArray, IDisposable, IOutputArray, IInputArrayOfArrays, IOutputArrayOfArrays { internal class DebuggerProxy { private VectorOfVectorOfByte _v; public byte[][] Values => _v.ToArrayOfArray(); public DebuggerProxy(VectorOfVectorOfByte v) { _v = v; } } private readonly bool _needDispose; public override int Size => VectorOfVectorOfByteGetSize(_ptr); public override IntPtr StartAddress => VectorOfVectorOfByteGetStartAddress(_ptr); public override long Length => VectorOfVectorOfByteGetMemorySize(_ptr); public VectorOfByte this[int index] { get { IntPtr element = IntPtr.Zero; VectorOfVectorOfByteGetItemPtr(_ptr, index, ref element); return new VectorOfByte(element, needDispose: false); } } public static int SizeOfItemInBytes => VectorOfVectorOfByteSizeOfItemInBytes(); static VectorOfVectorOfByte() { CvInvoke.Init(); } public VectorOfVectorOfByte() : this(VectorOfVectorOfByteCreate(), needDispose: true) { } internal VectorOfVectorOfByte(IntPtr ptr, bool needDispose) { _ptr = ptr; _needDispose = needDispose; } public VectorOfVectorOfByte(int size) : this(VectorOfVectorOfByteCreateSize(size), needDispose: true) { } public VectorOfVectorOfByte(params VectorOfByte[] values) : this() { Push(values); } public void Clear() { VectorOfVectorOfByteClear(_ptr); } public void Push(VectorOfByte value) { VectorOfVectorOfBytePush(_ptr, value.Ptr); } public void Push(VectorOfByte[] values) { foreach (VectorOfByte value in values) { Push(value); } } public void Push(VectorOfVectorOfByte other) { VectorOfVectorOfBytePushVector(_ptr, other); } protected override void DisposeObject() { if (_needDispose && _ptr != IntPtr.Zero) { VectorOfVectorOfByteRelease(ref _ptr); } } public InputArray GetInputArray() { return new InputArray(cveInputArrayFromVectorOfVectorOfByte(_ptr), this); } public OutputArray GetOutputArray() { return new OutputArray(cveOutputArrayFromVectorOfVectorOfByte(_ptr), this); } public InputOutputArray GetInputOutputArray() { return new InputOutputArray(cveInputOutputArrayFromVectorOfVectorOfByte(_ptr), this); } public VectorOfVectorOfByte(byte[][] values) : this() { using VectorOfByte vectorOfByte = new VectorOfByte(); for (int i = 0; i < values.Length; i++) { vectorOfByte.Push(values[i]); Push(vectorOfByte); vectorOfByte.Clear(); } } public byte[][] ToArrayOfArray() { int size = Size; byte[][] array = new byte[size][]; for (int i = 0; i < size; i++) { using VectorOfByte vectorOfByte = this[i]; array[i] = vectorOfByte.ToArray(); } return array; } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr VectorOfVectorOfByteCreate(); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr VectorOfVectorOfByteCreateSize(int size); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfVectorOfByteRelease(ref IntPtr v); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int VectorOfVectorOfByteGetSize(IntPtr v); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr VectorOfVectorOfByteGetStartAddress(IntPtr v); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern long VectorOfVectorOfByteGetMemorySize(IntPtr v); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfVectorOfBytePush(IntPtr v, IntPtr value); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfVectorOfBytePushVector(IntPtr ptr, IntPtr otherPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfVectorOfByteClear(IntPtr v); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfVectorOfByteGetItemPtr(IntPtr vec, int index, ref IntPtr element); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int VectorOfVectorOfByteSizeOfItemInBytes(); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveInputArrayFromVectorOfVectorOfByte(IntPtr vec); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveOutputArrayFromVectorOfVectorOfByte(IntPtr vec); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveInputOutputArrayFromVectorOfVectorOfByte(IntPtr vec); void IDisposable.Dispose() { Dispose(); } } [Serializable] [DebuggerTypeProxy(typeof(DebuggerProxy))] public class VectorOfVectorOfDMatch : UnmanagedVector, IInputOutputArray, IInputArray, IDisposable, IOutputArray, IInputArrayOfArrays, IOutputArrayOfArrays { internal class DebuggerProxy { private VectorOfVectorOfDMatch _v; public MDMatch[][] Values => _v.ToArrayOfArray(); public DebuggerProxy(VectorOfVectorOfDMatch v) { _v = v; } } private readonly bool _needDispose; public override int Size => VectorOfVectorOfDMatchGetSize(_ptr); public override IntPtr StartAddress => VectorOfVectorOfDMatchGetStartAddress(_ptr); public override long Length => VectorOfVectorOfDMatchGetMemorySize(_ptr); public VectorOfDMatch this[int index] { get { IntPtr element = IntPtr.Zero; VectorOfVectorOfDMatchGetItemPtr(_ptr, index, ref element); return new VectorOfDMatch(element, needDispose: false); } } public static int SizeOfItemInBytes => VectorOfVectorOfDMatchSizeOfItemInBytes(); static VectorOfVectorOfDMatch() { CvInvoke.Init(); } public VectorOfVectorOfDMatch() : this(VectorOfVectorOfDMatchCreate(), needDispose: true) { } internal VectorOfVectorOfDMatch(IntPtr ptr, bool needDispose) { _ptr = ptr; _needDispose = needDispose; } public VectorOfVectorOfDMatch(int size) : this(VectorOfVectorOfDMatchCreateSize(size), needDispose: true) { } public VectorOfVectorOfDMatch(params VectorOfDMatch[] values) : this() { Push(values); } public void Clear() { VectorOfVectorOfDMatchClear(_ptr); } public void Push(VectorOfDMatch value) { VectorOfVectorOfDMatchPush(_ptr, value.Ptr); } public void Push(VectorOfDMatch[] values) { foreach (VectorOfDMatch value in values) { Push(value); } } public void Push(VectorOfVectorOfDMatch other) { VectorOfVectorOfDMatchPushVector(_ptr, other); } protected override void DisposeObject() { if (_needDispose && _ptr != IntPtr.Zero) { VectorOfVectorOfDMatchRelease(ref _ptr); } } public InputArray GetInputArray() { return new InputArray(cveInputArrayFromVectorOfVectorOfDMatch(_ptr), this); } public OutputArray GetOutputArray() { return new OutputArray(cveOutputArrayFromVectorOfVectorOfDMatch(_ptr), this); } public InputOutputArray GetInputOutputArray() { return new InputOutputArray(cveInputOutputArrayFromVectorOfVectorOfDMatch(_ptr), this); } public VectorOfVectorOfDMatch(MDMatch[][] values) : this() { using VectorOfDMatch vectorOfDMatch = new VectorOfDMatch(); for (int i = 0; i < values.Length; i++) { vectorOfDMatch.Push(values[i]); Push(vectorOfDMatch); vectorOfDMatch.Clear(); } } public MDMatch[][] ToArrayOfArray() { int size = Size; MDMatch[][] array = new MDMatch[size][]; for (int i = 0; i < size; i++) { using VectorOfDMatch vectorOfDMatch = this[i]; array[i] = vectorOfDMatch.ToArray(); } return array; } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr VectorOfVectorOfDMatchCreate(); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr VectorOfVectorOfDMatchCreateSize(int size); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfVectorOfDMatchRelease(ref IntPtr v); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int VectorOfVectorOfDMatchGetSize(IntPtr v); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr VectorOfVectorOfDMatchGetStartAddress(IntPtr v); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern long VectorOfVectorOfDMatchGetMemorySize(IntPtr v); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfVectorOfDMatchPush(IntPtr v, IntPtr value); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfVectorOfDMatchPushVector(IntPtr ptr, IntPtr otherPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfVectorOfDMatchClear(IntPtr v); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfVectorOfDMatchGetItemPtr(IntPtr vec, int index, ref IntPtr element); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int VectorOfVectorOfDMatchSizeOfItemInBytes(); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveInputArrayFromVectorOfVectorOfDMatch(IntPtr vec); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveOutputArrayFromVectorOfVectorOfDMatch(IntPtr vec); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveInputOutputArrayFromVectorOfVectorOfDMatch(IntPtr vec); void IDisposable.Dispose() { Dispose(); } } [Serializable] [DebuggerTypeProxy(typeof(DebuggerProxy))] public class VectorOfVectorOfInt : UnmanagedVector, IInputOutputArray, IInputArray, IDisposable, IOutputArray, IInputArrayOfArrays, IOutputArrayOfArrays { internal class DebuggerProxy { private VectorOfVectorOfInt _v; public int[][] Values => _v.ToArrayOfArray(); public DebuggerProxy(VectorOfVectorOfInt v) { _v = v; } } private readonly bool _needDispose; public override int Size => VectorOfVectorOfIntGetSize(_ptr); public override IntPtr StartAddress => VectorOfVectorOfIntGetStartAddress(_ptr); public override long Length => VectorOfVectorOfIntGetMemorySize(_ptr); public VectorOfInt this[int index] { get { IntPtr element = IntPtr.Zero; VectorOfVectorOfIntGetItemPtr(_ptr, index, ref element); return new VectorOfInt(element, needDispose: false); } } public static int SizeOfItemInBytes => VectorOfVectorOfIntSizeOfItemInBytes(); static VectorOfVectorOfInt() { CvInvoke.Init(); } public VectorOfVectorOfInt() : this(VectorOfVectorOfIntCreate(), needDispose: true) { } internal VectorOfVectorOfInt(IntPtr ptr, bool needDispose) { _ptr = ptr; _needDispose = needDispose; } public VectorOfVectorOfInt(int size) : this(VectorOfVectorOfIntCreateSize(size), needDispose: true) { } public VectorOfVectorOfInt(params VectorOfInt[] values) : this() { Push(values); } public void Clear() { VectorOfVectorOfIntClear(_ptr); } public void Push(VectorOfInt value) { VectorOfVectorOfIntPush(_ptr, value.Ptr); } public void Push(VectorOfInt[] values) { foreach (VectorOfInt value in values) { Push(value); } } public void Push(VectorOfVectorOfInt other) { VectorOfVectorOfIntPushVector(_ptr, other); } protected override void DisposeObject() { if (_needDispose && _ptr != IntPtr.Zero) { VectorOfVectorOfIntRelease(ref _ptr); } } public InputArray GetInputArray() { return new InputArray(cveInputArrayFromVectorOfVectorOfInt(_ptr), this); } public OutputArray GetOutputArray() { return new OutputArray(cveOutputArrayFromVectorOfVectorOfInt(_ptr), this); } public InputOutputArray GetInputOutputArray() { return new InputOutputArray(cveInputOutputArrayFromVectorOfVectorOfInt(_ptr), this); } public VectorOfVectorOfInt(int[][] values) : this() { using VectorOfInt vectorOfInt = new VectorOfInt(); for (int i = 0; i < values.Length; i++) { vectorOfInt.Push(values[i]); Push(vectorOfInt); vectorOfInt.Clear(); } } public int[][] ToArrayOfArray() { int size = Size; int[][] array = new int[size][]; for (int i = 0; i < size; i++) { using VectorOfInt vectorOfInt = this[i]; array[i] = vectorOfInt.ToArray(); } return array; } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr VectorOfVectorOfIntCreate(); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr VectorOfVectorOfIntCreateSize(int size); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfVectorOfIntRelease(ref IntPtr v); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int VectorOfVectorOfIntGetSize(IntPtr v); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr VectorOfVectorOfIntGetStartAddress(IntPtr v); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern long VectorOfVectorOfIntGetMemorySize(IntPtr v); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfVectorOfIntPush(IntPtr v, IntPtr value); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfVectorOfIntPushVector(IntPtr ptr, IntPtr otherPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfVectorOfIntClear(IntPtr v); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfVectorOfIntGetItemPtr(IntPtr vec, int index, ref IntPtr element); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int VectorOfVectorOfIntSizeOfItemInBytes(); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveInputArrayFromVectorOfVectorOfInt(IntPtr vec); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveOutputArrayFromVectorOfVectorOfInt(IntPtr vec); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveInputOutputArrayFromVectorOfVectorOfInt(IntPtr vec); void IDisposable.Dispose() { Dispose(); } } [Serializable] [DebuggerTypeProxy(typeof(DebuggerProxy))] public class VectorOfVectorOfMat : UnmanagedVector { internal class DebuggerProxy { private VectorOfVectorOfMat _v; public VectorOfMat[] Values { get { VectorOfMat[] array = new VectorOfMat[_v.Size]; for (int i = 0; i < array.Length; i++) { array[i] = _v[i]; } return array; } } public DebuggerProxy(VectorOfVectorOfMat v) { _v = v; } } private readonly bool _needDispose; public override int Size => VectorOfVectorOfMatGetSize(_ptr); public override IntPtr StartAddress => VectorOfVectorOfMatGetStartAddress(_ptr); public override long Length => VectorOfVectorOfMatGetMemorySize(_ptr); public VectorOfMat this[int index] { get { IntPtr element = IntPtr.Zero; VectorOfVectorOfMatGetItemPtr(_ptr, index, ref element); return new VectorOfMat(element, needDispose: false); } } public static int SizeOfItemInBytes => VectorOfVectorOfMatSizeOfItemInBytes(); static VectorOfVectorOfMat() { CvInvoke.Init(); } public VectorOfVectorOfMat() : this(VectorOfVectorOfMatCreate(), needDispose: true) { } internal VectorOfVectorOfMat(IntPtr ptr, bool needDispose) { _ptr = ptr; _needDispose = needDispose; } public VectorOfVectorOfMat(int size) : this(VectorOfVectorOfMatCreateSize(size), needDispose: true) { } public VectorOfVectorOfMat(params VectorOfMat[] values) : this() { Push(values); } public void Clear() { VectorOfVectorOfMatClear(_ptr); } public void Push(VectorOfMat value) { VectorOfVectorOfMatPush(_ptr, value.Ptr); } public void Push(VectorOfMat[] values) { foreach (VectorOfMat value in values) { Push(value); } } public void Push(VectorOfVectorOfMat other) { VectorOfVectorOfMatPushVector(_ptr, other); } protected override void DisposeObject() { if (_needDispose && _ptr != IntPtr.Zero) { VectorOfVectorOfMatRelease(ref _ptr); } } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr VectorOfVectorOfMatCreate(); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr VectorOfVectorOfMatCreateSize(int size); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfVectorOfMatRelease(ref IntPtr v); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int VectorOfVectorOfMatGetSize(IntPtr v); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr VectorOfVectorOfMatGetStartAddress(IntPtr v); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern long VectorOfVectorOfMatGetMemorySize(IntPtr v); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfVectorOfMatPush(IntPtr v, IntPtr value); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfVectorOfMatPushVector(IntPtr ptr, IntPtr otherPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfVectorOfMatClear(IntPtr v); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfVectorOfMatGetItemPtr(IntPtr vec, int index, ref IntPtr element); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int VectorOfVectorOfMatSizeOfItemInBytes(); } [Serializable] [DebuggerTypeProxy(typeof(DebuggerProxy))] public class VectorOfVectorOfPoint : UnmanagedVector, IInputOutputArray, IInputArray, IDisposable, IOutputArray, IInputArrayOfArrays, IOutputArrayOfArrays { internal class DebuggerProxy { private VectorOfVectorOfPoint _v; public Point[][] Values => _v.ToArrayOfArray(); public DebuggerProxy(VectorOfVectorOfPoint v) { _v = v; } } private readonly bool _needDispose; public override int Size => VectorOfVectorOfPointGetSize(_ptr); public override IntPtr StartAddress => VectorOfVectorOfPointGetStartAddress(_ptr); public override long Length => VectorOfVectorOfPointGetMemorySize(_ptr); public VectorOfPoint this[int index] { get { IntPtr element = IntPtr.Zero; VectorOfVectorOfPointGetItemPtr(_ptr, index, ref element); return new VectorOfPoint(element, needDispose: false); } } public static int SizeOfItemInBytes => VectorOfVectorOfPointSizeOfItemInBytes(); static VectorOfVectorOfPoint() { CvInvoke.Init(); } public VectorOfVectorOfPoint() : this(VectorOfVectorOfPointCreate(), needDispose: true) { } internal VectorOfVectorOfPoint(IntPtr ptr, bool needDispose) { _ptr = ptr; _needDispose = needDispose; } public VectorOfVectorOfPoint(int size) : this(VectorOfVectorOfPointCreateSize(size), needDispose: true) { } public VectorOfVectorOfPoint(params VectorOfPoint[] values) : this() { Push(values); } public void Clear() { VectorOfVectorOfPointClear(_ptr); } public void Push(VectorOfPoint value) { VectorOfVectorOfPointPush(_ptr, value.Ptr); } public void Push(VectorOfPoint[] values) { foreach (VectorOfPoint value in values) { Push(value); } } public void Push(VectorOfVectorOfPoint other) { VectorOfVectorOfPointPushVector(_ptr, other); } protected override void DisposeObject() { if (_needDispose && _ptr != IntPtr.Zero) { VectorOfVectorOfPointRelease(ref _ptr); } } public InputArray GetInputArray() { return new InputArray(cveInputArrayFromVectorOfVectorOfPoint(_ptr), this); } public OutputArray GetOutputArray() { return new OutputArray(cveOutputArrayFromVectorOfVectorOfPoint(_ptr), this); } public InputOutputArray GetInputOutputArray() { return new InputOutputArray(cveInputOutputArrayFromVectorOfVectorOfPoint(_ptr), this); } public VectorOfVectorOfPoint(Point[][] values) : this() { using VectorOfPoint vectorOfPoint = new VectorOfPoint(); for (int i = 0; i < values.Length; i++) { vectorOfPoint.Push(values[i]); Push(vectorOfPoint); vectorOfPoint.Clear(); } } public Point[][] ToArrayOfArray() { int size = Size; Point[][] array = new Point[size][]; for (int i = 0; i < size; i++) { using VectorOfPoint vectorOfPoint = this[i]; array[i] = vectorOfPoint.ToArray(); } return array; } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr VectorOfVectorOfPointCreate(); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr VectorOfVectorOfPointCreateSize(int size); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfVectorOfPointRelease(ref IntPtr v); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int VectorOfVectorOfPointGetSize(IntPtr v); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr VectorOfVectorOfPointGetStartAddress(IntPtr v); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern long VectorOfVectorOfPointGetMemorySize(IntPtr v); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfVectorOfPointPush(IntPtr v, IntPtr value); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfVectorOfPointPushVector(IntPtr ptr, IntPtr otherPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfVectorOfPointClear(IntPtr v); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfVectorOfPointGetItemPtr(IntPtr vec, int index, ref IntPtr element); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int VectorOfVectorOfPointSizeOfItemInBytes(); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveInputArrayFromVectorOfVectorOfPoint(IntPtr vec); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveOutputArrayFromVectorOfVectorOfPoint(IntPtr vec); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveInputOutputArrayFromVectorOfVectorOfPoint(IntPtr vec); void IDisposable.Dispose() { Dispose(); } } [Serializable] [DebuggerTypeProxy(typeof(DebuggerProxy))] public class VectorOfVectorOfPoint3D32F : UnmanagedVector, IInputOutputArray, IInputArray, IDisposable, IOutputArray, IInputArrayOfArrays, IOutputArrayOfArrays { internal class DebuggerProxy { private VectorOfVectorOfPoint3D32F _v; public MCvPoint3D32f[][] Values => _v.ToArrayOfArray(); public DebuggerProxy(VectorOfVectorOfPoint3D32F v) { _v = v; } } private readonly bool _needDispose; public override int Size => VectorOfVectorOfPoint3D32FGetSize(_ptr); public override IntPtr StartAddress => VectorOfVectorOfPoint3D32FGetStartAddress(_ptr); public override long Length => VectorOfVectorOfPoint3D32FGetMemorySize(_ptr); public VectorOfPoint3D32F this[int index] { get { IntPtr element = IntPtr.Zero; VectorOfVectorOfPoint3D32FGetItemPtr(_ptr, index, ref element); return new VectorOfPoint3D32F(element, needDispose: false); } } public static int SizeOfItemInBytes => VectorOfVectorOfPoint3D32FSizeOfItemInBytes(); static VectorOfVectorOfPoint3D32F() { CvInvoke.Init(); } public VectorOfVectorOfPoint3D32F() : this(VectorOfVectorOfPoint3D32FCreate(), needDispose: true) { } internal VectorOfVectorOfPoint3D32F(IntPtr ptr, bool needDispose) { _ptr = ptr; _needDispose = needDispose; } public VectorOfVectorOfPoint3D32F(int size) : this(VectorOfVectorOfPoint3D32FCreateSize(size), needDispose: true) { } public VectorOfVectorOfPoint3D32F(params VectorOfPoint3D32F[] values) : this() { Push(values); } public void Clear() { VectorOfVectorOfPoint3D32FClear(_ptr); } public void Push(VectorOfPoint3D32F value) { VectorOfVectorOfPoint3D32FPush(_ptr, value.Ptr); } public void Push(VectorOfPoint3D32F[] values) { foreach (VectorOfPoint3D32F value in values) { Push(value); } } public void Push(VectorOfVectorOfPoint3D32F other) { VectorOfVectorOfPoint3D32FPushVector(_ptr, other); } protected override void DisposeObject() { if (_needDispose && _ptr != IntPtr.Zero) { VectorOfVectorOfPoint3D32FRelease(ref _ptr); } } public InputArray GetInputArray() { return new InputArray(cveInputArrayFromVectorOfVectorOfPoint3D32F(_ptr), this); } public OutputArray GetOutputArray() { return new OutputArray(cveOutputArrayFromVectorOfVectorOfPoint3D32F(_ptr), this); } public InputOutputArray GetInputOutputArray() { return new InputOutputArray(cveInputOutputArrayFromVectorOfVectorOfPoint3D32F(_ptr), this); } public VectorOfVectorOfPoint3D32F(MCvPoint3D32f[][] values) : this() { using VectorOfPoint3D32F vectorOfPoint3D32F = new VectorOfPoint3D32F(); for (int i = 0; i < values.Length; i++) { vectorOfPoint3D32F.Push(values[i]); Push(vectorOfPoint3D32F); vectorOfPoint3D32F.Clear(); } } public MCvPoint3D32f[][] ToArrayOfArray() { int size = Size; MCvPoint3D32f[][] array = new MCvPoint3D32f[size][]; for (int i = 0; i < size; i++) { using VectorOfPoint3D32F vectorOfPoint3D32F = this[i]; array[i] = vectorOfPoint3D32F.ToArray(); } return array; } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr VectorOfVectorOfPoint3D32FCreate(); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr VectorOfVectorOfPoint3D32FCreateSize(int size); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfVectorOfPoint3D32FRelease(ref IntPtr v); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int VectorOfVectorOfPoint3D32FGetSize(IntPtr v); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr VectorOfVectorOfPoint3D32FGetStartAddress(IntPtr v); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern long VectorOfVectorOfPoint3D32FGetMemorySize(IntPtr v); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfVectorOfPoint3D32FPush(IntPtr v, IntPtr value); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfVectorOfPoint3D32FPushVector(IntPtr ptr, IntPtr otherPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfVectorOfPoint3D32FClear(IntPtr v); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfVectorOfPoint3D32FGetItemPtr(IntPtr vec, int index, ref IntPtr element); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int VectorOfVectorOfPoint3D32FSizeOfItemInBytes(); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveInputArrayFromVectorOfVectorOfPoint3D32F(IntPtr vec); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveOutputArrayFromVectorOfVectorOfPoint3D32F(IntPtr vec); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveInputOutputArrayFromVectorOfVectorOfPoint3D32F(IntPtr vec); void IDisposable.Dispose() { Dispose(); } } [Serializable] [DebuggerTypeProxy(typeof(DebuggerProxy))] public class VectorOfVectorOfPointF : UnmanagedVector, IInputOutputArray, IInputArray, IDisposable, IOutputArray, IInputArrayOfArrays, IOutputArrayOfArrays { internal class DebuggerProxy { private VectorOfVectorOfPointF _v; public PointF[][] Values => _v.ToArrayOfArray(); public DebuggerProxy(VectorOfVectorOfPointF v) { _v = v; } } private readonly bool _needDispose; public override int Size => VectorOfVectorOfPointFGetSize(_ptr); public override IntPtr StartAddress => VectorOfVectorOfPointFGetStartAddress(_ptr); public override long Length => VectorOfVectorOfPointFGetMemorySize(_ptr); public VectorOfPointF this[int index] { get { IntPtr element = IntPtr.Zero; VectorOfVectorOfPointFGetItemPtr(_ptr, index, ref element); return new VectorOfPointF(element, needDispose: false); } } public static int SizeOfItemInBytes => VectorOfVectorOfPointFSizeOfItemInBytes(); static VectorOfVectorOfPointF() { CvInvoke.Init(); } public VectorOfVectorOfPointF() : this(VectorOfVectorOfPointFCreate(), needDispose: true) { } internal VectorOfVectorOfPointF(IntPtr ptr, bool needDispose) { _ptr = ptr; _needDispose = needDispose; } public VectorOfVectorOfPointF(int size) : this(VectorOfVectorOfPointFCreateSize(size), needDispose: true) { } public VectorOfVectorOfPointF(params VectorOfPointF[] values) : this() { Push(values); } public void Clear() { VectorOfVectorOfPointFClear(_ptr); } public void Push(VectorOfPointF value) { VectorOfVectorOfPointFPush(_ptr, value.Ptr); } public void Push(VectorOfPointF[] values) { foreach (VectorOfPointF value in values) { Push(value); } } public void Push(VectorOfVectorOfPointF other) { VectorOfVectorOfPointFPushVector(_ptr, other); } protected override void DisposeObject() { if (_needDispose && _ptr != IntPtr.Zero) { VectorOfVectorOfPointFRelease(ref _ptr); } } public InputArray GetInputArray() { return new InputArray(cveInputArrayFromVectorOfVectorOfPointF(_ptr), this); } public OutputArray GetOutputArray() { return new OutputArray(cveOutputArrayFromVectorOfVectorOfPointF(_ptr), this); } public InputOutputArray GetInputOutputArray() { return new InputOutputArray(cveInputOutputArrayFromVectorOfVectorOfPointF(_ptr), this); } public VectorOfVectorOfPointF(PointF[][] values) : this() { using VectorOfPointF vectorOfPointF = new VectorOfPointF(); for (int i = 0; i < values.Length; i++) { vectorOfPointF.Push(values[i]); Push(vectorOfPointF); vectorOfPointF.Clear(); } } public PointF[][] ToArrayOfArray() { int size = Size; PointF[][] array = new PointF[size][]; for (int i = 0; i < size; i++) { using VectorOfPointF vectorOfPointF = this[i]; array[i] = vectorOfPointF.ToArray(); } return array; } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr VectorOfVectorOfPointFCreate(); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr VectorOfVectorOfPointFCreateSize(int size); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfVectorOfPointFRelease(ref IntPtr v); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int VectorOfVectorOfPointFGetSize(IntPtr v); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr VectorOfVectorOfPointFGetStartAddress(IntPtr v); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern long VectorOfVectorOfPointFGetMemorySize(IntPtr v); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfVectorOfPointFPush(IntPtr v, IntPtr value); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfVectorOfPointFPushVector(IntPtr ptr, IntPtr otherPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfVectorOfPointFClear(IntPtr v); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfVectorOfPointFGetItemPtr(IntPtr vec, int index, ref IntPtr element); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int VectorOfVectorOfPointFSizeOfItemInBytes(); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveInputArrayFromVectorOfVectorOfPointF(IntPtr vec); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveOutputArrayFromVectorOfVectorOfPointF(IntPtr vec); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveInputOutputArrayFromVectorOfVectorOfPointF(IntPtr vec); void IDisposable.Dispose() { Dispose(); } } [Serializable] [DebuggerTypeProxy(typeof(DebuggerProxy))] public class VectorOfVectorOfRect : UnmanagedVector, IInputOutputArray, IInputArray, IDisposable, IOutputArray, IInputArrayOfArrays, IOutputArrayOfArrays { internal class DebuggerProxy { private VectorOfVectorOfRect _v; public Rectangle[][] Values => _v.ToArrayOfArray(); public DebuggerProxy(VectorOfVectorOfRect v) { _v = v; } } private readonly bool _needDispose; public override int Size => VectorOfVectorOfRectGetSize(_ptr); public override IntPtr StartAddress => VectorOfVectorOfRectGetStartAddress(_ptr); public override long Length => VectorOfVectorOfRectGetMemorySize(_ptr); public VectorOfRect this[int index] { get { IntPtr element = IntPtr.Zero; VectorOfVectorOfRectGetItemPtr(_ptr, index, ref element); return new VectorOfRect(element, needDispose: false); } } public static int SizeOfItemInBytes => VectorOfVectorOfRectSizeOfItemInBytes(); static VectorOfVectorOfRect() { CvInvoke.Init(); } public VectorOfVectorOfRect() : this(VectorOfVectorOfRectCreate(), needDispose: true) { } internal VectorOfVectorOfRect(IntPtr ptr, bool needDispose) { _ptr = ptr; _needDispose = needDispose; } public VectorOfVectorOfRect(int size) : this(VectorOfVectorOfRectCreateSize(size), needDispose: true) { } public VectorOfVectorOfRect(params VectorOfRect[] values) : this() { Push(values); } public void Clear() { VectorOfVectorOfRectClear(_ptr); } public void Push(VectorOfRect value) { VectorOfVectorOfRectPush(_ptr, value.Ptr); } public void Push(VectorOfRect[] values) { foreach (VectorOfRect value in values) { Push(value); } } public void Push(VectorOfVectorOfRect other) { VectorOfVectorOfRectPushVector(_ptr, other); } protected override void DisposeObject() { if (_needDispose && _ptr != IntPtr.Zero) { VectorOfVectorOfRectRelease(ref _ptr); } } public InputArray GetInputArray() { return new InputArray(cveInputArrayFromVectorOfVectorOfRect(_ptr), this); } public OutputArray GetOutputArray() { return new OutputArray(cveOutputArrayFromVectorOfVectorOfRect(_ptr), this); } public InputOutputArray GetInputOutputArray() { return new InputOutputArray(cveInputOutputArrayFromVectorOfVectorOfRect(_ptr), this); } public VectorOfVectorOfRect(Rectangle[][] values) : this() { using VectorOfRect vectorOfRect = new VectorOfRect(); for (int i = 0; i < values.Length; i++) { vectorOfRect.Push(values[i]); Push(vectorOfRect); vectorOfRect.Clear(); } } public Rectangle[][] ToArrayOfArray() { int size = Size; Rectangle[][] array = new Rectangle[size][]; for (int i = 0; i < size; i++) { using VectorOfRect vectorOfRect = this[i]; array[i] = vectorOfRect.ToArray(); } return array; } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr VectorOfVectorOfRectCreate(); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr VectorOfVectorOfRectCreateSize(int size); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfVectorOfRectRelease(ref IntPtr v); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int VectorOfVectorOfRectGetSize(IntPtr v); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr VectorOfVectorOfRectGetStartAddress(IntPtr v); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern long VectorOfVectorOfRectGetMemorySize(IntPtr v); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfVectorOfRectPush(IntPtr v, IntPtr value); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfVectorOfRectPushVector(IntPtr ptr, IntPtr otherPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfVectorOfRectClear(IntPtr v); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfVectorOfRectGetItemPtr(IntPtr vec, int index, ref IntPtr element); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int VectorOfVectorOfRectSizeOfItemInBytes(); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveInputArrayFromVectorOfVectorOfRect(IntPtr vec); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveOutputArrayFromVectorOfVectorOfRect(IntPtr vec); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveInputOutputArrayFromVectorOfVectorOfRect(IntPtr vec); void IDisposable.Dispose() { Dispose(); } } [Serializable] [DebuggerTypeProxy(typeof(DebuggerProxy))] public class VectorOfVideoCapture : UnmanagedVector { internal class DebuggerProxy { private VectorOfVideoCapture _v; public VideoCapture[] Values { get { VideoCapture[] array = new VideoCapture[_v.Size]; for (int i = 0; i < array.Length; i++) { array[i] = _v[i]; } return array; } } public DebuggerProxy(VectorOfVideoCapture v) { _v = v; } } private readonly bool _needDispose; public override int Size => VectorOfVideoCaptureGetSize(_ptr); public override IntPtr StartAddress => VectorOfVideoCaptureGetStartAddress(_ptr); public override long Length => VectorOfVideoCaptureGetMemorySize(_ptr); public VideoCapture this[int index] { get { IntPtr element = IntPtr.Zero; VectorOfVideoCaptureGetItemPtr(_ptr, index, ref element); return new VideoCapture(element, needDispose: false); } } public static int SizeOfItemInBytes => VectorOfVideoCaptureSizeOfItemInBytes(); static VectorOfVideoCapture() { CvInvoke.Init(); } public VectorOfVideoCapture() : this(VectorOfVideoCaptureCreate(), needDispose: true) { } internal VectorOfVideoCapture(IntPtr ptr, bool needDispose) { _ptr = ptr; _needDispose = needDispose; } public VectorOfVideoCapture(int size) : this(VectorOfVideoCaptureCreateSize(size), needDispose: true) { } public VectorOfVideoCapture(params VideoCapture[] values) : this() { Push(values); } public void Clear() { VectorOfVideoCaptureClear(_ptr); } public void Push(VideoCapture value) { VectorOfVideoCapturePush(_ptr, value.Ptr); } public void Push(VideoCapture[] values) { foreach (VideoCapture value in values) { Push(value); } } public void Push(VectorOfVideoCapture other) { VectorOfVideoCapturePushVector(_ptr, other); } protected override void DisposeObject() { if (_needDispose && _ptr != IntPtr.Zero) { VectorOfVideoCaptureRelease(ref _ptr); } } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr VectorOfVideoCaptureCreate(); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr VectorOfVideoCaptureCreateSize(int size); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfVideoCaptureRelease(ref IntPtr v); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int VectorOfVideoCaptureGetSize(IntPtr v); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr VectorOfVideoCaptureGetStartAddress(IntPtr v); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern long VectorOfVideoCaptureGetMemorySize(IntPtr v); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfVideoCapturePush(IntPtr v, IntPtr value); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfVideoCapturePushVector(IntPtr ptr, IntPtr otherPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfVideoCaptureClear(IntPtr v); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void VectorOfVideoCaptureGetItemPtr(IntPtr vec, int index, ref IntPtr element); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int VectorOfVideoCaptureSizeOfItemInBytes(); } internal static class ZlibCompression { public static byte[] Compress(byte[] original, int compressionLevel) { byte[] array = new byte[CvInvoke.zlib_compress_bound(original.Length)]; GCHandle gCHandle = GCHandle.Alloc(original, GCHandleType.Pinned); GCHandle gCHandle2 = GCHandle.Alloc(array, GCHandleType.Pinned); int sizeDataCompressed = array.Length; CvInvoke.zlib_compress2(gCHandle2.AddrOfPinnedObject(), ref sizeDataCompressed, gCHandle.AddrOfPinnedObject(), original.Length, compressionLevel); gCHandle.Free(); gCHandle2.Free(); Array.Resize(ref array, sizeDataCompressed); return array; } public static byte[] Uncompress(byte[] compressedData, int estimatedUncompressedSize) { byte[] array = new byte[estimatedUncompressedSize]; GCHandle gCHandle = GCHandle.Alloc(compressedData, GCHandleType.Pinned); GCHandle gCHandle2 = GCHandle.Alloc(array, GCHandleType.Pinned); int sizeDataUncompressed = estimatedUncompressedSize; CvInvoke.zlib_uncompress(gCHandle2.AddrOfPinnedObject(), ref sizeDataUncompressed, gCHandle.AddrOfPinnedObject(), compressedData.Length); gCHandle.Free(); gCHandle2.Free(); if (sizeDataUncompressed != estimatedUncompressedSize) { Array.Resize(ref array, sizeDataUncompressed); } return array; } } } namespace Emgu.CV.Ocl { public class Context : UnmanagedObject { private static Context _defaultContext = new Context(OclInvoke.oclContextGetDefault(), needDispose: false); private bool _needDispose; public static Context Default => _defaultContext; public Context() : this(OclInvoke.oclContextCreate(), needDispose: true) { } internal Context(IntPtr ptr, bool needDispose) { _ptr = ptr; _needDispose = needDispose; } protected override void DisposeObject() { if (_needDispose && _ptr != IntPtr.Zero) { OclInvoke.oclContextRelease(ref _ptr); } } public Program GetProgram(ProgramSource prog, string buildOpt, CvString errMsg) { using CvString cvString = new CvString(buildOpt); return new Program(OclInvoke.oclContextGetProg(_ptr, prog, cvString, errMsg)); } } public static class OclInvoke { [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr oclContextCreate(); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr oclContextGetDefault(); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void oclContextRelease(ref IntPtr oclContext); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr oclContextGetProg(IntPtr context, IntPtr prog, IntPtr buildopt, IntPtr errmsg); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr oclDeviceCreate(); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void oclDeviceSet(IntPtr device, IntPtr p); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr oclDeviceGetDefault(); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void oclDeviceRelease(ref IntPtr oclDevice); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr oclDeviceGetPtr(IntPtr device); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.U1)] internal static extern bool cveDeviceIsNVidia(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.U1)] internal static extern bool cveDeviceIsIntel(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.U1)] internal static extern bool cveDeviceIsAMD(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int cveDeviceAddressBits(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.U1)] internal static extern bool cveDeviceLinkerAvailable(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.U1)] internal static extern bool cveDeviceCompilerAvailable(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.U1)] internal static extern bool cveDeviceAvailable(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int cveDeviceMaxWorkGroupSize(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int cveDeviceMaxComputeUnits(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int cveDeviceLocalMemSize(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int cveDeviceMaxMemAllocSize(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int cveDeviceDeviceVersionMajor(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int cveDeviceDeviceVersionMinor(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern FpConfig cveDeviceHalfFPConfig(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern FpConfig cveDeviceSingleFPConfig(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern FpConfig cveDeviceDoubleFPConfig(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.U1)] internal static extern bool cveDeviceHostUnifiedMemory(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveDeviceGlobalMemSize(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int cveDeviceImage2DMaxWidth(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int cveDeviceImage2DMaxHeight(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern DeviceType cveDeviceType(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveDeviceName(IntPtr obj, IntPtr str); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveDeviceVersion(IntPtr obj, IntPtr str); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveDeviceVendorName(IntPtr obj, IntPtr str); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveDeviceDriverVersion(IntPtr obj, IntPtr str); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveDeviceExtensions(IntPtr obj, IntPtr str); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveDeviceOpenCLVersion(IntPtr obj, IntPtr str); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveDeviceOpenCLCVersion(IntPtr obj, IntPtr str); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr oclImage2DFromUMat(IntPtr src, [MarshalAs(UnmanagedType.U1)] bool norm, [MarshalAs(UnmanagedType.U1)] bool alias); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void oclImage2DRelease(ref IntPtr oclImage2d); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr oclKernelCreateDefault(); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.U1)] internal static extern bool oclKernelCreate(IntPtr kernel, IntPtr kname, IntPtr programSource, IntPtr buildOps, IntPtr errorMsg); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void oclKernelRelease(ref IntPtr oclKernel); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int oclKernelSetImage2D(IntPtr kernel, int i, IntPtr image2D); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int oclKernelSetUMat(IntPtr kernel, int i, IntPtr umat); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl, EntryPoint = "oclKernelSet")] internal static extern int oclKernelSetFloat(IntPtr kernel, int i, ref float value, int size); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl, EntryPoint = "oclKernelSet")] internal static extern int oclKernelSetInt(IntPtr kernel, int i, ref int value, int size); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl, EntryPoint = "oclKernelSet")] internal static extern int oclKernelSetDouble(IntPtr kernel, int i, ref double value, int size); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int oclKernelSet(IntPtr kernel, int i, IntPtr value, int size); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int oclKernelSetKernelArg(IntPtr kernel, int i, IntPtr kernelArg); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.U1)] internal static extern bool oclKernelRun(IntPtr kernel, int dims, IntPtr globalsize, IntPtr localsize, [MarshalAs(UnmanagedType.U1)] bool sync, IntPtr q); public static string TypeToString(DepthType depthType, int channels = 1) { using CvString cvString = new CvString(); oclTypeToString(CvInvoke.MakeType(depthType, channels), cvString); return cvString.ToString(); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void oclTypeToString(int type, IntPtr str); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.U1)] internal static extern bool cveOclKernelEmpty(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveOclKernelNativeKernelPtr(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr oclKernelArgCreate(KernelArg.Flags flags, IntPtr m, int wscale, int iwscale, IntPtr obj, IntPtr sz); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void oclKernelArgRelease(ref IntPtr k); static OclInvoke() { CvInvoke.Init(); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void oclPlatformInfoRelease(ref IntPtr platformInfo); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void oclGetPlatformsInfo(IntPtr platformInfoVec); public static VectorOfOclPlatformInfo GetPlatformsInfo() { VectorOfOclPlatformInfo vectorOfOclPlatformInfo = new VectorOfOclPlatformInfo(); oclGetPlatformsInfo(vectorOfOclPlatformInfo); return vectorOfOclPlatformInfo; } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void oclPlatformInfoGetDevice(IntPtr platformInfo, IntPtr device, int d); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cvePlatformInfoName(IntPtr obj, IntPtr str); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cvePlatformInfoVersion(IntPtr obj, IntPtr str); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cvePlatformInfoVendor(IntPtr obj, IntPtr str); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int cvePlatformInfoDeviceNumber(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr oclProgramCreate(); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void oclProgramRelease(ref IntPtr oclProgram); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void oclProgramGetBinary(IntPtr program, IntPtr binary); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr oclProgramSourceCreate(IntPtr source); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void oclProgramSourceRelease(ref IntPtr oclProgramSource); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr oclProgramSourceGetSource(IntPtr programSource); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr oclQueueCreate(); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr oclQueueFinish(IntPtr queue); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void oclQueueRelease(ref IntPtr queue); } public class Device : UnmanagedObject { private static Device _defaultDevice = new Device(OclInvoke.oclDeviceGetDefault(), needDispose: false); private bool _needDispose; public static Device Default => _defaultDevice; public IntPtr NativeDevicePointer => OclInvoke.oclDeviceGetPtr(_ptr); public bool IsNVidia => OclInvoke.cveDeviceIsNVidia(_ptr); public bool IsIntel => OclInvoke.cveDeviceIsIntel(_ptr); public bool IsAMD => OclInvoke.cveDeviceIsAMD(_ptr); public int AddressBits => OclInvoke.cveDeviceAddressBits(_ptr); public bool LinkerAvailable => OclInvoke.cveDeviceLinkerAvailable(_ptr); public bool CompilerAvailable => OclInvoke.cveDeviceCompilerAvailable(_ptr); public bool Available => OclInvoke.cveDeviceAvailable(_ptr); public int MaxWorkGroupSize => OclInvoke.cveDeviceMaxWorkGroupSize(_ptr); public int MaxComputeUnits => OclInvoke.cveDeviceMaxComputeUnits(_ptr); public int LocalMemSize => OclInvoke.cveDeviceLocalMemSize(_ptr); public int MaxMemAllocSize => OclInvoke.cveDeviceMaxMemAllocSize(_ptr); public int DeviceVersionMajor => OclInvoke.cveDeviceDeviceVersionMajor(_ptr); public int DeviceVersionMinor => OclInvoke.cveDeviceDeviceVersionMinor(_ptr); public FpConfig HalfFPConfig => OclInvoke.cveDeviceHalfFPConfig(_ptr); public FpConfig SingleFPConfig => OclInvoke.cveDeviceSingleFPConfig(_ptr); public FpConfig DoubleFPConfig => OclInvoke.cveDeviceDoubleFPConfig(_ptr); public bool HostUnifiedMemory => OclInvoke.cveDeviceHostUnifiedMemory(_ptr); public IntPtr GlobalMemSize => OclInvoke.cveDeviceGlobalMemSize(_ptr); public int Image2DMaxWidth => OclInvoke.cveDeviceImage2DMaxWidth(_ptr); public int Image2DMaxHeight => OclInvoke.cveDeviceImage2DMaxHeight(_ptr); public DeviceType Type => OclInvoke.cveDeviceType(_ptr); public string Name { get { using CvString cvString = new CvString(); OclInvoke.cveDeviceName(_ptr, cvString); return cvString.ToString(); } } public string Version { get { using CvString cvString = new CvString(); OclInvoke.cveDeviceVersion(_ptr, cvString); return cvString.ToString(); } } public string VendorName { get { using CvString cvString = new CvString(); OclInvoke.cveDeviceVendorName(_ptr, cvString); return cvString.ToString(); } } public string DriverVersion { get { using CvString cvString = new CvString(); OclInvoke.cveDeviceDriverVersion(_ptr, cvString); return cvString.ToString(); } } public string Extensions { get { using CvString cvString = new CvString(); OclInvoke.cveDeviceExtensions(_ptr, cvString); return cvString.ToString(); } } public string OpenCLVersion { get { using CvString cvString = new CvString(); OclInvoke.cveDeviceOpenCLVersion(_ptr, cvString); return cvString.ToString(); } } public string OpenCLCVersion { get { using CvString cvString = new CvString(); OclInvoke.cveDeviceOpenCLCVersion(_ptr, cvString); return cvString.ToString(); } } public Device() : this(OclInvoke.oclDeviceCreate(), needDispose: true) { } internal Device(IntPtr ptr, bool needDispose) { _ptr = ptr; _needDispose = needDispose; } protected override void DisposeObject() { if (_needDispose && _ptr != IntPtr.Zero) { OclInvoke.oclDeviceRelease(ref _ptr); } } public void Set(IntPtr nativeDevicePointer) { OclInvoke.oclDeviceSet(_ptr, nativeDevicePointer); } public override string ToString() { return $"{Name} {DeviceVersionMajor}.{DeviceVersionMinor} ({Type}):Version - {Version}; Global memory - {GlobalMemSize}ï¼› Local memory - {LocalMemSize}; Max image size - {Image2DMaxWidth}x{Image2DMaxHeight}; DoubleFpConfig: {DoubleFPConfig}"; } } public enum DeviceType { Default = 1, Cpu = 2, Gpu = 4, Accelerator = 8, DGpu = 65540, IGpu = 131076, All = -1 } [Flags] public enum FpConfig { Denorm = 1, InfNan = 2, RoundToNearest = 4, RoundToZero = 8, RoundToInf = 0x10, Fma = 0x20, SoftFloat = 0x40, CorrectlyRoundedDivideSqrt = 0x80 } public class Image2D : UnmanagedObject { public Image2D(UMat src, bool norm = false, bool alias = false) { _ptr = OclInvoke.oclImage2DFromUMat(src, norm, alias); } protected override void DisposeObject() { if (_ptr != IntPtr.Zero) { OclInvoke.oclImage2DRelease(ref _ptr); } } } public class Kernel : UnmanagedObject { private static int _sizeOfInt = Toolbox.SizeOf(); private static int _sizeOfFloat = Toolbox.SizeOf(); private static int _sizeOfDouble = Toolbox.SizeOf(); public bool Empty => OclInvoke.cveOclKernelEmpty(_ptr); public IntPtr NativeKernelPtr => OclInvoke.cveOclKernelNativeKernelPtr(_ptr); public Kernel() { _ptr = OclInvoke.oclKernelCreateDefault(); } public bool Create(string kernelName, ProgramSource programSource, string buildOps = null, CvString errMsg = null) { using CvString cvString = new CvString(kernelName); using CvString cvString2 = new CvString(buildOps); return OclInvoke.oclKernelCreate(_ptr, cvString, programSource, cvString2, errMsg); } protected override void DisposeObject() { if (_ptr != IntPtr.Zero) { OclInvoke.oclKernelRelease(ref _ptr); } } public int Set(int i, Image2D image2d) { return OclInvoke.oclKernelSetImage2D(_ptr, i, image2d); } public int Set(int i, UMat umat) { return OclInvoke.oclKernelSetUMat(_ptr, i, umat); } public int Set(int i, ref int value) { return OclInvoke.oclKernelSetInt(_ptr, i, ref value, _sizeOfInt); } public int Set(int i, ref float value) { return OclInvoke.oclKernelSetFloat(_ptr, i, ref value, _sizeOfFloat); } public int Set(int i, ref double value) { return OclInvoke.oclKernelSetDouble(_ptr, i, ref value, _sizeOfDouble); } public int Set(int i, KernelArg kernelArg) { return OclInvoke.oclKernelSetKernelArg(_ptr, i, kernelArg); } public int Set(int i, IntPtr data, int size) { return OclInvoke.oclKernelSet(_ptr, i, data, size); } public bool Run(IntPtr[] globalsize, IntPtr[] localsize, bool sync, Queue q = null) { GCHandle gCHandle = GCHandle.Alloc(globalsize, GCHandleType.Pinned); GCHandle gCHandle2 = ((localsize == null) ? default(GCHandle) : GCHandle.Alloc(localsize, GCHandleType.Pinned)); try { return OclInvoke.oclKernelRun(_ptr, globalsize.Length, gCHandle.AddrOfPinnedObject(), (localsize == null) ? IntPtr.Zero : gCHandle2.AddrOfPinnedObject(), sync, q); } finally { gCHandle.Free(); if (localsize != null) { gCHandle2.Free(); } } } } public class KernelArg : UnmanagedObject { [Flags] public enum Flags { Local = 1, ReadOnly = 2, WriteOnly = 4, ReadWrite = 6, Constant = 8, PtrOnly = 0x10, NoSize = 0x100 } public KernelArg(Flags flags, UMat m, int wscale = 1, int iwscale = 1, IntPtr obj = default(IntPtr), IntPtr sz = default(IntPtr)) { _ptr = OclInvoke.oclKernelArgCreate(flags, m, wscale, iwscale, obj, sz); } protected override void DisposeObject() { if (_ptr != IntPtr.Zero) { OclInvoke.oclKernelArgRelease(ref _ptr); } } } public class PlatformInfo : UnmanagedObject { private bool _needDispose; public string Name { get { using CvString cvString = new CvString(); OclInvoke.cvePlatformInfoName(_ptr, cvString); return cvString.ToString(); } } public string Version { get { using CvString cvString = new CvString(); OclInvoke.cvePlatformInfoVersion(_ptr, cvString); return cvString.ToString(); } } public string Vendor { get { using CvString cvString = new CvString(); OclInvoke.cvePlatformInfoVendor(_ptr, cvString); return cvString.ToString(); } } public int DeviceNumber => OclInvoke.cvePlatformInfoDeviceNumber(_ptr); internal PlatformInfo(IntPtr ptr, bool needDispose) { _ptr = ptr; _needDispose = needDispose; } protected override void DisposeObject() { if (_needDispose) { OclInvoke.oclPlatformInfoRelease(ref _ptr); } } public Device GetDevice(int d) { Device device = new Device(); OclInvoke.oclPlatformInfoGetDevice(base.Ptr, device, d); return device; } public override string ToString() { return Name; } } public class Program : UnmanagedObject { public byte[] Binary { get { if (_ptr == IntPtr.Zero) { return null; } using VectorOfByte vectorOfByte = new VectorOfByte(); OclInvoke.oclProgramGetBinary(_ptr, vectorOfByte); return vectorOfByte.ToArray(); } } public Program() : this(OclInvoke.oclProgramCreate()) { } internal Program(IntPtr ptr) { _ptr = ptr; } protected override void DisposeObject() { if (_ptr != IntPtr.Zero) { OclInvoke.oclProgramRelease(ref _ptr); } } } public class ProgramSource : UnmanagedObject { private CvString _programSource; public string Source { get { using CvString cvString = new CvString(OclInvoke.oclProgramSourceGetSource(_ptr), needDispose: false); return cvString.ToString(); } } public ProgramSource(string source) { _programSource = new CvString(source); _ptr = OclInvoke.oclProgramSourceCreate(_programSource); } protected override void DisposeObject() { OclInvoke.oclProgramSourceRelease(ref _ptr); _programSource.Dispose(); } } public class Queue : UnmanagedObject { public Queue() { _ptr = OclInvoke.oclQueueCreate(); } public void Finish() { OclInvoke.oclQueueFinish(_ptr); } protected override void DisposeObject() { if (_ptr != IntPtr.Zero) { OclInvoke.oclQueueRelease(ref _ptr); } } } } namespace Emgu.CV.Tiff { internal static class TIFFInvoke { [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr tiffWriterOpen([MarshalAs(UnmanagedType.LPStr)] string fileSpec); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void tiffWriterClose(ref IntPtr pTiff); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void tiffWriteGeoTag(IntPtr pTiff, IntPtr modelTiepoint, IntPtr ModelPixelScale); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void tiffWriteImage(IntPtr pTiff, IntPtr image); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void tiffWriteImageInfo(IntPtr pTiff, int bitsPerSample, int samplesPerPixel); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] public static extern void tiffWriteTileInfo(IntPtr pTiff, ref Size tileSize); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] public static extern void tiffWriteTile(IntPtr pTiff, int row, int col, IntPtr tileImage); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] public static extern int tiffTileRowSize(IntPtr pTiff); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] public static extern int tiffTileSize(IntPtr pTiff); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] public static extern void tiffWriteImageSize(IntPtr pTiff, ref Size imageSize); } public class TiffWriter : UnmanagedObject where TColor : struct, IColor where TDepth : new() { static TiffWriter() { CvInvoke.Init(); } public TiffWriter(string fileName) { _ptr = TIFFInvoke.tiffWriterOpen(fileName); TIFFInvoke.tiffWriteImageInfo(_ptr, CvArray.SizeOfElement * 8, new TColor().Dimension); } public virtual void WriteImage(Image image) { if ((typeof(TColor) == typeof(Gray) && typeof(TDepth) == typeof(byte)) || (typeof(TColor) == typeof(Rgb) && typeof(TDepth) == typeof(byte)) || (typeof(TColor) == typeof(Rgba) && typeof(TDepth) == typeof(byte))) { TIFFInvoke.tiffWriteImage(_ptr, image); return; } if (typeof(TColor) == typeof(Bgra) && typeof(TDepth) == typeof(byte)) { using (Image image2 = (image as Image).Convert()) { TIFFInvoke.tiffWriteImage(_ptr, image2); return; } } if (typeof(TColor) == typeof(Bgr) && typeof(TDepth) == typeof(byte)) { using (Image image3 = (image as Image).Convert()) { TIFFInvoke.tiffWriteImage(_ptr, image3); return; } } throw new NotImplementedException("The specific image type is not supported"); } public void WriteGeoTag(double[] modelTiepoint, double[] modelPixelScale) { GCHandle gCHandle = GCHandle.Alloc(modelTiepoint, GCHandleType.Pinned); GCHandle gCHandle2 = GCHandle.Alloc(modelPixelScale, GCHandleType.Pinned); TIFFInvoke.tiffWriteGeoTag(_ptr, gCHandle.AddrOfPinnedObject(), gCHandle2.AddrOfPinnedObject()); gCHandle.Free(); gCHandle2.Free(); } protected override void DisposeObject() { TIFFInvoke.tiffWriterClose(ref _ptr); } } public class TileTiffWriter : TiffWriter where TColor : struct, IColor where TDepth : new() { public int TileSizeInBytes => TIFFInvoke.tiffTileSize(_ptr); public int TileRowSizeInBytes => TIFFInvoke.tiffTileRowSize(_ptr); public Size TileSize => new Size(TileRowSizeInBytes / (CvArray.SizeOfElement * new TColor().Dimension), TileSizeInBytes / TileRowSizeInBytes); public TileTiffWriter(string fileName, Size imageSize, Size tileSize) : base(fileName) { TIFFInvoke.tiffWriteImageSize(_ptr, ref imageSize); TIFFInvoke.tiffWriteTileInfo(_ptr, ref tileSize); } public void WriteTile(int rowNumber, int colNumber, Image tile) { TIFFInvoke.tiffWriteTile(_ptr, rowNumber, colNumber, tile); } public override void WriteImage(Image image) { Rectangle rOI = image.ROI; int sizeOfElement = CvArray.SizeOfElement; int tileRowSizeInBytes = TileRowSizeInBytes; Size tileSize = TileSize; Size size = (rOI.Equals((object?)Rectangle.Empty) ? image.Size : rOI.Size); for (int i = 0; i < image.Height; i += tileSize.Height) { int height = ((tileSize.Height < size.Height - i) ? tileSize.Height : (size.Height - i)); for (int j = 0; j < size.Width; j += tileSize.Width) { int num = ((j + tileSize.Width <= size.Width) ? tileRowSizeInBytes : (size.Width % tileSize.Width * sizeOfElement)); image.ROI = new Rectangle(rOI.Y + j, rOI.X + i, num / sizeOfElement, height); WriteTile(i, j, image); } } image.ROI = rOI; } } } namespace Emgu.CV.Reflection { [AttributeUsage(AttributeTargets.Method)] public sealed class ExposableMethodAttribute : Attribute { private bool _exposable; private string _category; private Type[] _genericParametesOptions; private int[] _genericParametersOptionSizes; public bool Exposable { get { return _exposable; } set { _exposable = value; } } public string Category { get { return _category; } set { _category = value; } } public int[] GenericParametersOptionSizes { get { return _genericParametersOptionSizes; } set { _genericParametersOptionSizes = value; } } public Type[] GenericParametersOptions { get { return _genericParametesOptions; } set { _genericParametesOptions = value; } } public ExposableMethodAttribute() { _category = "Various"; } } public class GenericParameter { private Type _selectedType; private Type[] _availableTypes; public Type SelectedType { get { return _selectedType; } set { _selectedType = value; } } public Type[] AvailableTypes { get { return _availableTypes; } set { _availableTypes = value; } } public GenericParameter(Type selectedType, Type[] availableType) { _selectedType = selectedType; _availableTypes = availableType; } } public static class ReflectColorType { public static Color[] GetDisplayColorOfChannels(IColor color) { List list = new List(); PropertyInfo[] properties = color.GetType().GetProperties(); for (int i = 0; i < properties.Length; i++) { object[] customAttributes = properties[i].GetCustomAttributes(typeof(DisplayColorAttribute), inherit: true); if (customAttributes.Length != 0) { list.Add(((DisplayColorAttribute)customAttributes[0]).DisplayColor); } } if (list.Count > 0) { return list.ToArray(); } Color[] array = new Color[color.Dimension]; for (int j = 0; j < array.Length; j++) { array[j] = Color.Gray; } return array; } public static string[] GetNamesOfChannels(IColor color) { List list = new List(); PropertyInfo[] properties = color.GetType().GetProperties(); foreach (PropertyInfo propertyInfo in properties) { if (propertyInfo.GetCustomAttributes(typeof(DisplayColorAttribute), inherit: true).Length != 0) { list.Add(propertyInfo.Name); } } if (list.Count > 0) { return list.ToArray(); } string[] array = new string[color.Dimension]; for (int j = 0; j < array.Length; j++) { array[j] = $"Channel {j}"; } return array; } } public static class ReflectIImage { public static IEnumerable> GetImageMethods(IInputArray image) { if (image == null) { yield break; } MethodInfo[] methods = image.GetType().GetMethods(); foreach (MethodInfo methodInfo in methods) { object[] customAttributes = methodInfo.GetCustomAttributes(typeof(ExposableMethodAttribute), inherit: false); if (customAttributes.Length != 0) { ExposableMethodAttribute exposableMethodAttribute = (ExposableMethodAttribute)customAttributes[0]; if (exposableMethodAttribute.Exposable) { yield return new KeyValuePair(exposableMethodAttribute.Category, methodInfo); } } } } public static Type GetTypeOfColor(IInputArray image) { Type type = Toolbox.GetBaseType(image.GetType(), "Image`2") ?? Toolbox.GetBaseType(image.GetType(), "CudaImage`2"); if (type != null) { return type.GetGenericArguments()[0]; } using InputArray inputArray = image.GetInputArray(); return inputArray.GetChannels() switch { 4 => typeof(Bgra), 3 => typeof(Bgr), 1 => typeof(Gray), _ => null, }; } public static Type GetTypeOfDepth(IInputArray image) { Type type = Toolbox.GetBaseType(image.GetType(), "Image`2") ?? Toolbox.GetBaseType(image.GetType(), "CudaImage`2"); if (type != null) { return type.GetGenericArguments()[1]; } using InputArray inputArray = image.GetInputArray(); return CvInvoke.GetDepthType(inputArray.GetDepth()); } public static IColor GetPixelColor(IInputArray image, Point location) { using InputArray inputArray = image.GetInputArray(); Size size = inputArray.GetSize(); location.X = Math.Min(location.X, size.Width - 1); location.Y = Math.Min(location.Y, size.Height - 1); MethodInfo method = image.GetType().GetMethod("get_Item", new Type[2] { typeof(int), typeof(int) }); object result; if (!(method == null)) { result = method.Invoke(image, new object[2] { location.Y, location.X }) as IColor; } else { IColor color = default(Bgra); result = color; } return (IColor)result; } } } namespace Emgu.CV.Geodetic { public struct GeodeticCoordinate : IEquatable { private double _latitude; private double _longitude; private double _altitude; public static readonly GeodeticCoordinate Empty; public double Latitude { get { return _latitude; } set { _latitude = value; } } public double Longitude { get { return _longitude; } set { _longitude = value; } } public double Altitude { get { return _altitude; } set { _altitude = value; } } public GeodeticCoordinate(double latitude, double longitude, double altitude) { _latitude = latitude; _longitude = longitude; _altitude = altitude; } public static GeodeticCoordinate operator +(GeodeticCoordinate coor1, GeodeticCoordinate coor2) { return new GeodeticCoordinate(coor1.Latitude + coor2.Latitude, coor1.Longitude + coor2.Longitude, coor1.Altitude + coor2.Altitude); } public static GeodeticCoordinate operator -(GeodeticCoordinate coor1, GeodeticCoordinate coor2) { return new GeodeticCoordinate(coor1.Latitude - coor2.Latitude, coor1.Longitude - coor2.Longitude, coor1.Altitude - coor2.Altitude); } public static GeodeticCoordinate operator *(GeodeticCoordinate coor, double scale) { return new GeodeticCoordinate(coor.Latitude * scale, coor.Longitude * scale, coor.Altitude * scale); } public bool Equals(GeodeticCoordinate other) { if (Latitude.Equals(other.Latitude) && Longitude.Equals(other.Longitude)) { return Altitude.Equals(other.Altitude); } return false; } public static double RadianToDegree(double radian) { return radian * (180.0 / Math.PI); } public static double DegreeToRadian(double degree) { return degree * (Math.PI / 180.0); } } } namespace Emgu.CV.Flann { public enum CenterInitType { Random, Gonzales, Kmeanspp } internal static class FlannInvoke { static FlannInvoke() { CvInvoke.Init(); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveFlannIndexCreate(IntPtr features, IntPtr ip, DistType distType); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveFlannIndexRelease(ref IntPtr index); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveFlannIndexKnnSearch(IntPtr index, IntPtr queries, IntPtr indices, IntPtr dists, int knn, int checks, float eps, [MarshalAs(UnmanagedType.Bool)] bool sorted); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int cveFlannIndexRadiusSearch(IntPtr index, IntPtr queries, IntPtr indices, IntPtr dists, double radius, int maxResults, int checks, float eps, [MarshalAs(UnmanagedType.Bool)] bool sorted); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveLinearIndexParamsCreate(ref IntPtr ip); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveLinearIndexParamsRelease(ref IntPtr p); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveKDTreeIndexParamsCreate(ref IntPtr ip, int trees); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveKDTreeIndexParamsRelease(ref IntPtr p); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveLshIndexParamsCreate(ref IntPtr ip, int tableNumber, int keySize, int multiProbeLevel); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveLshIndexParamsRelease(ref IntPtr p); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveKMeansIndexParamsCreate(ref IntPtr ip, int branching, int iterations, CenterInitType centersInit, float cbIndex); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveKMeansIndexParamsRelease(ref IntPtr p); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveCompositeIndexParamsCreate(ref IntPtr ip, int trees, int branching, int iterations, CenterInitType centersInit, float cbIndex); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveCompositeIndexParamsRelease(ref IntPtr p); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveAutotunedIndexParamsCreate(ref IntPtr ip, float targetPrecision, float buildWeight, float memoryWeight, float sampleFraction); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveAutotunedIndexParamsRelease(ref IntPtr p); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveHierarchicalClusteringIndexParamsCreate(ref IntPtr ip, int branching, CenterInitType centersInit, int trees, int leafSize); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveHierarchicalClusteringIndexParamsRelease(ref IntPtr p); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveSearchParamsCreate(ref IntPtr ip, int checks, float eps, [MarshalAs(UnmanagedType.U1)] bool sorted); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveSearchParamsRelease(ref IntPtr p); } public interface IIndexParams { IntPtr IndexParamPtr { get; } } public enum DistType { Euclidean = 1, L2 = 1, Manhattan = 2, L1 = 2, Minkowski = 3, Max = 4, HistIntersect = 5, Hellinger = 6, ChiSquare = 7, CS = 7, KullbackLeibler = 8, KL = 8, Hamming = 9 } public class Index : UnmanagedObject { public Index(IInputArray values, IIndexParams ip, DistType distType = DistType.Euclidean) { using InputArray inputArray = values.GetInputArray(); _ptr = FlannInvoke.cveFlannIndexCreate(inputArray, ip.IndexParamPtr, distType); } public void KnnSearch(IInputArray queries, IOutputArray indices, IOutputArray squareDistances, int knn, int checks = 32, float eps = 0f, bool sorted = true) { using InputArray inputArray = queries.GetInputArray(); using OutputArray outputArray = indices.GetOutputArray(); using OutputArray outputArray2 = squareDistances.GetOutputArray(); FlannInvoke.cveFlannIndexKnnSearch(_ptr, inputArray, outputArray, outputArray2, knn, checks, eps, sorted); } public int RadiusSearch(IInputArray queries, IOutputArray indices, IOutputArray squareDistances, double radius, int maxResults, int checks = 32, float eps = 0f, bool sorted = true) { using InputArray inputArray = queries.GetInputArray(); using OutputArray outputArray = indices.GetOutputArray(); using OutputArray outputArray2 = squareDistances.GetOutputArray(); return FlannInvoke.cveFlannIndexRadiusSearch(_ptr, inputArray, outputArray, outputArray2, radius, maxResults, checks, eps, sorted); } protected override void DisposeObject() { if (_ptr != IntPtr.Zero) { FlannInvoke.cveFlannIndexRelease(ref _ptr); } } } public class Index3D : UnmanagedObject { public struct Neighbor { public int Index; public float SquareDist; } private MCvPoint3D32f[] _points; private Index _flannIndex; private Matrix _dataMatrix; private Matrix _query; private Matrix _distance; private Matrix _index; private GCHandle _dataHandle; public Index3D(MCvPoint3D32f[] points, IIndexParams ip) { _points = points; _dataHandle = GCHandle.Alloc(_points, GCHandleType.Pinned); _dataMatrix = new Matrix(_points.Length, 3, _dataHandle.AddrOfPinnedObject()); _flannIndex = new Index(_dataMatrix, ip); _query = new Matrix(1, 3); _distance = new Matrix(1, 1); _index = new Matrix(1, 1); } public Neighbor NearestNeighbor(MCvPoint3D32f position) { _query.Data[0, 0] = position.X; _query.Data[0, 1] = position.Y; _query.Data[0, 2] = position.Z; _flannIndex.KnnSearch(_query, _index, _distance, 1, 1); Neighbor result = default(Neighbor); result.Index = _index.Data[0, 0]; result.SquareDist = _distance.Data[0, 0]; return result; } public Neighbor[] RadiusSearch(MCvPoint3D32f position, double radius, int maxResults) { _query.Data[0, 0] = position.X; _query.Data[0, 1] = position.Y; _query.Data[0, 2] = position.Z; using Mat mat = new Mat(new Size(maxResults, 1), DepthType.Cv32S, 1); using Mat mat2 = new Mat(new Size(maxResults, 1), DepthType.Cv32F, 1); mat.SetTo(new MCvScalar(-1.0)); mat2.SetTo(new MCvScalar(-1.0)); _flannIndex.RadiusSearch(_query, mat, mat2, radius, maxResults); int[] array = new int[mat.Rows * mat.Cols]; mat.CopyTo(array); float[] array2 = new float[mat2.Rows * mat2.Cols]; mat2.CopyTo(array2); List list = new List(); for (int i = 0; i < maxResults && array[i] > 0; i++) { Neighbor item = default(Neighbor); item.Index = array[i]; item.SquareDist = array2[i]; list.Add(item); } return list.ToArray(); } protected override void DisposeObject() { _index.Dispose(); _dataHandle.Free(); _dataMatrix.Dispose(); _query.Dispose(); _distance.Dispose(); } } public class LinearIndexParams : UnmanagedObject, IIndexParams { private IntPtr _indexParamPtr; IntPtr IIndexParams.IndexParamPtr => _indexParamPtr; public LinearIndexParams() { _ptr = FlannInvoke.cveLinearIndexParamsCreate(ref _indexParamPtr); } protected override void DisposeObject() { if (IntPtr.Zero != _ptr) { FlannInvoke.cveLinearIndexParamsRelease(ref _ptr); _indexParamPtr = IntPtr.Zero; } } } public class KdTreeIndexParams : UnmanagedObject, IIndexParams { private IntPtr _indexParamPtr; IntPtr IIndexParams.IndexParamPtr => _indexParamPtr; public KdTreeIndexParams(int trees = 4) { _ptr = FlannInvoke.cveKDTreeIndexParamsCreate(ref _indexParamPtr, trees); } protected override void DisposeObject() { if (IntPtr.Zero != _ptr) { FlannInvoke.cveKDTreeIndexParamsRelease(ref _ptr); _indexParamPtr = IntPtr.Zero; } } } public class LshIndexParams : UnmanagedObject, IIndexParams { private IntPtr _indexParamPtr; IntPtr IIndexParams.IndexParamPtr => _indexParamPtr; public LshIndexParams(int tableNumber, int keySize, int multiProbeLevel) { _ptr = FlannInvoke.cveLshIndexParamsCreate(ref _indexParamPtr, tableNumber, keySize, multiProbeLevel); } protected override void DisposeObject() { if (IntPtr.Zero != _ptr) { FlannInvoke.cveLshIndexParamsRelease(ref _ptr); _indexParamPtr = IntPtr.Zero; } } } public class KMeansIndexParams : UnmanagedObject, IIndexParams { private IntPtr _indexParamPtr; IntPtr IIndexParams.IndexParamPtr => _indexParamPtr; public KMeansIndexParams(int branching = 32, int iterations = 11, CenterInitType centersInit = CenterInitType.Random, float cbIndex = 0.2f) { _ptr = FlannInvoke.cveKMeansIndexParamsCreate(ref _indexParamPtr, branching, iterations, centersInit, cbIndex); } protected override void DisposeObject() { if (IntPtr.Zero != _ptr) { FlannInvoke.cveKMeansIndexParamsRelease(ref _ptr); _indexParamPtr = IntPtr.Zero; } } } public class CompositeIndexParams : UnmanagedObject, IIndexParams { private IntPtr _indexParamPtr; IntPtr IIndexParams.IndexParamPtr => _indexParamPtr; public CompositeIndexParams(int trees = 4, int branching = 32, int iterations = 11, CenterInitType centersInit = CenterInitType.Random, float cbIndex = 0.2f) { _ptr = FlannInvoke.cveCompositeIndexParamsCreate(ref _indexParamPtr, trees, branching, iterations, centersInit, cbIndex); } protected override void DisposeObject() { if (IntPtr.Zero != _ptr) { FlannInvoke.cveCompositeIndexParamsRelease(ref _ptr); _indexParamPtr = IntPtr.Zero; } } } public class AutotunedIndexParams : UnmanagedObject, IIndexParams { private IntPtr _indexParamPtr; IntPtr IIndexParams.IndexParamPtr => _indexParamPtr; public AutotunedIndexParams(float targetPrecision = 0.8f, float buildWeight = 0.01f, float memoryWeight = 0f, float sampleFraction = 0.1f) { _ptr = FlannInvoke.cveAutotunedIndexParamsCreate(ref _indexParamPtr, targetPrecision, buildWeight, memoryWeight, sampleFraction); } protected override void DisposeObject() { if (IntPtr.Zero != _ptr) { FlannInvoke.cveAutotunedIndexParamsRelease(ref _ptr); _indexParamPtr = IntPtr.Zero; } } } public class HierarchicalClusteringIndexParams : UnmanagedObject, IIndexParams { private IntPtr _indexParamPtr; IntPtr IIndexParams.IndexParamPtr => _indexParamPtr; public HierarchicalClusteringIndexParams(int branching = 32, CenterInitType centersInit = CenterInitType.Random, int trees = 4, int leafSize = 100) { _ptr = FlannInvoke.cveHierarchicalClusteringIndexParamsCreate(ref _indexParamPtr, branching, centersInit, trees, leafSize); } protected override void DisposeObject() { if (IntPtr.Zero != _ptr) { FlannInvoke.cveHierarchicalClusteringIndexParamsRelease(ref _ptr); _indexParamPtr = IntPtr.Zero; } } } public class SearchParams : UnmanagedObject, IIndexParams { private IntPtr _indexParamPtr; IntPtr IIndexParams.IndexParamPtr => _indexParamPtr; public SearchParams(int checks = 32, float eps = 0f, bool sorted = true) { _ptr = FlannInvoke.cveSearchParamsCreate(ref _indexParamPtr, checks, eps, sorted); } protected override void DisposeObject() { if (IntPtr.Zero != _ptr) { FlannInvoke.cveSearchParamsRelease(ref _ptr); _indexParamPtr = IntPtr.Zero; } } } } namespace Emgu.CV.Features2D { public class AgastFeatureDetector : Feature2D { public enum Type { AGAST_5_8, AGAST_7_12d, AGAST_7_12s, OAST_9_16 } public AgastFeatureDetector(int threshold = 10, bool nonmaxSuppression = true, Type type = Type.OAST_9_16) { _ptr = Features2DInvoke.cveAgastFeatureDetectorCreate(threshold, nonmaxSuppression, type, ref _feature2D, ref _sharedPtr); } protected override void DisposeObject() { if (_sharedPtr != IntPtr.Zero) { Features2DInvoke.cveAgastFeatureDetectorRelease(ref _sharedPtr); } base.DisposeObject(); } } public static class Features2DInvoke { [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveAgastFeatureDetectorCreate(int threshold, [MarshalAs(UnmanagedType.U1)] bool nonmaxSuppression, AgastFeatureDetector.Type type, ref IntPtr feature2D, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveAgastFeatureDetectorRelease(ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveAKAZEDetectorCreate(AKAZE.DescriptorType descriptorType, int descriptorSize, int descriptorChannels, float threshold, int octaves, int nOctaveLayers, KAZE.Diffusivity diffusivity, ref IntPtr feature2D, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveAKAZEDetectorRelease(ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveBFMatcherCreate(DistanceType distanceType, [MarshalAs(UnmanagedType.U1)] bool crossCheck, ref IntPtr dmPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveBFMatcherRelease(ref IntPtr matcher); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveBOWImgDescriptorExtractorCreate(IntPtr descriptorExtractor, IntPtr descriptorMatcher); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveBOWImgDescriptorExtractorRelease(ref IntPtr descriptorExtractor); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveBOWImgDescriptorExtractorCompute(IntPtr bowImgDescriptorExtractor, IntPtr image, IntPtr keypoints, IntPtr imgDescriptor); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveBOWImgDescriptorExtractorSetVocabulary(IntPtr bowImgDescriptorExtractor, IntPtr vocabulary); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveBOWKMeansTrainerCreate(int clusterCount, ref MCvTermCriteria termcrit, int attempts, KMeansInitType flags); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveBOWKMeansTrainerRelease(ref IntPtr trainer); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int cveBOWKMeansTrainerGetDescriptorCount(IntPtr trainer); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveBOWKMeansTrainerAdd(IntPtr trainer, IntPtr descriptors); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveBOWKMeansTrainerCluster(IntPtr trainer, IntPtr cluster); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveBriskCreate(int thresh, int octaves, float patternScale, ref IntPtr feature2D, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveBriskRelease(ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveDescriptorMatcherAdd(IntPtr matcher, IntPtr trainDescriptor); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveDescriptorMatcherKnnMatch1(IntPtr matcher, IntPtr queryDescriptors, IntPtr trainDescriptors, IntPtr matches, int k, IntPtr mask, [MarshalAs(UnmanagedType.U1)] bool compactResult); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveDescriptorMatcherKnnMatch2(IntPtr matcher, IntPtr queryDescriptors, IntPtr matches, int k, IntPtr mask, [MarshalAs(UnmanagedType.U1)] bool compactResult); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveDescriptorMatcherGetAlgorithm(IntPtr matcher); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveDescriptorMatcherClear(IntPtr matcher); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.U1)] internal static extern bool cveDescriptorMatcherEmpty(IntPtr matcher); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.U1)] internal static extern bool cveDescriptorMatcherIsMaskSupported(IntPtr matcher); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveDescriptorMatcherTrain(IntPtr matcher); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveDescriptorMatcherMatch1(IntPtr matcher, IntPtr queryDescriptors, IntPtr trainDescriptors, IntPtr matches, IntPtr mask); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveDescriptorMatcherMatch2(IntPtr matcher, IntPtr queryDescriptors, IntPtr matches, IntPtr masks); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveDescriptorMatcherRadiusMatch1(IntPtr matcher, IntPtr queryDescriptors, IntPtr trainDescriptors, IntPtr matches, float maxDistance, IntPtr mask, [MarshalAs(UnmanagedType.U1)] bool compactResult); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveDescriptorMatcherRadiusMatch2(IntPtr matcher, IntPtr queryDescriptors, IntPtr matches, float maxDistance, IntPtr masks, [MarshalAs(UnmanagedType.U1)] bool compactResult); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveFASTFeatureDetectorCreate(int threshold, [MarshalAs(UnmanagedType.U1)] bool nonmaxSupression, FastFeatureDetector.DetectorType type, ref IntPtr feature2D, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveFASTFeatureDetectorRelease(ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr CvFeature2DGetAlgorithm(IntPtr detector); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void CvFeature2DDetectAndCompute(IntPtr feature2D, IntPtr image, IntPtr mask, IntPtr keypoints, IntPtr descriptors, [MarshalAs(UnmanagedType.U1)] bool useProvidedKeyPoints); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void CvFeature2DDetect(IntPtr detector, IntPtr image, IntPtr keypoints, IntPtr mask); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void CvFeature2DCompute(IntPtr extractor, IntPtr image, IntPtr keypoints, IntPtr descriptors); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int CvFeature2DGetDescriptorSize(IntPtr extractor); static Features2DInvoke() { CvInvoke.Init(); } [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.U1)] internal static extern bool getHomographyMatrixFromMatchedFeatures(IntPtr model, IntPtr observed, IntPtr indices, IntPtr mask, double ransacReprojThreshold, IntPtr homography); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int voteForSizeAndOrientation(IntPtr modelKeyPoints, IntPtr observedKeyPoints, IntPtr indices, IntPtr mask, double scaleIncrement, int rotationBins); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void drawMatchedFeatures1(IntPtr img1, IntPtr keypoints1, IntPtr img2, IntPtr keypoints2, IntPtr matchIndices, IntPtr outImg, ref MCvScalar matchColor, ref MCvScalar singlePointColor, IntPtr matchesMask, Features2DToolbox.KeypointDrawType flags); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void drawMatchedFeatures2(IntPtr img1, IntPtr keypoints1, IntPtr img2, IntPtr keypoints2, IntPtr matchIndices, IntPtr outImg, ref MCvScalar matchColor, ref MCvScalar singlePointColor, IntPtr matchesMask, Features2DToolbox.KeypointDrawType flags); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void drawMatchedFeatures3(IntPtr img1, IntPtr keypoints1, IntPtr img2, IntPtr keypoints2, IntPtr matchIndices, IntPtr outImg, ref MCvScalar matchColor, ref MCvScalar singlePointColor, IntPtr matchesMask, Features2DToolbox.KeypointDrawType flags); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void drawKeypoints(IntPtr image, IntPtr vectorOfKeypoints, IntPtr outImage, ref MCvScalar color, Features2DToolbox.KeypointDrawType flags); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveFlannBasedMatcherCreate(IntPtr ip, IntPtr sp, ref IntPtr dmPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveFlannBasedMatcherRelease(ref IntPtr matcher); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveGFTTDetectorCreate(int maxCorners, double qualityLevel, double minDistance, int blockSize, [MarshalAs(UnmanagedType.U1)] bool useHarrisDetector, double k, ref IntPtr feature2DPtr, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveGFTTDetectorRelease(ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveKAZEDetectorCreate([MarshalAs(UnmanagedType.U1)] bool extended, [MarshalAs(UnmanagedType.U1)] bool upright, float threshold, int octaves, int sublevels, KAZE.Diffusivity diffusivity, ref IntPtr feature2D, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveKAZEDetectorRelease(ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveMserCreate(int delta, int minArea, int maxArea, double maxVariation, double minDiversity, int maxEvolution, double areaThreshold, double minMargin, int edgeBlurSize, ref IntPtr feature2D, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveMserRelease(ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveMserDetectRegions(IntPtr mser, IntPtr image, IntPtr msers, IntPtr bboxes); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.U1)] internal static extern bool cveMSERGetPass2Only(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveMSERSetPass2Only(IntPtr obj, [MarshalAs(UnmanagedType.U1)] bool val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int cveMSERGetDelta(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveMSERSetDelta(IntPtr obj, int val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int cveMSERGetMinArea(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveMSERSetMinArea(IntPtr obj, int val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern int cveMSERGetMaxArea(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveMSERSetMaxArea(IntPtr obj, int val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveOrbCreate(int numberOfFeatures, float scaleFactor, int nLevels, int edgeThreshold, int firstLevel, int WTK_A, ORB.ScoreType scoreType, int patchSize, int fastThreshold, ref IntPtr feature2D, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveOrbRelease(ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveSIFTCreate(int nFeatures, int nOctaveLayers, double contrastThreshold, double edgeThreshold, double sigma, ref IntPtr feature2D, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveSIFTRelease(ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveSimpleBlobDetectorCreate(ref IntPtr feature2DPtr, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveSimpleBlobDetectorCreateWithParams(ref IntPtr feature2DPtr, IntPtr parameters, ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveSimpleBlobDetectorRelease(ref IntPtr sharedPtr); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveSimpleBlobDetectorParamsCreate(); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveSimpleBlobDetectorParamsRelease(ref IntPtr parameters); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern float cveSimpleBlobDetectorParamsGetThresholdStep(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveSimpleBlobDetectorParamsSetThresholdStep(IntPtr obj, float val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern float cveSimpleBlobDetectorParamsGetMinThreshold(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveSimpleBlobDetectorParamsSetMinThreshold(IntPtr obj, float val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern float cveSimpleBlobDetectorParamsGetMaxThreshold(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveSimpleBlobDetectorParamsSetMaxThreshold(IntPtr obj, float val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern float cveSimpleBlobDetectorParamsGetMinDistBetweenBlobs(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveSimpleBlobDetectorParamsSetMinDistBetweenBlobs(IntPtr obj, float val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.U1)] internal static extern bool cveSimpleBlobDetectorParamsGetFilterByColor(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveSimpleBlobDetectorParamsSetFilterByColor(IntPtr obj, [MarshalAs(UnmanagedType.U1)] bool val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern byte cveSimpleBlobDetectorParamsGetblobColor(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveSimpleBlobDetectorParamsSetblobColor(IntPtr obj, byte val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.U1)] internal static extern bool cveSimpleBlobDetectorParamsGetFilterByArea(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveSimpleBlobDetectorParamsSetFilterByArea(IntPtr obj, [MarshalAs(UnmanagedType.U1)] bool val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern float cveSimpleBlobDetectorParamsGetMinArea(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveSimpleBlobDetectorParamsSetMinArea(IntPtr obj, float val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern float cveSimpleBlobDetectorParamsGetMaxArea(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveSimpleBlobDetectorParamsSetMaxArea(IntPtr obj, float val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.U1)] internal static extern bool cveSimpleBlobDetectorParamsGetFilterByCircularity(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveSimpleBlobDetectorParamsSetFilterByCircularity(IntPtr obj, [MarshalAs(UnmanagedType.U1)] bool val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern float cveSimpleBlobDetectorParamsGetMinCircularity(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveSimpleBlobDetectorParamsSetMinCircularity(IntPtr obj, float val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern float cveSimpleBlobDetectorParamsGetMaxCircularity(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveSimpleBlobDetectorParamsSetMaxCircularity(IntPtr obj, float val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.U1)] internal static extern bool cveSimpleBlobDetectorParamsGetFilterByInertia(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveSimpleBlobDetectorParamsSetFilterByInertia(IntPtr obj, [MarshalAs(UnmanagedType.U1)] bool val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern float cveSimpleBlobDetectorParamsGetMinInertiaRatio(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveSimpleBlobDetectorParamsSetMinInertiaRatio(IntPtr obj, float val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern float cveSimpleBlobDetectorParamsGetMaxInertiaRatio(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveSimpleBlobDetectorParamsSetMaxInertiaRatio(IntPtr obj, float val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.U1)] internal static extern bool cveSimpleBlobDetectorParamsGetFilterByConvexity(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveSimpleBlobDetectorParamsSetFilterByConvexity(IntPtr obj, [MarshalAs(UnmanagedType.U1)] bool val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern float cveSimpleBlobDetectorParamsGetMinConvexity(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveSimpleBlobDetectorParamsSetMinConvexity(IntPtr obj, float val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern float cveSimpleBlobDetectorParamsGetMaxConvexity(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveSimpleBlobDetectorParamsSetMaxConvexity(IntPtr obj, float val); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr cveSimpleBlobDetectorParamsGetMinRepeatability(IntPtr obj); [DllImport("cvextern", CallingConvention = CallingConvention.Cdecl)] internal static extern void cveSimpleBlobDetectorParamsSetMinRepeatability(IntPtr obj, IntPtr val); } public class AKAZE : Feature2D { public enum DescriptorType { KazeUpright = 2, Kaze, MldbUpright, Mldb } public AKAZE(DescriptorType descriptorType = DescriptorType.Mldb, int descriptorSize = 0, int descriptorChannels = 3, float threshold = 0.001f, int nOctaves = 4, int nOctaveLayers = 4, KAZE.Diffusivity diffusivity = KAZE.Diffusivity.PmG2) { _ptr = Features2DInvoke.cveAKAZEDetectorCreate(descriptorType, descriptorSize, descriptorChannels, threshold, nOctaves, nOctaveLayers, diffusivity, ref _feature2D, ref _sharedPtr); } protected override void DisposeObject() { if (_sharedPtr != IntPtr.Zero) { Features2DInvoke.cveAKAZEDetectorRelease(ref _sharedPtr); } base.DisposeObject(); } } [Flags] public enum DistanceType { Inf = 1, L1 = 2, L2 = 4, L2Sqr = 5, Hamming = 6, Hamming2 = 7, TypeMask = 7, Relative = 8, MinMax = 0x20 } public class BFMatcher : DescriptorMatcher { public BFMatcher(DistanceType distanceType, bool crossCheck = false) { _ptr = Features2DInvoke.cveBFMatcherCreate(distanceType, crossCheck, ref _descriptorMatcherPtr); } protected override void DisposeObject() { if (IntPtr.Zero != _ptr) { Features2DInvoke.cveBFMatcherRelease(ref _ptr); } base.DisposeObject(); } } public class BOWImgDescriptorExtractor : UnmanagedObject { public BOWImgDescriptorExtractor(Feature2D descriptorExtractor, DescriptorMatcher descriptorMatcher) { _ptr = Features2DInvoke.cveBOWImgDescriptorExtractorCreate(descriptorExtractor.Feature2DPtr, descriptorMatcher); } public void SetVocabulary(Mat vocabulary) { Features2DInvoke.cveBOWImgDescriptorExtractorSetVocabulary(_ptr, vocabulary); } public void Compute(IInputArray image, VectorOfKeyPoint keypoints, Mat imgDescriptors) { using InputArray inputArray = image.GetInputArray(); Features2DInvoke.cveBOWImgDescriptorExtractorCompute(_ptr, inputArray, keypoints, imgDescriptors); } protected override void DisposeObject() { if (IntPtr.Zero != _ptr) { Features2DInvoke.cveBOWImgDescriptorExtractorRelease(ref _ptr); } } } public class BOWKMeansTrainer : UnmanagedObject { public int DescriptorCount => Features2DInvoke.cveBOWKMeansTrainerGetDescriptorCount(_ptr); public BOWKMeansTrainer(int clusterCount, MCvTermCriteria termcrit, int attempts = 3, KMeansInitType flags = KMeansInitType.PPCenters) { _ptr = Features2DInvoke.cveBOWKMeansTrainerCreate(clusterCount, ref termcrit, attempts, flags); } public void Add(Mat descriptors) { Features2DInvoke.cveBOWKMeansTrainerAdd(_ptr, descriptors); } public void Cluster(IOutputArray cluster) { using OutputArray outputArray = cluster.GetOutputArray(); Features2DInvoke.cveBOWKMeansTrainerCluster(_ptr, outputArray); } protected override void DisposeObject() { if (_ptr != IntPtr.Zero) { Features2DInvoke.cveBOWKMeansTrainerRelease(ref _ptr); } } } public class Brisk : Feature2D { public Brisk(int thresh = 30, int octaves = 3, float patternScale = 1f) { _ptr = Features2DInvoke.cveBriskCreate(thresh, octaves, patternScale, ref _feature2D, ref _sharedPtr); } protected override void DisposeObject() { if (_sharedPtr != IntPtr.Zero) { Features2DInvoke.cveBriskRelease(ref _sharedPtr); } base.DisposeObject(); } } public abstract class DescriptorMatcher : UnmanagedObject, IAlgorithm { protected IntPtr _descriptorMatcherPtr; IntPtr IAlgorithm.AlgorithmPtr => Features2DInvoke.cveDescriptorMatcherGetAlgorithm(_ptr); public bool Empty => Features2DInvoke.cveDescriptorMatcherEmpty(_descriptorMatcherPtr); public bool IsMaskSupported => Features2DInvoke.cveDescriptorMatcherIsMaskSupported(_descriptorMatcherPtr); public void KnnMatch(IInputArray queryDescriptors, IInputArray trainDescriptors, VectorOfVectorOfDMatch matches, int k, IInputArray mask = null, bool compactResult = false) { using InputArray inputArray = queryDescriptors.GetInputArray(); using InputArray inputArray2 = trainDescriptors.GetInputArray(); using InputArray inputArray3 = ((mask == null) ? InputArray.GetEmpty() : mask.GetInputArray()); Features2DInvoke.cveDescriptorMatcherKnnMatch1(_descriptorMatcherPtr, inputArray, inputArray2, matches, k, inputArray3, compactResult); } public void KnnMatch(IInputArray queryDescriptor, VectorOfVectorOfDMatch matches, int k, IInputArray mask = null, bool compactResult = false) { using InputArray inputArray = queryDescriptor.GetInputArray(); using InputArray inputArray2 = ((mask == null) ? InputArray.GetEmpty() : mask.GetInputArray()); Features2DInvoke.cveDescriptorMatcherKnnMatch2(_descriptorMatcherPtr, inputArray, matches, k, inputArray2, compactResult); } public void Add(IInputArray modelDescriptors) { using InputArray inputArray = modelDescriptors.GetInputArray(); Features2DInvoke.cveDescriptorMatcherAdd(_descriptorMatcherPtr, inputArray); } protected override void DisposeObject() { _descriptorMatcherPtr = IntPtr.Zero; } public void Clear() { Features2DInvoke.cveDescriptorMatcherClear(_descriptorMatcherPtr); } public void Train() { Features2DInvoke.cveDescriptorMatcherTrain(_descriptorMatcherPtr); } public void Match(IInputArray queryDescriptors, IInputArray trainDescriptors, VectorOfDMatch matches, IInputArray mask = null) { using InputArray inputArray = queryDescriptors.GetInputArray(); using InputArray inputArray2 = trainDescriptors.GetInputArray(); using InputArray inputArray3 = ((mask == null) ? InputArray.GetEmpty() : mask.GetInputArray()); Features2DInvoke.cveDescriptorMatcherMatch1(_descriptorMatcherPtr, inputArray, inputArray2, matches, inputArray3); } public void Match(IInputArray queryDescriptors, VectorOfDMatch matches, IInputArrayOfArrays masks = null) { using InputArray inputArray = queryDescriptors.GetInputArray(); using InputArray inputArray2 = ((masks == null) ? InputArray.GetEmpty() : masks.GetInputArray()); Features2DInvoke.cveDescriptorMatcherMatch2(_descriptorMatcherPtr, inputArray, matches, inputArray2); } public void RadiusMatch(IInputArray queryDescriptors, IInputArray trainDescriptors, VectorOfVectorOfDMatch matches, float maxDistance, IInputArrayOfArrays mask = null, bool compactResult = false) { using InputArray inputArray = queryDescriptors.GetInputArray(); using InputArray inputArray2 = trainDescriptors.GetInputArray(); using InputArray inputArray3 = ((mask == null) ? InputArray.GetEmpty() : mask.GetInputArray()); Features2DInvoke.cveDescriptorMatcherRadiusMatch1(_descriptorMatcherPtr, inputArray, inputArray2, matches, maxDistance, inputArray3, compactResult); } public void RadiusMatch(IInputArray queryDescriptors, VectorOfVectorOfDMatch matches, float maxDistance, IInputArray masks = null, bool compactResult = false) { using InputArray inputArray = queryDescriptors.GetInputArray(); using InputArray inputArray2 = ((masks == null) ? InputArray.GetEmpty() : masks.GetInputArray()); Features2DInvoke.cveDescriptorMatcherRadiusMatch2(_descriptorMatcherPtr, inputArray, matches, maxDistance, inputArray2, compactResult); } } public class FastFeatureDetector : Feature2D { public enum DetectorType { Type5_8, Type7_12, Type9_16 } public FastFeatureDetector(int threshold = 10, bool nonmaxSupression = true, DetectorType type = DetectorType.Type9_16) { _ptr = Features2DInvoke.cveFASTFeatureDetectorCreate(threshold, nonmaxSupression, type, ref _feature2D, ref _sharedPtr); } protected override void DisposeObject() { if (_sharedPtr != IntPtr.Zero) { Features2DInvoke.cveFASTFeatureDetectorRelease(ref _sharedPtr); } base.DisposeObject(); } } public abstract class Feature2D : SharedPtrObject, IAlgorithm { protected IntPtr _feature2D; public IntPtr Feature2DPtr => _feature2D; IntPtr IAlgorithm.AlgorithmPtr { get { if (_feature2D == IntPtr.Zero) { return IntPtr.Zero; } return Features2DInvoke.CvFeature2DGetAlgorithm(_feature2D); } } public int DescriptorSize { get { if (_feature2D == IntPtr.Zero) { return 0; } return Features2DInvoke.CvFeature2DGetDescriptorSize(_feature2D); } } public void DetectAndCompute(IInputArray image, IInputArray mask, VectorOfKeyPoint keyPoints, IOutputArray descriptors, bool useProvidedKeyPoints) { using InputArray inputArray = image.GetInputArray(); using InputArray inputArray2 = ((mask == null) ? InputArray.GetEmpty() : mask.GetInputArray()); using OutputArray outputArray = descriptors.GetOutputArray(); Features2DInvoke.CvFeature2DDetectAndCompute(_ptr, inputArray, inputArray2, keyPoints, outputArray, useProvidedKeyPoints); } protected override void DisposeObject() { _ptr = IntPtr.Zero; _feature2D = IntPtr.Zero; } public void DetectRaw(IInputArray image, VectorOfKeyPoint keypoints, IInputArray mask = null) { using InputArray inputArray = image.GetInputArray(); using InputArray inputArray2 = ((mask == null) ? InputArray.GetEmpty() : mask.GetInputArray()); Features2DInvoke.CvFeature2DDetect(_feature2D, inputArray, keypoints.Ptr, inputArray2); } public MKeyPoint[] Detect(IInputArray image, IInputArray mask = null) { using VectorOfKeyPoint vectorOfKeyPoint = new VectorOfKeyPoint(); DetectRaw(image, vectorOfKeyPoint, mask); return vectorOfKeyPoint.ToArray(); } public void Compute(IInputArray image, VectorOfKeyPoint keyPoints, IOutputArray descriptors) { using InputArray inputArray = image.GetInputArray(); using OutputArray outputArray = descriptors.GetOutputArray(); Features2DInvoke.CvFeature2DCompute(_feature2D, inputArray, keyPoints.Ptr, outputArray); } } public static class Features2DToolbox { public enum KeypointDrawType { Default = 0, NotDrawSinglePoints = 2, DrawRichKeypoints = 4 } public static void DrawKeypoints(IInputArray image, VectorOfKeyPoint keypoints, IInputOutputArray outImage, Bgr color, KeypointDrawType type = KeypointDrawType.Default) { MCvScalar color2 = color.MCvScalar; using InputArray inputArray = image.GetInputArray(); using InputOutputArray inputOutputArray = outImage.GetInputOutputArray(); Features2DInvoke.drawKeypoints(inputArray, keypoints, inputOutputArray, ref color2, type); } public static void DrawMatches(IInputArray modelImage, VectorOfKeyPoint modelKeypoints, IInputArray observedImage, VectorOfKeyPoint observedKeyPoints, VectorOfVectorOfDMatch matches, IInputOutputArray result, MCvScalar matchColor, MCvScalar singlePointColor, VectorOfVectorOfByte mask = null, KeypointDrawType flags = KeypointDrawType.Default) { using InputArray inputArray2 = modelImage.GetInputArray(); using InputArray inputArray = observedImage.GetInputArray(); using InputOutputArray inputOutputArray = result.GetInputOutputArray(); Features2DInvoke.drawMatchedFeatures2(inputArray, observedKeyPoints, inputArray2, modelKeypoints, matches, inputOutputArray, ref matchColor, ref singlePointColor, mask, flags); } public static void DrawMatches(IInputArray modelImage, VectorOfKeyPoint modelKeypoints, IInputArray observedImage, VectorOfKeyPoint observedKeyPoints, VectorOfDMatch matches, IInputOutputArray result, MCvScalar matchColor, MCvScalar singlePointColor, VectorOfByte mask = null, KeypointDrawType flags = KeypointDrawType.Default) { using InputArray inputArray2 = modelImage.GetInputArray(); using InputArray inputArray = observedImage.GetInputArray(); using InputOutputArray inputOutputArray = result.GetInputOutputArray(); Features2DInvoke.drawMatchedFeatures1(inputArray, observedKeyPoints, inputArray2, modelKeypoints, matches, inputOutputArray, ref matchColor, ref singlePointColor, mask, flags); } public static void DrawMatches(IInputArray modelImage, VectorOfKeyPoint modelKeypoints, IInputArray observedImage, VectorOfKeyPoint observedKeyPoints, VectorOfVectorOfDMatch matches, IInputOutputArray result, MCvScalar matchColor, MCvScalar singlePointColor, IInputArray mask = null, KeypointDrawType flags = KeypointDrawType.Default) { using InputArray inputArray2 = modelImage.GetInputArray(); using InputArray inputArray = observedImage.GetInputArray(); using InputOutputArray inputOutputArray = result.GetInputOutputArray(); using InputArray inputArray3 = ((mask == null) ? InputArray.GetEmpty() : mask.GetInputArray()); Features2DInvoke.drawMatchedFeatures3(inputArray, observedKeyPoints, inputArray2, modelKeypoints, matches, inputOutputArray, ref matchColor, ref singlePointColor, inputArray3, flags); } public static int VoteForSizeAndOrientation(VectorOfKeyPoint modelKeyPoints, VectorOfKeyPoint observedKeyPoints, VectorOfVectorOfDMatch matches, Mat mask, double scaleIncrement, int rotationBins) { return Features2DInvoke.voteForSizeAndOrientation(modelKeyPoints, observedKeyPoints, matches, mask, scaleIncrement, rotationBins); } public static Mat GetHomographyMatrixFromMatchedFeatures(VectorOfKeyPoint model, VectorOfKeyPoint observed, VectorOfVectorOfDMatch matches, Mat mask, double ransacReprojThreshold) { Mat mat = new Mat(); if (Features2DInvoke.getHomographyMatrixFromMatchedFeatures(model, observed, matches, mask, ransacReprojThreshold, mat)) { return mat; } mat.Dispose(); return null; } public static void VoteForUniqueness(VectorOfVectorOfDMatch matches, double uniquenessThreshold, Mat mask) { MDMatch[][] array = matches.ToArrayOfArray(); byte[] array2 = new byte[array.Length]; GCHandle gCHandle = GCHandle.Alloc(array2, GCHandleType.Pinned); using (Mat mat = new Mat(array.Length, 1, DepthType.Cv8U, 1, gCHandle.AddrOfPinnedObject(), 1)) { mask.CopyTo(mat); for (int i = 0; i < array.Length; i++) { if (array2[i] != 0 && (double)(array[i][0].Distance / array[i][1].Distance) > uniquenessThreshold) { array2[i] = 0; } } mat.CopyTo(mask); } gCHandle.Free(); } } public class FlannBasedMatcher : DescriptorMatcher { public FlannBasedMatcher(IIndexParams indexParams, SearchParams search) { _ptr = Features2DInvoke.cveFlannBasedMatcherCreate(indexParams.IndexParamPtr, search.Ptr, ref _descriptorMatcherPtr); } protected override void DisposeObject() { if (_ptr != IntPtr.Zero) { Features2DInvoke.cveFlannBasedMatcherRelease(ref _ptr); } base.DisposeObject(); } } public class GFTTDetector : Feature2D { public GFTTDetector(int maxCorners = 1000, double qualityLevel = 0.01, double minDistance = 1.0, int blockSize = 3, bool useHarrisDetector = false, double k = 0.04) { _ptr = Features2DInvoke.cveGFTTDetectorCreate(maxCorners, qualityLevel, minDistance, blockSize, useHarrisDetector, k, ref _feature2D, ref _sharedPtr); } protected override void DisposeObject() { if (_sharedPtr != IntPtr.Zero) { Features2DInvoke.cveGFTTDetectorRelease(ref _sharedPtr); } base.DisposeObject(); } } public class KAZE : Feature2D { public enum Diffusivity { PmG1, PmG2, Weickert, Charbonnier } public KAZE(bool extended = false, bool upright = false, float threshold = 0.001f, int octaves = 4, int sublevels = 4, Diffusivity diffusivity = Diffusivity.PmG2) { _ptr = Features2DInvoke.cveKAZEDetectorCreate(extended, upright, threshold, octaves, sublevels, diffusivity, ref _feature2D, ref _sharedPtr); } protected override void DisposeObject() { if (_sharedPtr != IntPtr.Zero) { Features2DInvoke.cveKAZEDetectorRelease(ref _sharedPtr); } base.DisposeObject(); } } public class MSER : Feature2D { public bool Pass2Only { get { return Features2DInvoke.cveMSERGetPass2Only(_ptr); } set { Features2DInvoke.cveMSERSetPass2Only(_ptr, value); } } public int Delta { get { return Features2DInvoke.cveMSERGetDelta(_ptr); } set { Features2DInvoke.cveMSERSetDelta(_ptr, value); } } public int MinArea { get { return Features2DInvoke.cveMSERGetMinArea(_ptr); } set { Features2DInvoke.cveMSERSetMinArea(_ptr, value); } } public int MaxArea { get { return Features2DInvoke.cveMSERGetMaxArea(_ptr); } set { Features2DInvoke.cveMSERSetMaxArea(_ptr, value); } } public MSER(int delta = 5, int minArea = 60, int maxArea = 14400, double maxVariation = 0.25, double minDiversity = 0.2, int maxEvolution = 200, double areaThreshold = 1.01, double minMargin = 0.003, int edgeBlurSize = 5) { _ptr = Features2DInvoke.cveMserCreate(delta, minArea, maxArea, maxVariation, minDiversity, maxEvolution, areaThreshold, minMargin, edgeBlurSize, ref _feature2D, ref _sharedPtr); } protected override void DisposeObject() { if (_sharedPtr != IntPtr.Zero) { Features2DInvoke.cveMserRelease(ref _sharedPtr); } base.DisposeObject(); } public void DetectRegions(IInputArray image, VectorOfVectorOfPoint msers, VectorOfRect bboxes) { using InputArray inputArray = image.GetInputArray(); Features2DInvoke.cveMserDetectRegions(_ptr, inputArray, msers, bboxes); } } public class ORB : Feature2D { public enum ScoreType { Harris, Fast } public ORB(int numberOfFeatures = 500, float scaleFactor = 1.2f, int nLevels = 8, int edgeThreshold = 31, int firstLevel = 0, int WTK_A = 2, ScoreType scoreType = ScoreType.Harris, int patchSize = 31, int fastThreshold = 20) { _ptr = Features2DInvoke.cveOrbCreate(numberOfFeatures, scaleFactor, nLevels, edgeThreshold, firstLevel, WTK_A, scoreType, patchSize, fastThreshold, ref _feature2D, ref _sharedPtr); } protected override void DisposeObject() { if (_sharedPtr != IntPtr.Zero) { Features2DInvoke.cveOrbRelease(ref _sharedPtr); } base.DisposeObject(); } } public class SIFT : Feature2D { public SIFT(int nFeatures = 0, int nOctaveLayers = 3, double contrastThreshold = 0.04, double edgeThreshold = 10.0, double sigma = 1.6) { _ptr = Features2DInvoke.cveSIFTCreate(nFeatures, nOctaveLayers, contrastThreshold, edgeThreshold, sigma, ref _feature2D, ref _sharedPtr); } protected override void DisposeObject() { if (_sharedPtr != IntPtr.Zero) { Features2DInvoke.cveSIFTRelease(ref _sharedPtr); } base.DisposeObject(); } } public class SimpleBlobDetector : Feature2D { public SimpleBlobDetector(SimpleBlobDetectorParams parameters = null) { if (parameters == null) { _ptr = Features2DInvoke.cveSimpleBlobDetectorCreate(ref _feature2D, ref _sharedPtr); } else { _ptr = Features2DInvoke.cveSimpleBlobDetectorCreateWithParams(ref _feature2D, parameters, ref _sharedPtr); } } protected override void DisposeObject() { if (_sharedPtr != IntPtr.Zero) { Features2DInvoke.cveSimpleBlobDetectorRelease(ref _sharedPtr); } base.DisposeObject(); } } public class SimpleBlobDetectorParams : UnmanagedObject { public float ThresholdStep { get { return Features2DInvoke.cveSimpleBlobDetectorParamsGetThresholdStep(_ptr); } set { Features2DInvoke.cveSimpleBlobDetectorParamsSetThresholdStep(_ptr, value); } } public float MinThreshold { get { return Features2DInvoke.cveSimpleBlobDetectorParamsGetMinThreshold(_ptr); } set { Features2DInvoke.cveSimpleBlobDetectorParamsSetMinThreshold(_ptr, value); } } public float MaxThreshold { get { return Features2DInvoke.cveSimpleBlobDetectorParamsGetMaxThreshold(_ptr); } set { Features2DInvoke.cveSimpleBlobDetectorParamsSetMaxThreshold(_ptr, value); } } public float MinDistBetweenBlobs { get { return Features2DInvoke.cveSimpleBlobDetectorParamsGetMinDistBetweenBlobs(_ptr); } set { Features2DInvoke.cveSimpleBlobDetectorParamsSetMinDistBetweenBlobs(_ptr, value); } } public bool FilterByColor { get { return Features2DInvoke.cveSimpleBlobDetectorParamsGetFilterByColor(_ptr); } set { Features2DInvoke.cveSimpleBlobDetectorParamsSetFilterByColor(_ptr, value); } } public byte blobColor { get { return Features2DInvoke.cveSimpleBlobDetectorParamsGetblobColor(_ptr); } set { Features2DInvoke.cveSimpleBlobDetectorParamsSetblobColor(_ptr, value); } } public bool FilterByArea { get { return Features2DInvoke.cveSimpleBlobDetectorParamsGetFilterByArea(_ptr); } set { Features2DInvoke.cveSimpleBlobDetectorParamsSetFilterByArea(_ptr, value); } } public float MinArea { get { return Features2DInvoke.cveSimpleBlobDetectorParamsGetMinArea(_ptr); } set { Features2DInvoke.cveSimpleBlobDetectorParamsSetMinArea(_ptr, value); } } public float MaxArea { get { return Features2DInvoke.cveSimpleBlobDetectorParamsGetMaxArea(_ptr); } set { Features2DInvoke.cveSimpleBlobDetectorParamsSetMaxArea(_ptr, value); } } public bool FilterByCircularity { get { return Features2DInvoke.cveSimpleBlobDetectorParamsGetFilterByCircularity(_ptr); } set { Features2DInvoke.cveSimpleBlobDetectorParamsSetFilterByCircularity(_ptr, value); } } public float MinCircularity { get { return Features2DInvoke.cveSimpleBlobDetectorParamsGetMinCircularity(_ptr); } set { Features2DInvoke.cveSimpleBlobDetectorParamsSetMinCircularity(_ptr, value); } } public float MaxCircularity { get { return Features2DInvoke.cveSimpleBlobDetectorParamsGetMaxCircularity(_ptr); } set { Features2DInvoke.cveSimpleBlobDetectorParamsSetMaxCircularity(_ptr, value); } } public bool FilterByInertia { get { return Features2DInvoke.cveSimpleBlobDetectorParamsGetFilterByInertia(_ptr); } set { Features2DInvoke.cveSimpleBlobDetectorParamsSetFilterByInertia(_ptr, value); } } public float MinInertiaRatio { get { return Features2DInvoke.cveSimpleBlobDetectorParamsGetMinInertiaRatio(_ptr); } set { Features2DInvoke.cveSimpleBlobDetectorParamsSetMinInertiaRatio(_ptr, value); } } public float MaxInertiaRatio { get { return Features2DInvoke.cveSimpleBlobDetectorParamsGetMaxInertiaRatio(_ptr); } set { Features2DInvoke.cveSimpleBlobDetectorParamsSetMaxInertiaRatio(_ptr, value); } } public bool FilterByConvexity { get { return Features2DInvoke.cveSimpleBlobDetectorParamsGetFilterByConvexity(_ptr); } set { Features2DInvoke.cveSimpleBlobDetectorParamsSetFilterByConvexity(_ptr, value); } } public float MinConvexity { get { return Features2DInvoke.cveSimpleBlobDetectorParamsGetMinConvexity(_ptr); } set { Features2DInvoke.cveSimpleBlobDetectorParamsSetMinConvexity(_ptr, value); } } public float MaxConvexity { get { return Features2DInvoke.cveSimpleBlobDetectorParamsGetMaxConvexity(_ptr); } set { Features2DInvoke.cveSimpleBlobDetectorParamsSetMaxConvexity(_ptr, value); } } public IntPtr MinRepeatability { get { return Features2DInvoke.cveSimpleBlobDetectorParamsGetMinRepeatability(_ptr); } set { Features2DInvoke.cveSimpleBlobDetectorParamsSetMinRepeatability(_ptr, value); } } public SimpleBlobDetectorParams() { _ptr = Features2DInvoke.cveSimpleBlobDetectorParamsCreate(); } protected override void DisposeObject() { if (_ptr != IntPtr.Zero) { Features2DInvoke.cveSimpleBlobDetectorParamsRelease(ref _ptr); } } } }