Ejemplo n.º 1
0
        static string RecognizeFromStorage(Configuration conf)
        {
            string name = "10.png";

            OcrApi  api     = new OcrApi(conf);
            FileApi fileApi = new FileApi(conf /* or AppSid & AppKey*/);

            fileApi.UploadFile(new UploadFileRequest(name, System.IO.File.OpenRead(name)));

            GetRecognizeDocumentRequest request = new GetRecognizeDocumentRequest(name);
            OCRResponse response = api.GetRecognizeDocument(request);

            return(response.Text);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Recognize image text, language and text region can be selected
        /// </summary>
        /// <param name="request">Request. <see cref="GetRecognizeDocumentRequest" /></param>
        /// <returns><see cref="OCRResponse"/></returns>
        public OCRResponse GetRecognizeDocument(GetRecognizeDocumentRequest request)
        {
            // verify the required parameter 'name' is set
            if (request.name == null)
            {
                throw new ApiException(400, "Missing required parameter 'name' when calling GetRecognizeDocument");
            }

            // create path and map variables
            var resourcePath = this.mConfiguration.GetApiRootUrl() + "/ocr/{name}/recognize";

            resourcePath = Regex
                           .Replace(resourcePath, "\\*", string.Empty)
                           .Replace("&amp;", "&")
                           .Replace("/?", "?");
            resourcePath = UrlHelper.AddPathParameter(resourcePath, "name", request.name);
            resourcePath = UrlHelper.AddQueryParameterToUrl(resourcePath, "storage", request.storage);
            resourcePath = UrlHelper.AddQueryParameterToUrl(resourcePath, "folder", request.folder);
            resourcePath = UrlHelper.AddQueryParameterToUrl(resourcePath, "language", request.language);
            resourcePath = UrlHelper.AddQueryParameterToUrl(resourcePath, "resultType", request.resultType);
            resourcePath = UrlHelper.AddQueryParameterToUrl(resourcePath, "skewCorrect", request.skewCorrect);
            resourcePath = UrlHelper.AddQueryParameterToUrl(resourcePath, "spellCheck", request.spellCheck);
            resourcePath = UrlHelper.AddQueryParameterToUrl(resourcePath, "dsrMode", request.dsrMode);
            resourcePath = UrlHelper.AddQueryParameterToUrl(resourcePath, "dsrConfidence", request.dsrConfidence);
            resourcePath = UrlHelper.AddQueryParameterToUrl(resourcePath, "makeContrastCorrection", request.contrastCorrection);



            try
            {
                return(this.apiInvoker.InvokeApi <OCRResponse>(
                           resourcePath,
                           "GET",
                           null,
                           null,
                           null));
            }
            catch (TimeoutException)
            {
                OCRResponse ocrRespose = new OCRResponse();
                ocrRespose.Status        = "2";
                ocrRespose.StatusMessage = "TimeOutException";
                return(ocrRespose);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Recognize image text, language and text region can be selected
        /// </summary>
        /// <param name="request">Request. <see cref="GetRecognizeDocumentRequest" /></param>
        /// <returns><see cref="OCRResponse"/></returns>
        public OCRResponse GetRecognizeDocument(GetRecognizeDocumentRequest request)
        {
            // verify the required parameter 'name' is set
            if (request.name == null)
            {
                throw new ApiException(400, "Missing required parameter 'name' when calling GetRecognizeDocument");
            }

            // create path and map variables
            var resourcePath = this.configuration.GetApiRootUrl() + "/ocr/{name}/recognize";

            resourcePath = Regex
                           .Replace(resourcePath, "\\*", string.Empty)
                           .Replace("&amp;", "&")
                           .Replace("/?", "?");
            resourcePath = UrlHelper.AddPathParameter(resourcePath, "name", request.name);
            resourcePath = UrlHelper.AddQueryParameterToUrl(resourcePath, "storage", request.storage);
            resourcePath = UrlHelper.AddQueryParameterToUrl(resourcePath, "folder", request.folder);

            try
            {
                var response = this.apiInvoker.InvokeApi(
                    resourcePath,
                    "GET",
                    null,
                    null,
                    null);
                if (response != null)
                {
                    return((OCRResponse)SerializationHelper.Deserialize(response, typeof(OCRResponse)));
                }

                return(null);
            }
            catch (ApiException ex)
            {
                if (ex.ErrorCode == 404)
                {
                    return(null);
                }

                throw;
            }
        }
        public string Convert(Stream file, string fileName, string language)
        {
            LanguageEnum lg = LanguageEnum.English;

            System.Enum.TryParse <LanguageEnum>(language, true, out lg);

            UploadFileRequest uploadFileRequest = new UploadFileRequest()
            {
                path = fileName,
                File = file
            };

            OCRFileApi.UploadFile(uploadFileRequest);

            GetRecognizeDocumentRequest request = new GetRecognizeDocumentRequest(name: fileName, language: lg);
            OCRResponse response = OCRCloudApi.GetRecognizeDocument(request);

            OCRFileApi.DeleteFile(new DeleteFileRequest(path: fileName));

            return(response.Text);
        }