Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
using System.Runtime.InteropServices;

#pragma warning disable 1591
#pragma warning disable CA1401 // P/Invokes should not be visible
#pragma warning disable IDE1006 // Naming style

namespace OpenCvSharp.Internal;

static partial class NativeMethods
{
[DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern ExceptionStatus saliency_Ptr_MotionSaliencyBinWangApr2014_delete(IntPtr obj);

[DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern ExceptionStatus saliency_Ptr_MotionSaliencyBinWangApr2014_get(
IntPtr ptr, out IntPtr returnValue);

[DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern ExceptionStatus saliency_MotionSaliencyBinWangApr2014_create(
out IntPtr returnValue);

[DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern ExceptionStatus saliency_MotionSaliencyBinWangApr2014_computeSaliency(
IntPtr obj, IntPtr image, IntPtr saliencyMap, out int returnValue);

[DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern ExceptionStatus saliency_MotionSaliencyBinWangApr2014_setImagesize(
IntPtr obj, int W, int H);

[DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern ExceptionStatus saliency_MotionSaliencyBinWangApr2014_init(
IntPtr obj, out int returnValue);

[DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern ExceptionStatus saliency_MotionSaliencyBinWangApr2014_getImageWidth(
IntPtr obj, out int returnValue);

[DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern ExceptionStatus saliency_MotionSaliencyBinWangApr2014_setImageWidth(
IntPtr obj, int val);

[DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern ExceptionStatus saliency_MotionSaliencyBinWangApr2014_getImageHeight(
IntPtr obj, out int returnValue);

[DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern ExceptionStatus saliency_MotionSaliencyBinWangApr2014_setImageHeight(
IntPtr obj, int val);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
using System.Runtime.InteropServices;

#pragma warning disable 1591
#pragma warning disable CA1401 // P/Invokes should not be visible
#pragma warning disable IDE1006 // Naming style

namespace OpenCvSharp.Internal;

static partial class NativeMethods
{
[DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern ExceptionStatus saliency_Ptr_ObjectnessBING_delete(IntPtr obj);

[DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern ExceptionStatus saliency_Ptr_ObjectnessBING_get(
IntPtr ptr, out IntPtr returnValue);

[DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern ExceptionStatus saliency_ObjectnessBING_create(out IntPtr returnValue);

[DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern ExceptionStatus saliency_ObjectnessBING_computeSaliency(
IntPtr obj, IntPtr image, IntPtr objectnessBoundingBox, out int returnValue);

[DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern ExceptionStatus saliency_ObjectnessBING_getobjectnessValues(
IntPtr obj, IntPtr returnValue);

[DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern ExceptionStatus saliency_ObjectnessBING_setTrainingPath(
IntPtr obj, [MarshalAs(UnmanagedType.LPStr)] string trainingPath);

Check warning on line 31 in src/OpenCvSharp/Internal/PInvoke/NativeMethods/saliency/NativeMethods_saliency_ObjectnessBING.cs

View workflow job for this annotation

GitHub Actions / build

Specify marshaling for P/Invoke string arguments (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca2101)

Check warning on line 31 in src/OpenCvSharp/Internal/PInvoke/NativeMethods/saliency/NativeMethods_saliency_ObjectnessBING.cs

View workflow job for this annotation

GitHub Actions / build

Specify marshaling for P/Invoke string arguments (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca2101)

Check warning on line 31 in src/OpenCvSharp/Internal/PInvoke/NativeMethods/saliency/NativeMethods_saliency_ObjectnessBING.cs

View workflow job for this annotation

GitHub Actions / build

Specify marshaling for P/Invoke string arguments (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca2101)

Check warning on line 31 in src/OpenCvSharp/Internal/PInvoke/NativeMethods/saliency/NativeMethods_saliency_ObjectnessBING.cs

View workflow job for this annotation

GitHub Actions / build

Specify marshaling for P/Invoke string arguments (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca2101)

Check warning on line 31 in src/OpenCvSharp/Internal/PInvoke/NativeMethods/saliency/NativeMethods_saliency_ObjectnessBING.cs

View workflow job for this annotation

GitHub Actions / test

Specify marshaling for P/Invoke string arguments (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca2101)

Check warning on line 31 in src/OpenCvSharp/Internal/PInvoke/NativeMethods/saliency/NativeMethods_saliency_ObjectnessBING.cs

View workflow job for this annotation

GitHub Actions / test

Specify marshaling for P/Invoke string arguments (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca2101)

[DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern ExceptionStatus saliency_ObjectnessBING_setBBResDir(
IntPtr obj, [MarshalAs(UnmanagedType.LPStr)] string resultsDir);

Check warning on line 35 in src/OpenCvSharp/Internal/PInvoke/NativeMethods/saliency/NativeMethods_saliency_ObjectnessBING.cs

View workflow job for this annotation

GitHub Actions / build

Specify marshaling for P/Invoke string arguments (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca2101)

Check warning on line 35 in src/OpenCvSharp/Internal/PInvoke/NativeMethods/saliency/NativeMethods_saliency_ObjectnessBING.cs

View workflow job for this annotation

GitHub Actions / build

Specify marshaling for P/Invoke string arguments (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca2101)

Check warning on line 35 in src/OpenCvSharp/Internal/PInvoke/NativeMethods/saliency/NativeMethods_saliency_ObjectnessBING.cs

View workflow job for this annotation

GitHub Actions / build

Specify marshaling for P/Invoke string arguments (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca2101)

Check warning on line 35 in src/OpenCvSharp/Internal/PInvoke/NativeMethods/saliency/NativeMethods_saliency_ObjectnessBING.cs

View workflow job for this annotation

GitHub Actions / build

Specify marshaling for P/Invoke string arguments (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca2101)

Check warning on line 35 in src/OpenCvSharp/Internal/PInvoke/NativeMethods/saliency/NativeMethods_saliency_ObjectnessBING.cs

View workflow job for this annotation

GitHub Actions / test

Specify marshaling for P/Invoke string arguments (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca2101)

Check warning on line 35 in src/OpenCvSharp/Internal/PInvoke/NativeMethods/saliency/NativeMethods_saliency_ObjectnessBING.cs

View workflow job for this annotation

GitHub Actions / test

Specify marshaling for P/Invoke string arguments (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca2101)

[DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern ExceptionStatus saliency_ObjectnessBING_getBase(
IntPtr obj, out double returnValue);

[DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern ExceptionStatus saliency_ObjectnessBING_setBase(IntPtr obj, double val);

[DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern ExceptionStatus saliency_ObjectnessBING_getNSS(
IntPtr obj, out int returnValue);

[DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern ExceptionStatus saliency_ObjectnessBING_setNSS(IntPtr obj, int val);

[DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern ExceptionStatus saliency_ObjectnessBING_getW(
IntPtr obj, out int returnValue);

[DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern ExceptionStatus saliency_ObjectnessBING_setW(IntPtr obj, int val);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using System.Runtime.InteropServices;

#pragma warning disable 1591
#pragma warning disable CA1401 // P/Invokes should not be visible
#pragma warning disable IDE1006 // Naming style

namespace OpenCvSharp.Internal;

static partial class NativeMethods
{
[DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern ExceptionStatus saliency_Ptr_StaticSaliencyFineGrained_delete(IntPtr obj);

[DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern ExceptionStatus saliency_Ptr_StaticSaliencyFineGrained_get(
IntPtr ptr, out IntPtr returnValue);

[DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern ExceptionStatus saliency_StaticSaliencyFineGrained_create(
out IntPtr returnValue);

[DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern ExceptionStatus saliency_StaticSaliencyFineGrained_computeSaliency(
IntPtr obj, IntPtr image, IntPtr saliencyMap, out int returnValue);

[DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern ExceptionStatus saliency_StaticSaliencyFineGrained_computeBinaryMap(
IntPtr obj, IntPtr saliencyMap, IntPtr binaryMap, out int returnValue);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using System.Runtime.InteropServices;

#pragma warning disable 1591
#pragma warning disable CA1401 // P/Invokes should not be visible
#pragma warning disable IDE1006 // Naming style

namespace OpenCvSharp.Internal;

static partial class NativeMethods
{
[DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern ExceptionStatus saliency_Ptr_StaticSaliencySpectralResidual_delete(IntPtr obj);

[DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern ExceptionStatus saliency_Ptr_StaticSaliencySpectralResidual_get(
IntPtr ptr, out IntPtr returnValue);

[DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern ExceptionStatus saliency_StaticSaliencySpectralResidual_create(
out IntPtr returnValue);

[DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern ExceptionStatus saliency_StaticSaliencySpectralResidual_computeSaliency(
IntPtr obj, IntPtr image, IntPtr saliencyMap, out int returnValue);

[DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern ExceptionStatus saliency_StaticSaliencySpectralResidual_computeBinaryMap(
IntPtr obj, IntPtr saliencyMap, IntPtr binaryMap, out int returnValue);

[DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern ExceptionStatus saliency_StaticSaliencySpectralResidual_getImageWidth(
IntPtr obj, out int returnValue);

[DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern ExceptionStatus saliency_StaticSaliencySpectralResidual_setImageWidth(
IntPtr obj, int val);

[DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern ExceptionStatus saliency_StaticSaliencySpectralResidual_getImageHeight(
IntPtr obj, out int returnValue);

[DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern ExceptionStatus saliency_StaticSaliencySpectralResidual_setImageHeight(
IntPtr obj, int val);
}
125 changes: 125 additions & 0 deletions src/OpenCvSharp/Modules/saliency/MotionSaliencyBinWangApr2014.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
using OpenCvSharp.Internal;

// ReSharper disable UnusedMember.Global

namespace OpenCvSharp.Saliency;

/// <summary>
/// A Fast Self-tuning Background Subtraction Algorithm for motion saliency detection.
/// </summary>
public class MotionSaliencyBinWangApr2014 : Algorithm
{
private MotionSaliencyBinWangApr2014(IntPtr smartPtr, IntPtr rawPtr)
: base(smartPtr, rawPtr, p => NativeMethods.HandleException(
NativeMethods.saliency_Ptr_MotionSaliencyBinWangApr2014_delete(p)))
{ }

/// <summary>
/// Creates a MotionSaliencyBinWangApr2014 instance.
/// </summary>
public static MotionSaliencyBinWangApr2014 Create()
{
NativeMethods.HandleException(
NativeMethods.saliency_MotionSaliencyBinWangApr2014_create(out var smartPtr));
NativeMethods.HandleException(
NativeMethods.saliency_Ptr_MotionSaliencyBinWangApr2014_get(smartPtr, out var rawPtr));
return new MotionSaliencyBinWangApr2014(smartPtr, rawPtr);
}

/// <summary>
/// Computes the motion saliency map for the given frame.
/// </summary>
/// <param name="image">Input image frame (grayscale, CV_8UC1).</param>
/// <param name="saliencyMap">The computed binary saliency map.</param>
/// <returns>true if the saliency map was computed successfully.</returns>
public virtual bool ComputeSaliency(InputArray image, OutputArray saliencyMap)
{
ThrowIfDisposed();
if (image is null)
throw new ArgumentNullException(nameof(image));
if (saliencyMap is null)
throw new ArgumentNullException(nameof(saliencyMap));
image.ThrowIfDisposed();
saliencyMap.ThrowIfNotReady();

NativeMethods.HandleException(
NativeMethods.saliency_MotionSaliencyBinWangApr2014_computeSaliency(
RawPtr, image.CvPtr, saliencyMap.CvPtr, out var ret));
GC.KeepAlive(this);
GC.KeepAlive(image);
saliencyMap.Fix();
return ret != 0;
}

/// <summary>
/// Sets the image dimensions to prepare the algorithm's data structures.
/// Must be called before <see cref="Init"/>.
/// </summary>
/// <param name="width">Width of the input images.</param>
/// <param name="height">Height of the input images.</param>
public void SetImagesize(int width, int height)
{
ThrowIfDisposed();
NativeMethods.HandleException(
NativeMethods.saliency_MotionSaliencyBinWangApr2014_setImagesize(RawPtr, width, height));
GC.KeepAlive(this);
}

/// <summary>
/// Initializes all data structures for the algorithm.
/// Call after <see cref="SetImagesize"/>.
/// </summary>
/// <returns>true if initialization succeeded.</returns>
public bool Init()
{
ThrowIfDisposed();
NativeMethods.HandleException(
NativeMethods.saliency_MotionSaliencyBinWangApr2014_init(RawPtr, out var ret));
GC.KeepAlive(this);
return ret != 0;
}

/// <summary>
/// Gets or sets the image width.
/// </summary>
public int ImageWidth
{
get
{
ThrowIfDisposed();
NativeMethods.HandleException(
NativeMethods.saliency_MotionSaliencyBinWangApr2014_getImageWidth(RawPtr, out var val));
GC.KeepAlive(this);
return val;
}
set
{
ThrowIfDisposed();
NativeMethods.HandleException(
NativeMethods.saliency_MotionSaliencyBinWangApr2014_setImageWidth(RawPtr, value));
GC.KeepAlive(this);
}
}

/// <summary>
/// Gets or sets the image height.
/// </summary>
public int ImageHeight
{
get
{
ThrowIfDisposed();
NativeMethods.HandleException(
NativeMethods.saliency_MotionSaliencyBinWangApr2014_getImageHeight(RawPtr, out var val));
GC.KeepAlive(this);
return val;
}
set
{
ThrowIfDisposed();
NativeMethods.HandleException(
NativeMethods.saliency_MotionSaliencyBinWangApr2014_setImageHeight(RawPtr, value));
GC.KeepAlive(this);
}
}
}
Loading
Loading