Exemplo n.º 1
0
        /// <summary>
        /// Loads image from file, binarize and rotate it and returns KrecImage
        /// </summary>
        /// <param name="path">Image path</param>
        /// <param name="deskewParameters">The information on how the image has been deskewed</param>
        /// <returns>Binarized and rotated image with deskew parameters</returns>
        public static KrecImage LoadAlignedBinarisedImageFromFile(string path, out DeskewParameters deskewParameters)
        {
            var sourceImage    = KrecImage.FromFile(path);
            var binarizedImage = sourceImage.Binarize();

            deskewParameters = FastImageDeskewer.GetDeskewParameters(binarizedImage);
            return(RotateGrayscaleImage(binarizedImage, deskewParameters.AngleRadians));
        }
        /// <summary>
        /// Scales given recognition results by specified factor
        /// </summary>
        /// <param name="source">The results of OCR to process</param>
        /// <param name="scaleFactor"></param>
        /// <returns>Recognition results which are guaranteed to be deskewed</returns>
        public static RecognitionResult Scale(this RecognitionResult source, double scaleFactor)
        {
            var targetModel      = source.GeometryModel.ScaleModel(scaleFactor);
            var deskewParameters = source.DeskewParameters;

            if (deskewParameters != null)
            {
                var sourceBoundingBoxScaled = DeskewProcessor.ScaleBoundingBox(new BoundingBox(0, 0, deskewParameters.SourceWidth, deskewParameters.SourceHeight), scaleFactor);
                deskewParameters = new DeskewParameters(sourceBoundingBoxScaled.Width, sourceBoundingBoxScaled.Height, deskewParameters.AngleRadians);
                return(new RecognitionResult(targetModel, deskewParameters));
            }
            return(new RecognitionResult(targetModel));
        }
Exemplo n.º 3
0
 /// <summary>
 /// Creates new instance of recognition results assuming that results are not deskewed
 /// </summary>
 /// <param name="geometryModel"></param>
 public RecognitionResult(TextGeometryModel geometryModel)
 {
     this.geometryModel = geometryModel;
     deskewParameters   = null;
     isDeskewed         = false;
 }
Exemplo n.º 4
0
 /// <summary>
 /// Creates new instance of recognition results assuming that results are deskewed with given transformation
 /// </summary>
 /// <param name="geometryModel">The model to store</param>
 /// <param name="deskewParameters">The set of deskew transformation parameters</param>
 public RecognitionResult([NotNull] TextGeometryModel geometryModel, [NotNull] DeskewParameters deskewParameters)
 {
     this.geometryModel    = geometryModel;
     this.deskewParameters = deskewParameters;
     isDeskewed            = true;
 }