Beispiel #1
0
        /// <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 = 0,
            Size?minSize            = null,
            Size?maxSize            = null,
            bool outputRejectLevels = false)
        {
            ThrowIfDisposed();
            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_detectMultiScale2(
                            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 #2
0
        /// <summary>
        /// Returns a list of the leading edge ID connected to each triangle.
        /// The function gives one edge ID for each triangle.
        /// </summary>
        /// <returns>Output vector.</returns>
        public int[] GetLeadingEdgeList()
        {
            ThrowIfDisposed();

            using var leadingEdgeList = new VectorOfInt32();
            NativeMethods.HandleException(
                NativeMethods.imgproc_Subdiv2D_getLeadingEdgeList(ptr, leadingEdgeList.CvPtr));

            GC.KeepAlive(this);
            return(leadingEdgeList.ToArray());
        }
        /// <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="weights"></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">Relative difference between sides of the rectangles to merge them into a group.</param>
        public static void GroupRectangles(IList <Rect> rectList, out int[] weights, int groupThreshold, double eps = 0.2)
        {
            if (rectList == null)
            {
                throw new ArgumentNullException(nameof(rectList));
            }

            using (var rectListVec = new VectorOfRect(rectList))
                using (var weightsVec = new VectorOfInt32())
                {
                    NativeMethods.objdetect_groupRectangles2(rectListVec.CvPtr, weightsVec.CvPtr, groupThreshold, eps);
                    ClearAndAddRange(rectList, rectListVec.ToArray());
                    weights = weightsVec.ToArray();
                }
        }
Beispiel #4
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 #5
0
            /// <summary>
            ///
            /// </summary>
            /// <param name="image">Input image CV_8UC1 or CV_8UC3 with a single letter</param>
            /// <param name="classes">The classifier returns the character class categorical label, or list of class labels, to which the input image corresponds</param>
            /// <param name="confidences">The classifier returns the probability of the input image corresponding to each classes in out_class</param>
            public void Eval(InputArray image, out int[] classes, out double[] confidences)
            {
                if (image == null)
                {
                    throw new ArgumentNullException("nameof(image)");
                }
                image.ThrowIfDisposed();

                using (var vecClass = new VectorOfInt32())
                    using (var vecConfd = new VectorOfDouble())
                    {
                        NativeMethods.text_OCRHMMDecoder_ClassifierCallback_eval(ptr, image.CvPtr, vecClass.CvPtr, vecConfd.CvPtr);

                        classes     = vecClass.ToArray();
                        confidences = vecConfd.ToArray();
                    }

                GC.KeepAlive(image);
            }
        /// <summary>
        /// Groups the object candidate rectangles.
        /// </summary>
        /// <param name="rectList"></param>
        /// <param name="groupThreshold"></param>
        /// <param name="eps"></param>
        /// <param name="weights"></param>
        /// <param name="levelWeights"></param>
        public static void GroupRectangles(IList <Rect> rectList, int groupThreshold, double eps, out int[] weights, out double[] levelWeights)
        {
            if (rectList == null)
            {
                throw new ArgumentNullException(nameof(rectList));
            }

            using var rectListVec     = new VectorOfRect(rectList);
            using var weightsVec      = new VectorOfInt32();
            using var levelWeightsVec = new VectorOfDouble();

            NativeMethods.HandleException(
                NativeMethods.objdetect_groupRectangles3(
                    rectListVec.CvPtr, groupThreshold, eps, weightsVec.CvPtr, levelWeightsVec.CvPtr));

            ClearAndAddRange(rectList, rectListVec.ToArray());
            weights      = weightsVec.ToArray();
            levelWeights = levelWeightsVec.ToArray();
        }
Beispiel #7
0
        /// <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 = 0,
            Size?minSize            = null,
            Size?maxSize            = null,
            bool outputRejectLevels = false)
        {
            if (disposed)
            {
                throw new ObjectDisposedException("CascadeClassifier");
            }
            if (image == null)
            {
                throw new ArgumentNullException("nameof(image)");
            }
            _stopWatch.Start();
            image.ThrowIfDisposed();
            _stopWatch.Stop();
            Debug.Log("FF_throw: " + _stopWatch.ElapsedMilliseconds + "ms");
            _stopWatch.Reset();

            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_detectMultiScale2(
                            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());
                    }
        }