Skip to content

Commit

Permalink
Merge pull request #1137 from shimat/fix_tracking
Browse files Browse the repository at this point in the history
Move Tracker implementation from tracking to video
  • Loading branch information
shimat authored Dec 31, 2020
2 parents 7721686 + 54cd60a commit 5921d3f
Show file tree
Hide file tree
Showing 8 changed files with 154 additions and 161 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System;

namespace OpenCvSharp.Tracking
namespace OpenCvSharp
{
/// <summary>
/// Base abstract class for the long-term tracker
Expand Down Expand Up @@ -44,7 +44,7 @@ public void Init(Mat image, Rect boundingBox)

image.ThrowIfDisposed();
NativeMethods.HandleException(
NativeMethods.tracking_Tracker_init(ptr, image.CvPtr, boundingBox));
NativeMethods.video_Tracker_init(ptr, image.CvPtr, boundingBox));
GC.KeepAlive(this);
GC.KeepAlive(image);
}
Expand All @@ -66,7 +66,7 @@ public bool Update(Mat image, ref Rect boundingBox)

image.ThrowIfDisposed();
NativeMethods.HandleException(
NativeMethods.tracking_Tracker_update(ptr, image.CvPtr, ref boundingBox, out var ret));
NativeMethods.video_Tracker_update(ptr, image.CvPtr, ref boundingBox, out var ret));
GC.KeepAlive(this);
GC.KeepAlive(image);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System;
using System.Runtime.InteropServices;

namespace OpenCvSharp.Tracking
namespace OpenCvSharp
{
/// <inheritdoc />
/// <summary>
Expand Down Expand Up @@ -40,7 +40,7 @@ protected TrackerGOTURN(IntPtr p)
public static TrackerGOTURN Create()
{
NativeMethods.HandleException(
NativeMethods.tracking_TrackerGOTURN_create1(out var p));
NativeMethods.video_TrackerGOTURN_create1(out var p));
return new TrackerGOTURN(p);
}

Expand All @@ -55,7 +55,7 @@ public static TrackerGOTURN Create(Params parameters)
unsafe
{
NativeMethods.HandleException(
NativeMethods.tracking_TrackerGOTURN_create2(&parameters, out var p));
NativeMethods.video_TrackerGOTURN_create2(&parameters, out var p));
return new TrackerGOTURN(p);
}
}
Expand All @@ -69,15 +69,15 @@ public Ptr(IntPtr ptr) : base(ptr)
public override IntPtr Get()
{
NativeMethods.HandleException(
NativeMethods.tracking_Ptr_TrackerGOTURN_get(ptr, out var ret));
NativeMethods.video_Ptr_TrackerGOTURN_get(ptr, out var ret));
GC.KeepAlive(this);
return ret;
}

protected override void DisposeUnmanaged()
{
NativeMethods.HandleException(
NativeMethods.tracking_Ptr_TrackerGOTURN_delete(ptr));
NativeMethods.video_Ptr_TrackerGOTURN_delete(ptr));
base.DisposeUnmanaged();
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
using System;
using System.Runtime.InteropServices;
using OpenCvSharp.Tracking;

namespace OpenCvSharp.Tracking
namespace OpenCvSharp
{
/// <inheritdoc />
/// <summary>
Expand All @@ -27,7 +28,7 @@ protected TrackerMIL(IntPtr p)
public static TrackerMIL Create()
{
NativeMethods.HandleException(
NativeMethods.tracking_TrackerMIL_create1(out var p));
NativeMethods.video_TrackerMIL_create1(out var p));
return new TrackerMIL(p);
}

Expand All @@ -41,7 +42,7 @@ public static TrackerMIL Create(Params parameters)
unsafe
{
NativeMethods.HandleException(
NativeMethods.tracking_TrackerMIL_create2(&parameters, out var p));
NativeMethods.video_TrackerMIL_create2(&parameters, out var p));
return new TrackerMIL(p);
}
}
Expand All @@ -55,15 +56,15 @@ public Ptr(IntPtr ptr) : base(ptr)
public override IntPtr Get()
{
NativeMethods.HandleException(
NativeMethods.tracking_Ptr_TrackerMIL_get(ptr, out var ret));
NativeMethods.video_Ptr_TrackerMIL_get(ptr, out var ret));
GC.KeepAlive(this);
return ret;
}

protected override void DisposeUnmanaged()
{
NativeMethods.HandleException(
NativeMethods.tracking_Ptr_TrackerMIL_delete(ptr));
NativeMethods.video_Ptr_TrackerMIL_delete(ptr));
base.DisposeUnmanaged();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,6 @@ namespace OpenCvSharp
{
static partial class NativeMethods
{
[Pure, DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern ExceptionStatus tracking_Tracker_init(IntPtr obj, IntPtr image, Rect boundingBox);

[Pure, DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern ExceptionStatus tracking_Tracker_update(IntPtr obj, IntPtr image, ref Rect boundingBox, out int returnValue);

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

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


// TrackerKCF

[Pure, DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
Expand All @@ -43,36 +30,6 @@ static partial class NativeMethods
public static extern ExceptionStatus tracking_Ptr_TrackerKCF_get(IntPtr ptr, out IntPtr returnValue);


// TrackerMIL

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

[Pure, DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern unsafe ExceptionStatus tracking_TrackerMIL_create2(TrackerMIL.Params* parameters, out IntPtr returnValue);

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

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


// TrackerGOTURN

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

[Pure, DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern unsafe ExceptionStatus tracking_TrackerGOTURN_create2(TrackerGOTURN.Params* parameters, out IntPtr returnValue);

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

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


// TrackerCSRT

[Pure, DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Diagnostics.Contracts;
using System.Runtime.InteropServices;
using OpenCvSharp.Tracking;

#pragma warning disable 1591
#pragma warning disable CA1401 // P/Invokes should not be visible
Expand Down Expand Up @@ -108,6 +109,48 @@ public static extern ExceptionStatus video_KalmanFilter_init(IntPtr obj, int dyn

#endregion

#region Tracker

// Tracker

[Pure, DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern ExceptionStatus video_Tracker_init(IntPtr obj, IntPtr image, Rect boundingBox);

[Pure, DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern ExceptionStatus video_Tracker_update(IntPtr obj, IntPtr image, ref Rect boundingBox, out int returnValue);


// TrackerMIL

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

[Pure, DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern unsafe ExceptionStatus video_TrackerMIL_create2(TrackerMIL.Params* parameters, out IntPtr returnValue);

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

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


// TrackerGOTURN

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

[Pure, DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern unsafe ExceptionStatus video_TrackerGOTURN_create2(TrackerGOTURN.Params* parameters, out IntPtr returnValue);

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

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

#endregion

// TODO
/*
[Pure, DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
Expand Down
104 changes: 0 additions & 104 deletions src/OpenCvSharpExtern/tracking.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,44 +8,6 @@

#include "include_opencv.h"

CVAPI(ExceptionStatus) tracking_Tracker_init(cv::Tracker* tracker, const cv::Mat* image, const MyCvRect boundingBox)
{
BEGIN_WRAP
tracker->init(*image, cpp(boundingBox));
END_WRAP
}

CVAPI(ExceptionStatus) tracking_Tracker_update(cv::Tracker* tracker, const cv::Mat* image, MyCvRect* boundingBox, int *returnValue)
{
BEGIN_WRAP
cv::Rect bb = cpp(*boundingBox);
const bool ret = tracker->update(*image, bb);
if (ret)
{
boundingBox->x = bb.x;
boundingBox->y = bb.y;
boundingBox->width = bb.width;
boundingBox->height = bb.height;
}

*returnValue = ret ? 1 : 0;
END_WRAP
}

CVAPI(ExceptionStatus) tracking_Ptr_Tracker_delete(cv::Ptr<cv::Tracker> *ptr)
{
BEGIN_WRAP
delete ptr;
END_WRAP
}

CVAPI(ExceptionStatus) tracking_Ptr_Tracker_get(cv::Ptr<cv::Tracker> *ptr, cv::Tracker **returnValue)
{
BEGIN_WRAP
*returnValue = ptr->get();
END_WRAP
}


// TrackerKCF

Expand Down Expand Up @@ -78,72 +40,6 @@ CVAPI(ExceptionStatus) tracking_Ptr_TrackerKCF_get(cv::Ptr<cv::TrackerKCF> *ptr,
END_WRAP
}


// TrackerMIL

CVAPI(ExceptionStatus) tracking_TrackerMIL_create1(cv::Ptr<cv::TrackerMIL> **returnValue)
{
BEGIN_WRAP
const auto p = cv::TrackerMIL::create();
*returnValue = clone(p);
END_WRAP
}

CVAPI(ExceptionStatus) tracking_TrackerMIL_create2(cv::TrackerMIL::Params *parameters, cv::Ptr<cv::TrackerMIL> **returnValue)
{
BEGIN_WRAP
const auto p = cv::TrackerMIL::create(*parameters);
*returnValue = clone(p);
END_WRAP
}

CVAPI(ExceptionStatus) tracking_Ptr_TrackerMIL_delete(cv::Ptr<cv::TrackerMIL> *ptr)
{
BEGIN_WRAP
delete ptr;
END_WRAP
}

CVAPI(ExceptionStatus) tracking_Ptr_TrackerMIL_get(cv::Ptr<cv::TrackerMIL> *ptr, cv::TrackerMIL **returnValue)
{
BEGIN_WRAP
*returnValue = ptr->get();
END_WRAP
}


// TrackerGOTURN

CVAPI(ExceptionStatus) tracking_TrackerGOTURN_create1(cv::Ptr<cv::TrackerGOTURN> **returnValue)
{
BEGIN_WRAP
const auto p = cv::TrackerGOTURN::create();
*returnValue = clone(p);
END_WRAP
}
CVAPI(ExceptionStatus) tracking_TrackerGOTURN_create2(cv::TrackerGOTURN::Params *parameters, cv::Ptr<cv::TrackerGOTURN> **returnValue)
{
BEGIN_WRAP
const auto p = cv::TrackerGOTURN::create(*parameters);
*returnValue = clone(p);
END_WRAP
}

CVAPI(ExceptionStatus) tracking_Ptr_TrackerGOTURN_delete(cv::Ptr<cv::TrackerGOTURN> *ptr)
{
BEGIN_WRAP
delete ptr;
END_WRAP
}

CVAPI(ExceptionStatus) tracking_Ptr_TrackerGOTURN_get(cv::Ptr<cv::TrackerGOTURN> *ptr, cv::TrackerGOTURN **returnValue)
{
BEGIN_WRAP
*returnValue = ptr->get();
END_WRAP
}


// TrackerCSRT

CV_EXTERN_C struct tracker_TrackerCSRT_Params
Expand Down
Loading

0 comments on commit 5921d3f

Please sign in to comment.