@ -17,81 +17,117 @@ using System.Drawing;
namespace Emgu.CV.Tracking
{
/// <summary>
/// Long-term tracker
/// </summary>
public abstract class Tracker : UnmanagedObject
{
private IntPtr _trackerPtr ;
/ *
/// <summary>
/// Creates a tracker by its name.
/// </summary>
/// <param name="trackerType">Tracker type, The following detector types are supported: "MIL" – TrackerMIL; "BOOSTING" – TrackerBoosting</param>
public Tracker ( String trackerType )
{
using ( CvString trackerTypeStr = new CvString ( trackerType ) )
_ptr = ContribInvoke . cveTrackerCreate ( trackerTypeStr ) ;
} * /
/// <summary>
/// Initialize the tracker with a know bounding box that surrounding the target.
/// </summary>
/// <param name="image">The initial frame</param>
/// <param name="boundingBox">The initial bounding box</param>
/// <returns></returns>
public bool Init ( Mat image , Rectangle boundingBox )
{
return ContribInvoke . cveTrackerInit ( _trackerPtr , image , ref boundingBox ) ;
}
/// <summary>
/// Update the tracker, find the new most likely bounding box for the target.
/// </summary>
/// <param name="image">The current frame</param>
/// <param name="boundingBox">The bounding box that represent the new target location, if true was returned, not modified otherwise</param>
/// <returns>True means that target was located and false means that tracker cannot locate target in current frame. Note, that latter does not imply that tracker has failed, maybe target is indeed missing from the frame (say, out of sight)</returns>
public bool Update ( Mat image , out Rectangle boundingBox )
{
boundingBox = new Rectangle ( ) ;
return ContribInvoke . cveTrackerUpdate ( _trackerPtr , image , ref boundingBox ) ;
}
/// <summary>
/// Release the unmanaged memory associated with this tracker
/// </summary>
protected override void DisposeObject ( )
{
public class TrackerBoosting : Tracker
{
/// <summary>
///
/// </summary>
/// <param name="numClassifiers">The number of classifiers to use in a OnlineBoosting algorithm</param>
/// <param name="samplerOverlap">Search region parameters to use in a OnlineBoosting algorithm</param>
/// <param name="samplerSearchFactor">search region parameters to use in a OnlineBoosting algorithm</param>
/// <param name="iterationInit">The initial iterations</param>
/// <param name="featureSetNumFeatures">Number of features, a good value would be 10*numClassifiers + iterationInit</param>
public TrackerBoosting ( int numClassifiers = 1 0 0 , float samplerOverlap = 0.99f , float samplerSearchFactor = 1.8f , int iterationInit = 5 0 , int featureSetNumFeatures = 1 0 0 * 1 0 + 5 0 )
{
ContribInvoke . cveTrackerBoostingCreate ( numClassifiers , samplerOverlap , samplerSearchFactor , iterationInit , featureSetNumFeatures , ref _trackerPtr ) ;
}
protected override void DisposeObject ( )
{
base . DisposeObject ( ) ;
ContribInvoke . cveTrackerBoostingRelease ( ref _ptr ) ;
}
}
public class TrackerMedianFlow : Tracker
{
public TrackerMedianFlow ( Params parameters )
{
ContribInvoke . cveTrackerMedianFlowCreate ( ref parameters , ref _trackerPtr ) ;
}
protected override void DisposeObject ( )
{
base . DisposeObject ( ) ;
ContribInvoke . cveTrackerMedianFlowRelease ( ref _ptr ) ;
}
}
/// <summary>
/// Long-term tracker
/// </summary>
public abstract class Tracker : UnmanagedObject
{
protected IntPtr _trackerPtr ;
/// <summary>
/// Initialize the tracker with a know bounding box that surrounding the target.
/// </summary>
/// <param name="image">The initial frame</param>
/// <param name="boundingBox">The initial bounding box</param>
/// <returns></returns>
public bool Init ( Mat image , Rectangle boundingBox )
{
return ContribInvoke . cveTrackerInit ( _trackerPtr , image , ref boundingBox ) ;
}
/// <summary>
/// Update the tracker, find the new most likely bounding box for the target.
/// </summary>
/// <param name="image">The current frame</param>
/// <param name="boundingBox">The bounding box that represent the new target location, if true was returned, not modified otherwise</param>
/// <returns>True means that target was located and false means that tracker cannot locate target in current frame. Note, that latter does not imply that tracker has failed, maybe target is indeed missing from the frame (say, out of sight)</returns>
public bool Update ( Mat image , out Rectangle boundingBox )
{
boundingBox = new Rectangle ( ) ;
return ContribInvoke . cveTrackerUpdate ( _trackerPtr , image , ref boundingBox ) ;
}
/// <summary>
/// Release the unmanaged memory associated with this tracker
/// </summary>
protected override void DisposeObject ( )
{
_trackerPtr = IntPtr . Zero ;
/ *
if ( _ptr ! = IntPtr . Zero )
ContribInvoke . cveTrackerRelease ( ref _ptr ) ; * /
}
}
}
}
}
namespace Emgu.CV
{
public static partial class ContribInvoke
{
[DllImport(CvInvoke.ExternLibrary, CallingConvention = CvInvoke.CvCallingConvention)]
internal static extern IntPtr cveTrackerCreate ( IntPtr trackerType ) ;
[DllImport(CvInvoke.ExternLibrary, CallingConvention = CvInvoke.CvCallingConvention)]
[return:MarshalAs(CvInvoke.BoolMarshalType)]
internal static extern bool cveTrackerInit ( IntPtr tracker , IntPtr image , ref Rectangle boundingBox ) ;
[DllImport(CvInvoke.ExternLibrary, CallingConvention = CvInvoke.CvCallingConvention)]
[return: MarshalAs(CvInvoke.BoolMarshalType)]
internal static extern bool cveTrackerUpdate ( IntPtr tracker , IntPtr image , ref Rectangle boundingBox ) ;
[DllImport(CvInvoke.ExternLibrary, CallingConvention = CvInvoke.CvCallingConvention)]
internal static extern void cveTrackerRelease ( ref IntPtr tracker ) ;
}
public static partial class ContribInvoke
{
//[DllImport(CvInvoke.ExternLibrary, CallingConvention = CvInvoke.CvCallingConvention)]
//internal static extern IntPtr cveTrackerCreate(IntPtr trackerType);
[DllImport(CvInvoke.ExternLibrary, CallingConvention = CvInvoke.CvCallingConvention)]
[return: MarshalAs(CvInvoke.BoolMarshalType)]
internal static extern bool cveTrackerInit ( IntPtr tracker , IntPtr image , ref Rectangle boundingBox ) ;
[DllImport(CvInvoke.ExternLibrary, CallingConvention = CvInvoke.CvCallingConvention)]
[return: MarshalAs(CvInvoke.BoolMarshalType)]
internal static extern bool cveTrackerUpdate ( IntPtr tracker , IntPtr image , ref Rectangle boundingBox ) ;
//[DllImport(CvInvoke.ExternLibrary, CallingConvention = CvInvoke.CvCallingConvention)]
//internal static extern void cveTrackerRelease(ref IntPtr tracker);
[DllImport(CvInvoke.ExternLibrary, CallingConvention = CvInvoke.CvCallingConvention)]
internal static extern IntPtr cveTrackerMedianFlowCreate ( int pointsInGrid , ref Size winSize , int maxLevel , ref CvTermCriteria termCriteria , ref Size winSizeNCC , double maxMedianLengthOfDisplacementDifference , ref IntPtr tracker ) ;
[DllImport(CvInvoke.ExternLibrary, CallingConvention = CvInvoke.CvCallingConvention)]
internal static extern void cveTrackerMedianFlowRelease ( ref IntPtr tracker ) ;
[DllImport(CvInvoke.ExternLibrary, CallingConvention = CvInvoke.CvCallingConvention)]
internal static extern IntPtr cveTrackerBoostingCreate ( int numClassifiers , float samplerOverlap , float samplerSearchFactor , int iterationInit , int featureSetNumFeatures , ref IntPtr tracker ) ;
[DllImport(CvInvoke.ExternLibrary, CallingConvention = CvInvoke.CvCallingConvention)]
internal static extern void cveTrackerBoostingRelease ( ref IntPtr tracker ) ;
}
}
#endif