Beispiel #1
0
        /// <summary>
        /// Pass a string path of image on local storage to the OCR API to extract text.
        /// </summary>
        /// <param name="imagePath"></param>
        public void OCRFile(string imagePath)
        {
            if (string.IsNullOrEmpty(imagePath))
            {
                return;
            }
            _ImagePath = imagePath;

            _log.Info($"Uploading URL: {_ImagePath} to OCR API");
            GoogleAnnotate annotate = new GoogleAnnotate(_log);

            annotate.GetText(_ImagePath, languageType + "");

            if (false == string.IsNullOrEmpty(annotate.Error))
            {
                ResultTextString = annotate.Error;
                _log.Info($"Error: {ResultTextString} uploading to OCR API using image URL: {_ImagePath}");
            }
            else
            {
                ResultJsonString = annotate.JsonResult;
                ResultTextString = annotate.TextResult;
                _log.Info($"Success: {ResultJsonString} uploading to OCR API using image URL: {_ImagePath}");
            }
        }
Beispiel #2
0
        /// <summary>
        /// Pass a URL to the OCR API to extract text.
        /// </summary>
        /// <param name="imageURI"></param>
        public void OCRFile(Uri imageURI)
        {
            if (string.IsNullOrEmpty(imageURI.ToString()))
            {
                _log.Info("URL is NULL or empty");
                return;
            }

            _ImageURI        = imageURI;
            ResultJsonString = "";
            ResultTextString = "";

            _log.Info($"Uploading URL: {_ImageURI.ToString()} to OCR API");
            GoogleAnnotate annotate = new GoogleAnnotate(_log);

            annotate.GetText(_ImageURI, languageType + "");

            if (false == string.IsNullOrEmpty(annotate.Error))
            {
                ResultTextString = annotate.Error;
                _log.Info($"Error: {ResultTextString} uploading to OCR API using image URL: {_ImageURI.ToString()}");
            }
            else
            {
                ResultJsonString = annotate.JsonResult;
                ResultTextString = annotate.TextResult;
                _log.Info($"Success: {ResultJsonString} uploading to OCR API using image URL: {_ImageURI.ToString()}");
            }
        }