/// <summary> /// Extracts text regions from image /// </summary> /// <param name="image">Source image where text blocks needs to be extracted from. Should be CV_8UC3 (color)</param> /// <param name="er_filter1">Extremal Region Filter for the 1st stage classifier of N&M algorithm [Neumann12]</param> /// <param name="er_filter2">Extremal Region Filter for the 2nd stage classifier of N&M algorithm [Neumann12]</param> /// <param name="regions">Output list of regions with text</param> public static void DetectRegions(InputArray image, ERFilter er_filter1, ERFilter er_filter2, out Point[][] regions) { using (var vecRegions = new VectorOfVectorPoint()) { NativeMethods.text_detectRegions(image.CvPtr, er_filter1.CvPtr, er_filter2.CvPtr, vecRegions.CvPtr); regions = vecRegions.ToArray(); } }
/// <summary> /// Converts MSER contours (vector<Point>) to ERStat regions. /// </summary> /// <param name="image">Source image CV_8UC1 from which the MSERs where extracted.</param> /// <param name="contours">Input vector with all the contours</param> /// <param name="regions">Output where the ERStat regions are stored</param> public static void MSERsToERStats(InputArray image, Point[][] contours, out ERStat[][] regions) { using (var vecRegions = new VectorOfVectorERStat()) using (var vecContours = new VectorOfVectorPoint(contours)) { NativeMethods.text_MSERsToERStats(image.CvPtr, vecContours.CvPtr, vecRegions.CvPtr); regions = vecRegions.ToArray(); } }
/// <summary> /// This one has no documentation in OpenCV sources or knowledge base /// </summary> /// <param name="image">Original RGB or Greyscale image from wich the regions were extracted</param> /// <param name="channel">Vector of single channel images CV_8UC1 from wich the regions were extracted</param> /// <param name="regions">Regions extracted by DetectRegions function</param> /// <param name="groups_rects">The output of the algorithm are stored in this parameter as list of rectangles</param> /// <param name="method">Grouping method (see GroupingModes). Can be one of { OrientationHorizontal, OrientationAny }</param> /// <param name="filename">The XML or YAML file with the classifier model. Only to use when grouping method is OrientationAny</param> /// <param name="minProbablity">The minimum probability for accepting a group. Only to use when grouping method is OrientationAny</param> public static void ErGrouping(Mat image, Mat[] channels, Point[][] regions, out Rect[] groups_rects, GroupingModes method, string filename = null, float minProbablity = 0.5f) { using (var vecChannels = new InputArray(channels)) using (var vecRegions = new VectorOfVectorPoint(regions)) using (var vecRects = new VectorOfRect()) using (var input = new InputArray(image)) { if (null == filename) { filename = string.Empty; } NativeMethods.text_erGrouping2(input.CvPtr, vecChannels.CvPtr, vecRegions.CvPtr, vecRects.CvPtr, (int)method, filename, minProbablity); groups_rects = vecRects.ToArray(); } }
/// <summary> /// /// </summary> /// <param name="image"></param> /// <param name="msers"></param> /// <param name="bboxes"></param> public virtual void DetectRegions( InputArray image, out Point[][] msers, out Rect[] bboxes) { if (disposed) throw new ObjectDisposedException(GetType().Name); if (image == null) throw new ArgumentNullException("nameof(image)"); image.ThrowIfDisposed(); using (var msersVec = new VectorOfVectorPoint()) using (var bboxesVec = new VectorOfRect()) { NativeMethods.features2d_MSER_detectRegions( ptr, image.CvPtr, msersVec.CvPtr, bboxesVec.CvPtr); msers = msersVec.ToArray(); bboxes = bboxesVec.ToArray(); } GC.KeepAlive(image); }
/// <summary> /// Detect MSER regions /// </summary> /// <param name="image">input image (8UC1, 8UC3 or 8UC4, must be greater or equal than 3x3)</param> /// <param name="msers">resulting list of point sets</param> /// <param name="bboxes">resulting bounding boxes</param> public virtual void DetectRegions( InputArray image, out Point[][] msers, out Rect[] bboxes) { ThrowIfDisposed(); if (image == null) { throw new ArgumentNullException(nameof(image)); } image.ThrowIfDisposed(); using (var msersVec = new VectorOfVectorPoint()) using (var bboxesVec = new VectorOfRect()) { NativeMethods.HandleException( NativeMethods.features2d_MSER_detectRegions( ptr, image.CvPtr, msersVec.CvPtr, bboxesVec.CvPtr)); GC.KeepAlive(this); msers = msersVec.ToArray(); bboxes = bboxesVec.ToArray(); } GC.KeepAlive(image); }