Пример #1
0
 private TransymOcrResult DoOcr(Stream imageAsStream, DateTime start)
 {
     try
     {
         var src = new Bitmap(imageAsStream);
         ValidateImageProportions(src);
         src = PreProcess(src);
         var byteStream = new MemoryStream();
         src.Save(byteStream, ImageFormat.Tiff);
         var entries          = _transymAccess.OcrByStream(byteStream);
         var rawTransymResult = RawTransymOcrResult.CreateFrom(entries);
         var content          = _parser.Execute(entries);
         return(TransymOcrResult.CreateSuccesResult(DateTime.Now.Subtract(start), content, rawTransymResult));
     }
     catch (Exception e)
     {
         return(TransymOcrResult.CreateErrorResult(DateTime.Now.Subtract(start), e));
     }
 }
Пример #2
0
        /// <summary>
        /// Method to call Transym installation on the machine to perform OCR and format the result into an easy to use format.
        /// Prior to calling the API, this method will rotate it according to the EXIF orientation.
        /// </summary>
        /// <param name="filePath">File path</param>
        /// <returns></returns>
        public TransymOcrResult OcrImage(string filePath)
        {
            var start = DateTime.Now;

            try
            {
                if (!File.Exists(filePath))
                {
                    throw new FileNotFoundException("", filePath);
                }
                using (var stream = File.OpenRead(filePath))
                {
                    return(DoOcr(stream, start));
                }
            }
            catch (Exception e)
            {
                return(TransymOcrResult.CreateErrorResult(DateTime.Now.Subtract(start), e));
            }
        }