Beispiel #1
0
        /// <summary>
        /// Groups the object candidate rectangles.
        /// </summary>
        /// <param name="rectList"> Input/output vector of rectangles. Output vector includes retained and grouped rectangles.</param>
        /// <param name="groupThreshold">Minimum possible number of rectangles minus 1. The threshold is used in a group of rectangles to retain it.</param>
        /// <param name="eps"></param>
        public static void GroupRectangles(IList <Rect> rectList, int groupThreshold, double eps = 0.2)
        {
            if (rectList == null)
            {
                throw new ArgumentNullException(nameof(rectList));
            }

            using (var rectListVec = new VectorOfRect(rectList))
            {
                NativeMethods.objdetect_groupRectangles1(rectListVec.CvPtr, groupThreshold, eps);
                ClearAndAddRange(rectList, rectListVec.ToArray());
            }
        }
Beispiel #2
0
        /// <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();
                    }
        }
Beispiel #3
0
        /// <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());
                    }
        }
Beispiel #5
0
        /// <summary>
        /// Splits a motion history image into a few parts corresponding to separate independent motions
        /// (for example, left hand, right hand).
        /// </summary>
        /// <param name="mhi">Motion history image.</param>
        /// <param name="segmask">Image where the found mask should be stored, single-channel, 32-bit floating-point.</param>
        /// <param name="boundingRects">Vector containing ROIs of motion connected components.</param>
        /// <param name="timestamp">Current time in milliseconds or other units.</param>
        /// <param name="segThresh">Segmentation threshold that is recommended to be equal to the interval between motion history “steps” or greater.</param>
        public static void SegmentMotion(
            InputArray mhi, OutputArray segmask,
            out Rect[] boundingRects,
            double timestamp, double segThresh)
        {
            if (mhi == null)
            {
                throw new ArgumentNullException("mhi");
            }
            if (segmask == null)
            {
                throw new ArgumentNullException("segmask");
            }
            mhi.ThrowIfDisposed();
            segmask.ThrowIfNotReady();

            using (var br = new VectorOfRect())
            {
                NativeMethods.video_segmentMotion(
                    mhi.CvPtr, segmask.CvPtr, br.CvPtr, timestamp, segThresh);
                boundingRects = br.ToArray();
            }
            segmask.Fix();
        }