/// <inheritdoc /> public override void Locate(PageShape page, Image image, Image originalImage, IList <Rectangle> areas, CancellationToken cancellationToken) { ISet <TextShape> texts = this.detector.FindText(image, page.EnumAllLines(), cancellationToken); // add found lines to the image page.AddShapes(texts); }
/// <inheritdoc /> public override void Locate(PageShape page, Image image, Image originalImage, IList <Rectangle> areas, CancellationToken cancellationToken) { ISet <PictureShape> pictures = this.detector.FindPictures(image, cancellationToken); // add found pictures to the image page.AddShapes(pictures); }
/// <summary> /// Initializes a new instance of the <see cref="PageSource"/> class. /// </summary> /// <param name="id">The source of data.</param> /// <param name="page">The <see cref="PageShape"/> object that contains the page data.</param> /// <exception cref="ArgumentNullException"> /// <paramref name="id"/> is <b>null</b>. /// </exception> public PageSource(DataSourceId id, PageShape page) : base(id) { this.Page = page; }
/// <summary> /// Initializes a new instance of the <see cref="PageSource"/> class. /// </summary> /// <param name="id">The unique identifier of the data.</param> /// <param name="name">The name of the data.</param> /// <param name="frameIndex"> /// The zero-based index for this data if it belongs to a multi-page file. /// <b>null</b> if this data belongs to a single-page file. /// </param> /// <param name="page">The <see cref="PageShape"/> object that contains the page data.</param> public PageSource(string id, string name, int?frameIndex, PageShape page) : base(id, name, frameIndex) { this.Page = page; }
/// <summary> /// Locates shapes on the specified <see cref="Image"/>. /// </summary> /// <param name="page">The <see cref="PageShape"/> that contains shapes previously found on the image and receives new shapes found by this locator..</param> /// <param name="image">The <see cref="Image"/> to locate shapes on. This image can be changed by locator.</param> /// <param name="originalImage">The <see cref="Image"/> to locate shapes on. This image is the copy of original image and remains unchanged.</param> /// <param name="areas">The areas on the <paramref name="image"/> to locate shapes in.</param> /// <param name="cancellationToken">The cancellationToken token used to notify the locator that operation should be canceled.</param> /// <remarks> /// Use this method to locate shapes of different types (i.e. lines, pictures, tables). /// </remarks> public abstract void Locate(PageShape page, Image image, Image originalImage, IList <Rectangle> areas, CancellationToken cancellationToken);
/// <summary> /// Segments the <see cref="Image"/> into the specified <see cref="Shape"/> objects. /// </summary> /// <param name="image">An image to parse.</param> /// <param name="areas">The areas on the <paramref name="image"/> to locate shapes in.</param> /// <param name="cancellationToken">The cancellation token used to notify the <see cref="ImageSegmentation"/> that operation should be canceled.</param> /// <returns>The <see cref="PageShape"/> object this method creates.</returns> public PageShape Segment(Image image, IList <Rectangle> areas, CancellationToken cancellationToken) { if (image == null) { throw new ArgumentNullException(nameof(image)); } // check if full image if (areas != null && areas.Any() && Rectangle.Union(areas) == image.Bounds) { areas = null; } PageShape page = new PageShape(image.Bounds, image.HorizontalResolution, image.VerticalResolution); Image originalImage = image.Clone(true); foreach (LocatorTypes locatorType in ImageSegmentation.Types.Keys) { if (this.Locators.HasFlag(locatorType)) { #if SESSION_DIAG this.StartStopwatch(); #endif LocatorBase locator = InitializeLocator(locatorType); if (locatorType == LocatorTypes.LineLocator) { // always run line locator on full image locator.Locate(page, image, originalImage, null, cancellationToken); // delete found lines from the image ////LineLocator.DeleteLines(parameters.LineLocatorParameters, image, page.GetAllLines(), cancellationToken); } else { locator.Locate(page, image, originalImage, areas, cancellationToken); } #if SESSION_DIAG this.StopStopwatch(locatorType.ToString()); #endif } cancellationToken.ThrowIfCancellationRequested(); } return(page); LocatorBase InitializeLocator(LocatorTypes locatorType) { if (!this.locators.TryGetValue(locatorType, out LocatorBase locator)) { try { this.locators[locatorType] = locator = (LocatorBase)Activator.CreateInstance( ImageSegmentation.Types[locatorType], BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, new object[] { }, null); } catch (Exception e) { throw new InvalidOperationException("Cannot create locator.", e); } } return(locator); } }