Exemple #1
0
 /// <summary>
 /// Release all the unmanaged memory associated with this cascade classifier
 /// </summary>
 protected override void DisposeObject()
 {
     if (_ptr != IntPtr.Zero)
     {
         SoftCascadeInvoke.cudaSoftCascadeDetectorRelease(ref _ptr);
     }
 }
Exemple #2
0
        /// <summary>
        /// Apply cascade to an input frame and return the array of decection objects.
        /// </summary>
        /// <param name="image">A frame on which detector will be applied.</param>
        /// <param name="rois">A regions of interests mask generated by genRoi. Only the objects that fall into one of the regions will be returned.</param>
        /// <param name="stream">Use a Stream to call the function asynchronously (non-blocking) or null to call the function synchronously (blocking).</param>
        /// <returns>An array of decection objects</returns>
        public GpuMat Detect(CudaImage <Bgr, Byte> image, GpuMat <int> rois, Emgu.CV.Cuda.Stream stream = null)
        {
            GpuMat result = new GpuMat();

            SoftCascadeInvoke.cudaSoftCascadeDetectorDetect(_ptr, image, rois, result, stream);
            return(result);
        }
Exemple #3
0
 /// <summary>
 /// Create a soft (stageless) cascaded detector.
 /// </summary>
 /// <param name="trainedCascadeFileName">File name of the trained soft cascade detector</param>
 /// <param name="minScale">A minimum scale relative to the original size of the image on which cascade will be applied. Use 0.4 for default.</param>
 /// <param name="maxScale">A maximum scale relative to the original size of the image on which cascade will be applied. Use 5.0 for default</param>
 /// <param name="scales">Number of scales from minScale to maxScale. Use 55 for default</param>
 /// <param name="flags">An extra tuning flags.</param>
 public CudaSoftCascadeDetector(String trainedCascadeFileName,
                                double minScale = 0.4, double maxScale = 5, int scales = 55,
                                SoftCascadeDetector.RejectionCriteria flags = SoftCascadeDetector.RejectionCriteria.NoReject)
 {
     using (CvString s = new CvString(trainedCascadeFileName))
         _ptr = SoftCascadeInvoke.cudaSoftCascadeDetectorCreate(s, minScale, maxScale, scales, flags);
 }
Exemple #4
0
        /// <summary>
        /// Apply cascade to an input frame and return the vector of Detection objects.
        /// </summary>
        /// <param name="image">A frame on which detector will be applied.</param>
        /// <param name="rois">A vector of regions of interest. Only the objects that fall into one of the regions will be returned.</param>
        /// <returns>An output array of Detections.</returns>
        public Detection[] Detect(IInputArray image, Rectangle[] rois = null)
        {
            using (VectorOfRect roiRects = new VectorOfRect())
                using (VectorOfRect regions = new VectorOfRect())
                    using (VectorOfFloat confidents = new VectorOfFloat())
                    {
                        IntPtr roisPtr;
                        if (rois == null || rois.Length == 0)
                        {
                            roisPtr = IntPtr.Zero;
                        }
                        else
                        {
                            roiRects.Push(rois);
                            roisPtr = roiRects.Ptr;
                        }
                        using (InputArray iaImage = image.GetInputArray())
                            SoftCascadeInvoke.cveSoftCascadeDetectorDetect(_ptr, iaImage, roisPtr, regions, confidents);

                        if (regions.Size == 0)
                        {
                            return(new Detection[0]);
                        }
                        else
                        {
                            Rectangle[] regionArr    = regions.ToArray();
                            float[]     confidentArr = confidents.ToArray();
                            Detection[] results      = new Detection[regionArr.Length];
                            for (int i = 0; i < results.Length; i++)
                            {
                                results[i] = new Detection(regionArr[i], confidentArr[i]);
                            }
                            return(results);
                        }
                    }
        }
Exemple #5
0
 /// <summary>
 /// Create a soft (stageless) cascaded detector.
 /// </summary>
 /// <param name="trainedCascadeFileName">File name of the trained soft cascade detector</param>
 /// <param name="minScale">A minimum scale relative to the original size of the image on which cascade will be applied.</param>
 /// <param name="maxScale">A maximum scale relative to the original size of the image on which cascade will be applied.</param>
 /// <param name="scales">Number of scales from minScale to maxScale.</param>
 /// <param name="rejCriteria">Algorithm used for non maximum suppression.</param>
 public SoftCascadeDetector(String trainedCascadeFileName, double minScale = 0.4, double maxScale = 5.0, int scales = 55, RejectionCriteria rejCriteria = RejectionCriteria.NoReject)
 {
     using (CvString s = new CvString(trainedCascadeFileName))
         _ptr = SoftCascadeInvoke.cveSoftCascadeDetectorCreate(s, minScale, maxScale, scales, rejCriteria);
 }