Ejemplo n.º 1
0
        /// <summary>Performs basic image preprocessing using buffered image (if provided).</summary>
        /// <remarks>
        /// Performs basic image preprocessing using buffered image (if provided).
        /// Preprocessed image will be saved in temporary directory.
        /// </remarks>
        /// <param name="inputFile">
        /// input image
        /// <see cref="System.IO.FileInfo"/>
        /// </param>
        /// <param name="pageNumber">number of page to be preprocessed</param>
        /// <returns>
        /// created preprocessed image as
        /// <see cref="Tesseract.Pix"/>
        /// </returns>
        internal static Pix PreprocessImage(FileInfo inputFile, int pageNumber)
        {
            Pix pix = null;

            // read image
            if (IsTiffImage(inputFile))
            {
                pix = TesseractOcrUtil.ReadPixPageFromTiff(inputFile, pageNumber - 1);
            }
            else
            {
                pix = ReadPix(inputFile);
            }
            if (pix == null)
            {
                throw new Tesseract4OcrException(Tesseract4OcrException.CANNOT_READ_PROVIDED_IMAGE).SetMessageParams(inputFile
                                                                                                                     .FullName);
            }
            return(TesseractOcrUtil.PreprocessPix(pix));
        }