/// <summary> /// Performs non maximum suppression given boxes and corresponding scores. /// </summary> /// <param name="bboxes">a set of bounding boxes to apply NMS.</param> /// <param name="scores">a set of corresponding confidences.</param> /// <param name="scoreThreshold">a threshold used to filter boxes by score.</param> /// <param name="nmsThreshold">a threshold used in non maximum suppression.</param> /// <param name="indices">the kept indices of bboxes after NMS.</param> /// <param name="eta">a coefficient in adaptive threshold formula</param> /// <param name="topK">if `>0`, keep at most @p top_k picked indices.</param> // ReSharper disable once IdentifierTypo public static void NMSBoxes(IEnumerable <Rect2d> bboxes, IEnumerable <float> scores, float scoreThreshold, float nmsThreshold, out int[] indices, float eta = 1.0f, int topK = 0) { if (bboxes == null) { throw new ArgumentNullException(nameof(bboxes)); } if (scores == null) { throw new ArgumentNullException(nameof(scores)); } // ReSharper disable once IdentifierTypo using (var bboxesVec = new VectorOfRect2d(bboxes)) using (var scoresVec = new VectorOfFloat(scores)) using (var indicesVec = new VectorOfInt32()) { NativeMethods.dnn_NMSBoxes_Rect2d( bboxesVec.CvPtr, scoresVec.CvPtr, scoreThreshold, nmsThreshold, indicesVec.CvPtr, eta, topK); indices = indicesVec.ToArray(); } }
/// <summary> /// Returns a reference to a storage for the tracked objects, each object corresponds to one tracker algorithm /// </summary> /// <returns></returns> public Rect2d[] GetObjects() { using var bbVec = new VectorOfRect2d(); NativeMethods.HandleException( NativeMethods.tracking_MultiTracker_getObjects(ptr, bbVec.CvPtr)); GC.KeepAlive(this); return(bbVec.ToArray()); }
/// <summary> /// Update the current tracking status. /// </summary> /// <param name="image">input image</param> /// <param name="boundingBox">the tracking result, represent a list of ROIs of the tracked objects.</param> /// <returns></returns> public bool Update(InputArray image, out Rect2d[] boundingBox) { if (image == null) { throw new ArgumentNullException(nameof(image)); } using var bbVec = new VectorOfRect2d(); NativeMethods.HandleException( NativeMethods.tracking_MultiTracker_update2(ptr, image.CvPtr, bbVec.CvPtr, out var ret)); boundingBox = bbVec.ToArray(); GC.KeepAlive(image); GC.KeepAlive(this); return(ret != 0); }