예제 #1
0
파일: ERFilter.cs 프로젝트: vinchu/emgucv
        /// <summary>
        /// Find groups of Extremal Regions that are organized as text blocks.
        /// </summary>
        /// <param name="image">The image where ER grouping is to be perform on</param>
        /// <param name="channels">Array of single channel images from which the regions were extracted</param>
        /// <param name="erstats">Vector of ER’s retrieved from the ERFilter algorithm from each channel</param>
        /// <param name="groupingTrainedFileName">The XML or YAML file with the classifier model (e.g. trained_classifier_erGrouping.xml)</param>
        /// <param name="minProbability">The minimum probability for accepting a group.</param>
        /// <param name="groupMethods">The grouping methods</param>
        /// <returns>The output of the algorithm that indicates the text regions</returns>
        public static System.Drawing.Rectangle[] ERGrouping(IInputArray image, IInputArrayOfArrays channels, VectorOfERStat[] erstats, GroupingMethod groupMethods = GroupingMethod.OrientationHoriz, String groupingTrainedFileName = null, float minProbability = 0.5f)
        {
            IntPtr[] erstatPtrs = new IntPtr[erstats.Length];

            for (int i = 0; i < erstatPtrs.Length; i++)
            {
                erstatPtrs[i] = erstats[i].Ptr;
            }

            using (VectorOfVectorOfPoint regionGroups = new VectorOfVectorOfPoint())
                using (VectorOfRect groupsBoxes = new VectorOfRect())
                    using (InputArray iaImage = image.GetInputArray())
                        using (InputArray iaChannels = channels.GetInputArray())
                            using (CvString s = (groupingTrainedFileName == null ? new CvString() : new CvString(groupingTrainedFileName)))
                            {
                                GCHandle erstatsHandle = GCHandle.Alloc(erstatPtrs, GCHandleType.Pinned);
                                ContribInvoke.CvERGrouping(
                                    iaImage, iaChannels,
                                    erstatsHandle.AddrOfPinnedObject(), erstatPtrs.Length,
                                    regionGroups, groupsBoxes,
                                    groupMethods,
                                    s, minProbability);

                                erstatsHandle.Free();
                                return(groupsBoxes.ToArray());
                            }
        }
예제 #2
0
 /// <summary>
 /// Creates a KCF Tracker
 /// </summary>
 /// <param name="detectThresh">detection confidence threshold</param>
 /// <param name="sigma">gaussian kernel bandwidth</param>
 /// <param name="lambda">regularization</param>
 /// <param name="interpFactor">linear interpolation factor for adaptation</param>
 /// <param name="outputSigmaFactor">spatial bandwidth (proportional to target)</param>
 /// <param name="pcaLearningRate">compression learning rate</param>
 /// <param name="resize">activate the resize feature to improve the processing speed</param>
 /// <param name="splitCoeff">split the training coefficients into two matrices</param>
 /// <param name="wrapKernel">wrap around the kernel values</param>
 /// <param name="compressFeature">activate the pca method to compress the features</param>
 /// <param name="maxPatchSize">threshold for the ROI size</param>
 /// <param name="compressedSize">feature size after compression</param>
 /// <param name="descPca">compressed descriptors of TrackerKCF::MODE</param>
 /// <param name="descNpca">non-compressed descriptors of TrackerKCF::MODE</param>
 public TrackerKCF(
     float detectThresh      = 0.5f,
     float sigma             = 0.2f,
     float lambda            = 0.01f,
     float interpFactor      = 0.075f,
     float outputSigmaFactor = 1.0f / 16.0f,
     float pcaLearningRate   = 0.15f,
     bool resize             = true,
     bool splitCoeff         = true,
     bool wrapKernel         = false,
     bool compressFeature    = true,
     int maxPatchSize        = 80 *80,
     int compressedSize      = 2,
     Mode descPca            = Mode.CN,
     Mode descNpca           = Mode.GRAY)
 {
     _ptr = ContribInvoke.cveTrackerKCFCreate(
         detectThresh,
         sigma,
         lambda,
         interpFactor,
         outputSigmaFactor,
         pcaLearningRate,
         resize,
         splitCoeff,
         wrapKernel,
         compressFeature,
         maxPatchSize,
         compressedSize,
         descPca,
         descNpca,
         ref _trackerPtr,
         ref _sharedPtr);
 }
예제 #3
0
 /// <summary>
 /// Release the unmanaged memory associated with this multi-tracker.
 /// </summary>
 protected override void DisposeObject()
 {
     if (_ptr != IntPtr.Zero)
     {
         ContribInvoke.cveMultiTrackerRelease(ref _ptr);
     }
 }
예제 #4
0
 /// <summary>
 /// Release the unmanaged memory associated with this Blob
 /// </summary>
 protected override void DisposeObject()
 {
     if (_ptr != IntPtr.Zero)
     {
         ContribInvoke.cveDnnBlobRelease(ref _ptr);
     }
 }
예제 #5
0
파일: Net.cs 프로젝트: formylover/emgucv-1
 /// <summary>
 /// Returns the layer output blob.
 /// </summary>
 /// <param name="outputName">the descriptor of the returning layer output blob.</param>
 /// <returns>The layer output blob.</returns>
 public Blob GetBlob(String outputName)
 {
     using (CvString outputNameStr = new CvString(outputName))
     {
         return(new Blob(ContribInvoke.cveDnnNetGetBlob(_ptr, outputNameStr)));
     }
 }
예제 #6
0
 /// <summary>
 /// Creates a CSRT tracker
 /// </summary>
 public TrackerCSRT(
     bool useHog             = true,
     bool useColorNames      = true,
     bool useGray            = true,
     bool useRgb             = false,
     bool useChannelWeights  = true,
     bool useSegmentation    = true,
     String windowFunction   = null,
     float kaiserAlpha       = 3.75f,
     float chebAttenuation   = 45,
     float templateSize      = 200,
     float gslSigma          = 1.0f,
     float hogOrientations   = 9,
     float hogClip           = 0.2f,
     float padding           = 3.0f,
     float filterLr          = 0.02f,
     float weightsLr         = 0.02f,
     int numHogChannelsUsed  = 18,
     int admmIterations      = 4,
     int histogramBins       = 16,
     float histogramLr       = 0.04f,
     int backgroundRatio     = 2,
     int numberOfScales      = 33,
     float scaleSigmaFactor  = 0.250f,
     float scaleModelMaxArea = 512.0f,
     float scaleLr           = 0.025f,
     float scaleStep         = 1.020f
     )
 {
     using (CvString csWindowFunction = new CvString(windowFunction))
         _ptr = ContribInvoke.cveTrackerCSRTCreate(
             useHog,
             useColorNames,
             useGray,
             useRgb,
             useChannelWeights,
             useSegmentation,
             csWindowFunction,
             kaiserAlpha,
             chebAttenuation,
             templateSize,
             gslSigma,
             hogOrientations,
             hogClip,
             padding,
             filterLr,
             weightsLr,
             numHogChannelsUsed,
             admmIterations,
             histogramBins,
             histogramLr,
             backgroundRatio,
             numberOfScales,
             scaleSigmaFactor,
             scaleModelMaxArea,
             scaleLr,
             scaleStep,
             ref _trackerPtr,
             ref _sharedPtr);
 }
예제 #7
0
파일: ERFilter.cs 프로젝트: vinchu/emgucv
 /// <summary>
 /// Release all the unmanaged memory associate with this ERFilter
 /// </summary>
 protected override void DisposeObject()
 {
     if (_ptr != IntPtr.Zero)
     {
         ContribInvoke.CvERFilterRelease(ref _ptr);
     }
 }
예제 #8
0
        /// <summary>
        /// Returns reference to Mat, containing blob data.
        /// </summary>
        /// <returns>Reference to Mat, containing blob data.</returns>
        public Mat MatRef()
        {
            Mat m = new Mat();

            ContribInvoke.cveDnnBlobMatRef(_ptr, m);
            return(m);
        }
예제 #9
0
 /// <summary>
 /// Release all the unmanaged memory associated with this Boosting Tracker
 /// </summary>
 protected override void DisposeObject()
 {
     if (IntPtr.Zero != _ptr)
     {
         ContribInvoke.cveTrackerBoostingRelease(ref _ptr);
     }
     base.DisposeObject();
 }
예제 #10
0
 /// <summary>
 /// Returns the tracked objects, each object corresponds to one tracker algorithm.
 /// </summary>
 /// <returns>The tracked objects, each object corresponds to one tracker algorithm.</returns>
 public Rectangle[] GetObjects()
 {
     using (VectorOfRect vr = new VectorOfRect())
     {
         ContribInvoke.cveMultiTrackerGetObjects(_ptr, vr);
         return(vr.ToArray());
     }
 }
예제 #11
0
 /// <summary>
 /// Release the unmanaged resources associated with this tracker
 /// </summary>
 protected override void DisposeObject()
 {
     if (IntPtr.Zero != _ptr)
     {
         ContribInvoke.cveTrackerMedianFlowRelease(ref _ptr, ref _sharedPtr);
     }
     base.DisposeObject();
 }
예제 #12
0
 /// <summary>
 /// Create a Boosting Tracker
 /// </summary>
 /// <param name="numClassifiers">The number of classifiers to use in a OnlineBoosting algorithm</param>
 /// <param name="samplerOverlap">Search region parameters to use in a OnlineBoosting algorithm</param>
 /// <param name="samplerSearchFactor">search region parameters to use in a OnlineBoosting algorithm</param>
 /// <param name="iterationInit">The initial iterations</param>
 /// <param name="featureSetNumFeatures">Number of features, a good value would be 10*numClassifiers + iterationInit</param>
 public TrackerBoosting(
     int numClassifiers        = 100,
     float samplerOverlap      = 0.99f,
     float samplerSearchFactor = 1.8f,
     int iterationInit         = 50,
     int featureSetNumFeatures = 100 *10 + 50)
 {
     ContribInvoke.cveTrackerBoostingCreate(numClassifiers, samplerOverlap, samplerSearchFactor, iterationInit, featureSetNumFeatures, ref _trackerPtr, ref _sharedPtr);
 }
예제 #13
0
 /// <summary>
 /// Creates the importer of Caffe framework network.
 /// </summary>
 /// <param name="prototxt">path to the .prototxt file with text description of the network architecture.</param>
 /// <param name="caffeModel">path to the .caffemodel file with learned network.</param>
 /// <returns>The created importer, NULL in failure cases.</returns>
 public static Importer CreateCaffeImporter(String prototxt, String caffeModel)
 {
     using (CvString prototxtStr = new CvString(prototxt))
         using (CvString caffeModelStr = new CvString(caffeModel))
         {
             IntPtr result = ContribInvoke.cveDnnCreateCaffeImporter(prototxtStr, caffeModelStr);
             return(result == IntPtr.Zero ? null : new Importer(result));
         }
 }
예제 #14
0
 /// <summary>
 /// Release all the unmanaged memory associated with this background model.
 /// </summary>
 protected override void DisposeObject()
 {
     if (IntPtr.Zero != _ptr)
     {
         ContribInvoke.cveBackgroundSubtractorGSOCRelease(ref _ptr);
         _backgroundSubtractorPtr = IntPtr.Zero;
         _algorithmPtr            = IntPtr.Zero;
     }
 }
예제 #15
0
 /// <summary>Create a median flow tracker</summary>
 /// <param name="pointsInGrid">Points in grid, use 10 for default.</param>
 /// <param name="winSize">Win size, use (3, 3) for default</param>
 /// <param name="maxLevel">Max level, use 5 for default.</param>
 /// <param name="termCriteria">Termination criteria, use count = 20 and eps = 0.3 for default</param>
 /// <param name="winSizeNCC">win size NCC, use (30, 30) for default</param>
 /// <param name="maxMedianLengthOfDisplacementDifference">Max median length of displacement difference</param>
 public TrackerMedianFlow(
     int pointsInGrid,
     Size winSize,
     int maxLevel,
     MCvTermCriteria termCriteria,
     Size winSizeNCC,
     double maxMedianLengthOfDisplacementDifference = 10)
 {
     ContribInvoke.cveTrackerMedianFlowCreate(pointsInGrid, ref winSize, maxLevel, ref termCriteria, ref winSizeNCC, maxMedianLengthOfDisplacementDifference, ref _trackerPtr, ref _sharedPtr);
 }
예제 #16
0
파일: ERFilter.cs 프로젝트: vinchu/emgucv
 /// <summary>
 /// Create an Extremal Region Filter for the 1st stage classifier of N&amp;M algorithm
 /// </summary>
 /// <param name="classifierFileName">The file name of the classifier</param>
 /// <param name="thresholdDelta">Threshold step in subsequent thresholds when extracting the component tree.</param>
 /// <param name="minArea">The minimum area (% of image size) allowed for retreived ER’s.</param>
 /// <param name="maxArea">The maximum area (% of image size) allowed for retreived ER’s.</param>
 /// <param name="minProbability">The minimum probability P(er|character) allowed for retreived ER’s.</param>
 /// <param name="nonMaxSuppression">Whenever non-maximum suppression is done over the branch probabilities.</param>
 /// <param name="minProbabilityDiff">The minimum probability difference between local maxima and local minima ERs.</param>
 public ERFilterNM1(
     String classifierFileName,
     int thresholdDelta       = 1,
     float minArea            = 0.00025f,
     float maxArea            = 0.13f,
     float minProbability     = 0.4f,
     bool nonMaxSuppression   = true,
     float minProbabilityDiff = 0.1f)
 {
     using (CvString s = new CvString(classifierFileName))
         _ptr = ContribInvoke.CvERFilterNM1Create(s, thresholdDelta, minArea, maxArea, minProbability, nonMaxSuppression, minProbabilityDiff);
 }
예제 #17
0
        /// <summary>
        /// Predict the label of the image
        /// </summary>
        /// <param name="image">The image where prediction will be based on</param>
        /// <returns>The prediction label</returns>
        public PredictionResult Predict(IInputArray image)
        {
            int    label    = -1;
            double distance = -1;

            using (InputArray iaImage = image.GetInputArray())
                ContribInvoke.CvFaceRecognizerPredict(_ptr, iaImage, ref label, ref distance);
            return(new PredictionResult()
            {
                Label = label, Distance = distance
            });
        }
예제 #18
0
 public BackgroundSubtractorCNT(
     int minPixelStability = 15,
     bool useHistory       = true,
     int maxPixelStability = 15 * 60,
     bool isParallel       = true)
 {
     _ptr = ContribInvoke.cveBackgroundSubtractorCNTCreate(
         minPixelStability,
         useHistory,
         maxPixelStability,
         isParallel,
         ref _backgroundSubtractorPtr,
         ref _algorithmPtr);
 }
예제 #19
0
 /// <summary>
 /// Creates an instance of BackgroundSubtractorGSOC algorithm.
 /// </summary>
 /// <param name="mc">Whether to use camera motion compensation.</param>
 /// <param name="nSamples">Number of samples to maintain at each point of the frame.</param>
 /// <param name="replaceRate">Probability of replacing the old sample - how fast the model will update itself.</param>
 /// <param name="propagationRate">Probability of propagating to neighbors.</param>
 /// <param name="hitsThreshold">How many positives the sample must get before it will be considered as a possible replacement.</param>
 /// <param name="alpha">Scale coefficient for threshold.</param>
 /// <param name="beta">Bias coefficient for threshold.</param>
 /// <param name="blinkingSupressionDecay">Blinking supression decay factor.</param>
 /// <param name="blinkingSupressionMultiplier">Blinking supression multiplier.</param>
 /// <param name="noiseRemovalThresholdFacBG">Strength of the noise removal for background points.</param>
 /// <param name="noiseRemovalThresholdFacFG">Strength of the noise removal for foreground points.</param>
 public BackgroundSubtractorGSOC(
     BackgroundSubtractorLSBP.CameraMotionCompensation mc = BackgroundSubtractorLSBP.CameraMotionCompensation.None,
     int nSamples                       = 20,
     float replaceRate                  = 0.003f,
     float propagationRate              = 0.01f,
     int hitsThreshold                  = 32,
     float alpha                        = 0.01f,
     float beta                         = 0.0022f,
     float blinkingSupressionDecay      = 0.1f,
     float blinkingSupressionMultiplier = 0.1f,
     float noiseRemovalThresholdFacBG   = 0.0004f,
     float noiseRemovalThresholdFacFG   = 0.0008f)
 {
     _ptr = ContribInvoke.cveBackgroundSubtractorGSOCCreate(mc, nSamples, replaceRate, propagationRate, hitsThreshold, alpha, beta, blinkingSupressionDecay, blinkingSupressionMultiplier, noiseRemovalThresholdFacBG, noiseRemovalThresholdFacFG, ref _backgroundSubtractorPtr, ref _algorithmPtr);
 }
예제 #20
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="samplerInitInRadius">radius for gathering positive instances during init</param>
 /// <param name="samplerInitMaxNegNum">negative samples to use during init</param>
 /// <param name="samplerSearchWinSize">size of search window</param>
 /// <param name="samplerTrackInRadius">radius for gathering positive instances during tracking</param>
 /// <param name="samplerTrackMaxPosNum">positive samples to use during tracking</param>
 /// <param name="samplerTrackMaxNegNum">negative samples to use during tracking</param>
 /// <param name="featureSetNumFeatures">features</param>
 public TrackerMIL(
     float samplerInitInRadius,
     int samplerInitMaxNegNum,
     float samplerSearchWinSize,
     float samplerTrackInRadius,
     int samplerTrackMaxPosNum,
     int samplerTrackMaxNegNum,
     int featureSetNumFeatures)
 {
     ContribInvoke.cveTrackerMILCreate(
         samplerInitInRadius,
         samplerInitMaxNegNum,
         samplerSearchWinSize,
         samplerTrackInRadius,
         samplerTrackMaxPosNum,
         samplerTrackMaxNegNum,
         featureSetNumFeatures, ref _trackerPtr);
 }
예제 #21
0
 /// <summary>
 /// Creates a MIL Tracker
 /// </summary>
 /// <param name="samplerInitInRadius">radius for gathering positive instances during init</param>
 /// <param name="samplerInitMaxNegNum">negative samples to use during init</param>
 /// <param name="samplerSearchWinSize">size of search window</param>
 /// <param name="samplerTrackInRadius">radius for gathering positive instances during tracking</param>
 /// <param name="samplerTrackMaxPosNum">positive samples to use during tracking</param>
 /// <param name="samplerTrackMaxNegNum">negative samples to use during tracking</param>
 /// <param name="featureSetNumFeatures">features</param>
 public TrackerMIL(
     float samplerInitInRadius  = 3.0f,
     int samplerInitMaxNegNum   = 65,
     float samplerSearchWinSize = 25.0f,
     float samplerTrackInRadius = 4.0f,
     int samplerTrackMaxPosNum  = 100000,
     int samplerTrackMaxNegNum  = 65,
     int featureSetNumFeatures  = 250)
 {
     ContribInvoke.cveTrackerMILCreate(
         samplerInitInRadius,
         samplerInitMaxNegNum,
         samplerSearchWinSize,
         samplerTrackInRadius,
         samplerTrackMaxPosNum,
         samplerTrackMaxNegNum,
         featureSetNumFeatures,
         ref _trackerPtr,
         ref _sharedPtr);
 }
예제 #22
0
 /// <summary>
 /// Initialize the tracker with a know bounding box that surrounding the target.
 /// </summary>
 /// <param name="image">The initial frame</param>
 /// <param name="boundingBox">The initial bounding box</param>
 /// <returns></returns>
 public bool Init(Mat image, Rectangle boundingBox)
 {
     return(ContribInvoke.cveTrackerInit(_trackerPtr, image, ref boundingBox));
 }
예제 #23
0
 /// <summary>
 /// Create a LBPH face recognizer
 /// </summary>
 /// <param name="radius">Radius</param>
 /// <param name="neighbors">Neighbors</param>
 /// <param name="gridX">Grid X</param>
 /// <param name="gridY">Grid Y</param>
 /// <param name="threshold">The distance threshold</param>
 public LBPHFaceRecognizer(int radius       = 1, int neighbors = 8, int gridX = 8, int gridY = 8,
                           double threshold = Double.MaxValue)
 {
     _ptr = ContribInvoke.CvLBPHFaceRecognizerCreate(radius, neighbors, gridX, gridY, threshold);
 }
예제 #24
0
 /// <summary>
 /// Create a MOSSE tracker
 /// </summary>
 public TrackerMOSSE()
 {
     _ptr = ContribInvoke.cveTrackerMOSSECreate(ref _trackerPtr, ref _sharedPtr);
 }
예제 #25
0
 /// <summary>
 /// Create a GOTURN tracker
 /// </summary>
 public TrackerGOTURN()
 {
     _ptr = ContribInvoke.cveTrackerGOTURNCreate(ref _trackerPtr, ref _sharedPtr);
 }
예제 #26
0
 /// <summary>
 /// Updates a FaceRecognizer with given data and associated labels.
 /// </summary>
 /// <param name="images">The training images, that means the faces you want to learn. The data has to be given as a VectorOfMat.</param>
 /// <param name="labels">The labels corresponding to the images</param>
 public void Update(IInputArray images, IInputArray labels)
 {
     using (InputArray iaImages = images.GetInputArray())
         using (InputArray iaLabels = labels.GetInputArray())
             ContribInvoke.CvFaceRecognizerUpdate(_ptr, iaImages, iaLabels);
 }
예제 #27
0
 /// <summary>
 /// Train the face recognizer with the specific images and labels
 /// </summary>
 /// <param name="images">The images used in the training. This can be a VectorOfMat</param>
 /// <param name="labels">The labels of the images. This can be a VectorOfInt</param>
 public void Train(IInputArray images, IInputArray labels)
 {
     using (InputArray iaImage = images.GetInputArray())
         using (InputArray iaLabels = labels.GetInputArray())
             ContribInvoke.CvFaceRecognizerTrain(_ptr, iaImage, iaLabels);
 }
예제 #28
0
 /// <summary>
 /// Update the tracker, find the new most likely bounding box for the target.
 /// </summary>
 /// <param name="image">The current frame</param>
 /// <param name="boundingBox">The bounding box that represent the new target location, if true was returned, not modified otherwise</param>
 /// <returns>True means that target was located and false means that tracker cannot locate target in current frame. Note, that latter does not imply that tracker has failed, maybe target is indeed missing from the frame (say, out of sight)</returns>
 public bool Update(Mat image, out Rectangle boundingBox)
 {
     boundingBox = new Rectangle();
     return(ContribInvoke.cveTrackerUpdate(_trackerPtr, image, ref boundingBox));
 }
예제 #29
0
 /// <summary>
 /// Create a FisherFaceRecognizer
 /// </summary>
 /// <param name="numComponents">The number of components</param>
 /// <param name="threshold">The distance threshold</param>
 public FisherFaceRecognizer(int numComponents = 0, double threshold = double.MaxValue)
 {
     _ptr = ContribInvoke.CvFisherFaceRecognizerCreate(numComponents, threshold);
 }
예제 #30
0
 /// <summary>
 /// Load the FaceRecognizer from the file
 /// </summary>
 /// <param name="fileName">The file where the FaceRecognizer will be loaded from</param>
 public void Load(String fileName)
 {
     using (CvString s = new CvString(fileName))
         ContribInvoke.CvFaceRecognizerLoad(_ptr, s);
 }