/// <summary> /// Extracts the contours of Maximally Stable Extremal Regions /// </summary> /// <param name="image">The image where mser will be extracted from</param> /// <param name="mask">Can be null if not needed. Optional parameter for the region of interest</param> /// <param name="storage">The storage where the contour will be saved</param> /// <returns>The MSER regions</returns> public Seq<Point>[] ExtractContours(IImage image, Image<Gray, Byte> mask, MemStorage storage) { MCvMSERParams p = GetMSERParameters(); IntPtr mserPtr = new IntPtr(); CvInvoke.cvExtractMSER(image.Ptr, mask, ref mserPtr, storage, p); IntPtr[] mserSeq = new Seq<IntPtr>(mserPtr, storage).ToArray(); return Array.ConvertAll<IntPtr, Seq<Point>>(mserSeq, delegate(IntPtr ptr) { return new Seq<Point>(ptr, storage); }); }
/// <summary> /// Get the MSER parameters /// </summary> /// <returns>The MSER parameters</returns> public MCvMSERParams GetMSERParameters() { MCvMSERParams p = new MCvMSERParams(); p.Delta = Delta; p.MaxArea = MaxArea; p.MinArea = MinArea; p.MaxVariation = MaxVariation; p.MinDiversity = MinDiversity; p.MaxEvolution = MaxEvolution; p.AreaThreshold = AreaThreshold; p.MinMargin = MinMargin; p.EdgeBlurSize = EdgeBlurSize; return p; }
/// <summary> /// Create a MSER detector using the specific parameters /// </summary> /// <param name="delta">Use 5 as defalut. In the code, it compares (size_{i}-size_{i-delta})/size_{i-delta}</param> /// <param name="maxArea">Use 60 as default. Prune the area which bigger than max_area</param> /// <param name="minArea">Use 14400 as default. Prune the area which smaller than min_area</param> /// <param name="maxVariation">Use .25f as default. Prune the area have simliar size to its children</param> /// <param name="minDiversity">Use .2f as default. Trace back to cut off mser with diversity < min_diversity</param> /// <param name="maxEvolution">Use 200 as default. For color image, the evolution steps</param> /// <param name="areaThreshold">Use 1.01 as default. The area threshold to cause re-initialize</param> /// <param name="minMargin">Use 0.003 as default. Ignore too small margin</param> /// <param name="edgeBlurSize">Use 5 as default. The aperture size for edge blur</param> public MSERDetector( int delta, int maxArea, int minArea, float maxVariation, float minDiversity, int maxEvolution, double areaThreshold, double minMargin, int edgeBlurSize) { _delta = delta; _maxArea = maxArea; _minArea = minArea; _maxVariation = maxVariation; _minDiversity = minDiversity; _maxEvolution = maxEvolution; _areaThreshold = areaThreshold; _minMargin = minMargin; _edgeBlurSize = edgeBlurSize; MCvMSERParams p = GetMSERParameters(); _featureDetectorPtr = CvMserGetFeatureDetector(ref p); }
public static extern void cvExtractMSER( IntPtr img, IntPtr mask, ref IntPtr contours, IntPtr storage, MCvMSERParams parameters);
internal extern static IntPtr CvMserGetFeatureDetector(ref MCvMSERParams detector);
internal static extern IntPtr CvMserGetFeatureDetector(ref MCvMSERParams detector);