/// <summary> /// Groups the object candidate rectangles. /// </summary> /// <param name="rectList"></param> /// <param name="rejectLevels"></param> /// <param name="levelWeights"></param> /// <param name="groupThreshold"></param> /// <param name="eps"></param> public static void GroupRectangles(IList <Rect> rectList, out int[] rejectLevels, out double[] levelWeights, int groupThreshold, double eps = 0.2) { if (rectList == null) { throw new ArgumentNullException(nameof(rectList)); } using (var rectListVec = new VectorOfRect(rectList)) using (var rejectLevelsVec = new VectorOfInt32()) using (var levelWeightsVec = new VectorOfDouble()) { NativeMethods.objdetect_groupRectangles4(rectListVec.CvPtr, rejectLevelsVec.CvPtr, levelWeightsVec.CvPtr, groupThreshold, eps); ClearAndAddRange(rectList, rectListVec.ToArray()); rejectLevels = rejectLevelsVec.ToArray(); levelWeights = levelWeightsVec.ToArray(); } }
/// <summary> /// /// </summary> /// <param name="rectList"></param> /// <param name="foundWeights"></param> /// <param name="foundScales"></param> /// <param name="detectThreshold"></param> /// <param name="winDetSize"></param> public static void GroupRectanglesMeanshift(IList <Rect> rectList, out double[] foundWeights, out double[] foundScales, double detectThreshold = 0.0, Size?winDetSize = null) { if (rectList == null) { throw new ArgumentNullException(nameof(rectList)); } Size winDetSize0 = winDetSize.GetValueOrDefault(new Size(64, 128)); using (var rectListVec = new VectorOfRect(rectList)) using (var foundWeightsVec = new VectorOfDouble()) using (var foundScalesVec = new VectorOfDouble()) { NativeMethods.objdetect_groupRectangles_meanshift( rectListVec.CvPtr, foundWeightsVec.CvPtr, foundScalesVec.CvPtr, detectThreshold, winDetSize0); ClearAndAddRange(rectList, rectListVec.ToArray()); foundWeights = foundWeightsVec.ToArray(); foundScales = foundScalesVec.ToArray(); } }
/// <summary> /// Detects objects of different sizes in the input image. The detected objects are returned as a list of rectangles. /// </summary> /// <param name="image">Matrix of the type CV_8U containing an image where objects are detected.</param> /// <param name="rejectLevels"></param> /// <param name="levelWeights"></param> /// <param name="scaleFactor">Parameter specifying how much the image size is reduced at each image scale.</param> /// <param name="minNeighbors">Parameter specifying how many neighbors each candidate rectangle should have to retain it.</param> /// <param name="flags">Parameter with the same meaning for an old cascade as in the function cvHaarDetectObjects. /// It is not used for a new cascade.</param> /// <param name="minSize">Minimum possible object size. Objects smaller than that are ignored.</param> /// <param name="maxSize">Maximum possible object size. Objects larger than that are ignored.</param> /// <param name="outputRejectLevels"></param> /// <returns>Vector of rectangles where each rectangle contains the detected object.</returns> public virtual Rect[] DetectMultiScale( Mat image, out int[] rejectLevels, out double[] levelWeights, double scaleFactor = 1.1, int minNeighbors = 3, HaarDetectionType flags = HaarDetectionType.Zero, Size?minSize = null, Size?maxSize = null, bool outputRejectLevels = false) { if (disposed) { throw new ObjectDisposedException("CascadeClassifier"); } if (image == null) { throw new ArgumentNullException(nameof(image)); } image.ThrowIfDisposed(); Size minSize0 = minSize.GetValueOrDefault(new Size()); Size maxSize0 = maxSize.GetValueOrDefault(new Size()); using (var objectsVec = new VectorOfRect()) using (var rejectLevelsVec = new VectorOfInt32()) using (var levelWeightsVec = new VectorOfDouble()) { NativeMethods.objdetect_CascadeClassifier_detectMultiScale( ptr, image.CvPtr, objectsVec.CvPtr, rejectLevelsVec.CvPtr, levelWeightsVec.CvPtr, scaleFactor, minNeighbors, (int)flags, minSize0, maxSize0, outputRejectLevels ? 1 : 0); rejectLevels = rejectLevelsVec.ToArray(); levelWeights = levelWeightsVec.ToArray(); return(objectsVec.ToArray()); } }