mirror of https://github.com/emgucv/emgucv.git

6 changed files with 610 additions and 325 deletions
-
136Emgu.CV.Extern/core/ocl_c.cpp
-
23Emgu.CV.Extern/core/ocl_c.h
-
258Emgu.CV.Test/AutoTestOpenCL.cs
-
101Emgu.CV/Ocl/Context.cs
-
338Emgu.CV/Ocl/Device.cs
-
79Emgu.CV/Ocl/Program.cs
@ -0,0 +1,101 @@ |
|||
//----------------------------------------------------------------------------
|
|||
// Copyright (C) 2004-2020 by EMGU Corporation. All rights reserved.
|
|||
//----------------------------------------------------------------------------
|
|||
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Text; |
|||
using Emgu.CV; |
|||
using Emgu.Util; |
|||
using System.Runtime.InteropServices; |
|||
|
|||
namespace Emgu.CV.Ocl |
|||
{ |
|||
/// <summary>
|
|||
/// This class contains ocl context information
|
|||
/// </summary>
|
|||
public partial class Context : UnmanagedObject |
|||
{ |
|||
private static Context _defaultContext = new Context(OclInvoke.oclContextGetDefault(), false); |
|||
|
|||
private bool _needDispose; |
|||
|
|||
/// <summary>
|
|||
/// Create a empty OclContext object
|
|||
/// </summary>
|
|||
public Context() |
|||
: this(OclInvoke.oclContextCreate(), true) |
|||
{ |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Get the default OclContext. Do not dispose this context.
|
|||
/// </summary>
|
|||
public static Context Default |
|||
{ |
|||
get |
|||
{ |
|||
return _defaultContext; |
|||
} |
|||
} |
|||
|
|||
internal Context(IntPtr ptr, bool needDispose) |
|||
{ |
|||
_ptr = ptr; |
|||
_needDispose = needDispose; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Release all the unmanaged memory associated with this OclContext
|
|||
/// </summary>
|
|||
protected override void DisposeObject() |
|||
{ |
|||
if (_needDispose) |
|||
{ |
|||
if (_ptr != IntPtr.Zero) |
|||
{ |
|||
OclInvoke.oclContextRelease(ref _ptr); |
|||
} |
|||
} |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Compile the program
|
|||
/// </summary>
|
|||
/// <param name="prog">The program source</param>
|
|||
/// <param name="buildOpt">The build option</param>
|
|||
/// <param name="errMsg">Error message</param>
|
|||
/// <returns>The compiled program</returns>
|
|||
public Program GetProgram(ProgramSource prog, String buildOpt, CvString errMsg) |
|||
{ |
|||
using (CvString csBuildOpt = new CvString(buildOpt)) |
|||
{ |
|||
return new Program(OclInvoke.oclContextGetProg(_ptr, prog, csBuildOpt, errMsg)); |
|||
} |
|||
} |
|||
|
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Class that contains ocl functions
|
|||
/// </summary>
|
|||
public static partial class OclInvoke |
|||
{ |
|||
[DllImport(CvInvoke.ExternLibrary, CallingConvention = CvInvoke.CvCallingConvention)] |
|||
internal static extern IntPtr oclContextCreate(); |
|||
|
|||
[DllImport(CvInvoke.ExternLibrary, CallingConvention = CvInvoke.CvCallingConvention)] |
|||
internal static extern IntPtr oclContextGetDefault(); |
|||
|
|||
[DllImport(CvInvoke.ExternLibrary, CallingConvention = CvInvoke.CvCallingConvention)] |
|||
internal static extern void oclContextRelease(ref IntPtr oclContext); |
|||
|
|||
[DllImport(CvInvoke.ExternLibrary, CallingConvention = CvInvoke.CvCallingConvention)] |
|||
internal static extern IntPtr oclContextGetProg( |
|||
IntPtr context, |
|||
IntPtr prog, |
|||
IntPtr buildopt, |
|||
IntPtr errmsg); |
|||
|
|||
} |
|||
} |
@ -0,0 +1,79 @@ |
|||
//----------------------------------------------------------------------------
|
|||
// Copyright (C) 2004-2020 by EMGU Corporation. All rights reserved.
|
|||
//----------------------------------------------------------------------------
|
|||
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Text; |
|||
using Emgu.CV; |
|||
using Emgu.Util; |
|||
using System.Runtime.InteropServices; |
|||
using Emgu.CV.Util; |
|||
|
|||
namespace Emgu.CV.Ocl |
|||
{ |
|||
/// <summary>
|
|||
/// This class contains ocl Program information
|
|||
/// </summary>
|
|||
public partial class Program : UnmanagedObject |
|||
{ |
|||
/// <summary>
|
|||
/// Create a empty OclProgram object
|
|||
/// </summary>
|
|||
public Program() |
|||
: this(OclInvoke.oclProgramCreate()) |
|||
{ |
|||
} |
|||
|
|||
internal Program(IntPtr ptr) |
|||
{ |
|||
_ptr = ptr; |
|||
} |
|||
|
|||
|
|||
/// <summary>
|
|||
/// Get the program binary
|
|||
/// </summary>
|
|||
public byte[] Binary |
|||
{ |
|||
get |
|||
{ |
|||
if (_ptr == IntPtr.Zero) |
|||
return null; |
|||
|
|||
using (VectorOfByte vb = new VectorOfByte()) |
|||
{ |
|||
OclInvoke.oclProgramGetBinary(_ptr, vb); |
|||
return vb.ToArray(); |
|||
} |
|||
} |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Release all the unmanaged memory associated with this OclProgram
|
|||
/// </summary>
|
|||
protected override void DisposeObject() |
|||
{ |
|||
if (_ptr != IntPtr.Zero) |
|||
{ |
|||
OclInvoke.oclProgramRelease(ref _ptr); |
|||
} |
|||
} |
|||
|
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Class that contains ocl functions
|
|||
/// </summary>
|
|||
public static partial class OclInvoke |
|||
{ |
|||
[DllImport(CvInvoke.ExternLibrary, CallingConvention = CvInvoke.CvCallingConvention)] |
|||
internal static extern IntPtr oclProgramCreate(); |
|||
|
|||
[DllImport(CvInvoke.ExternLibrary, CallingConvention = CvInvoke.CvCallingConvention)] |
|||
internal static extern void oclProgramRelease(ref IntPtr oclProgram); |
|||
|
|||
[DllImport(CvInvoke.ExternLibrary, CallingConvention = CvInvoke.CvCallingConvention)] |
|||
internal static extern void oclProgramGetBinary(IntPtr program, IntPtr binary); |
|||
} |
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue