static string RecognizeTableFromUrl(Configuration conf)
        {
            string urlToFile = @"https://learnche.org/pid/_images/table-car-payments.png";

            OcrApi api = new OcrApi(conf);
            OCRTableRequestData requestData = new OCRTableRequestData()
            {
                MakeSkewCorrect = true
            };
            OCRTableResponse response = api.OcrTableFromUrl(requestData, urlToFile);

            return(response.Text);
        }
        static string RecognizeTableFromContent(Configuration conf)
        {
            string name = "table.png";

            using (FileStream fs = File.OpenRead(name))
            {
                OcrApi api     = new OcrApi(conf);
                var    request = new OCRTableRequestData()
                {
                    MakeSkewCorrect = true
                };
                OCRTableResponse response = api.OcrTableFromContent(request, fs);

                //response.Excel, response.CSV
                return(response.Text);
            }
        }
Beispiel #3
0
        /// <summary>
        /// Recognize Receipt table image located at Aspose Storage.
        /// Use StorageApi to upload your files. <see cref="StorageApi"/>
        /// </summary>
        /// <param name="requestData">Receipt recognition configuration <see cref="OCRTableRequestDataStorage"/></param>
        /// <returns><see cref="OCRTableResponse"/></returns>
        public OCRTableResponse OcrTableFromStorage(OCRTableRequestDataStorage requestData)
        {
            var requestUrl = BuildUrl("recognize-table-storage");
            var formParams = new Dictionary <string, object> {
                { "requestData", requestData }
            };

            try
            {
                return(this.apiInvoker.InvokeApi <OCRTableResponse>(requestUrl, "POST", null, null, formParams));
            }
            catch (TimeoutException)
            {
                OCRTableResponse ocrRespose = new OCRTableResponse();
                ocrRespose.Status        = "2";
                ocrRespose.StatusMessage = "TimeOutException";
                return(ocrRespose);
            }
        }
Beispiel #4
0
        /// <summary>
        /// Recognize Receipt table image from File Stream
        /// </summary>
        /// <param name="requestData">Receipt recognition configuration <see cref="OCRTableRequestData"/></param>
        /// <param name="file">Local file stream</param>
        /// <returns><see cref="OCRTableResponse"/></returns>
        public OCRTableResponse OcrTableFromContent(OCRTableRequestData requestData, Stream file)
        {
            var requestUrl = BuildUrl("recognize-table-content");
            var fileInfo   = this.apiInvoker.ToFileInfo(file, "File");
            var formParams = new Dictionary <string, object> {
                { "file", fileInfo }, { "requestData", requestData }
            };

            try
            {
                return(this.apiInvoker.InvokeApi <OCRTableResponse>(requestUrl, "POST", null, null, formParams));
            }
            catch (TimeoutException)
            {
                OCRTableResponse ocrRespose = new OCRTableResponse();
                ocrRespose.Status        = "2";
                ocrRespose.StatusMessage = "TimeOutException";
                return(ocrRespose);
            }
        }
        static string RecognizeTableFromStorage(Configuration conf)
        {
            string name = "table.png";

            using (FileStream fs = File.OpenRead(name))
            {
                OcrApi  api     = new OcrApi(conf);
                FileApi fileApi = new FileApi(conf /* or AppSid & AppKey*/);

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

                OCRTableRequestDataStorage requestData = new OCRTableRequestDataStorage()
                {
                    FileName        = name,
                    MakeSkewCorrect = true
                };
                OCRTableResponse response = api.OcrTableFromContent(requestData, fs);

                //response.Excel, response.CSV
                return(response.Text);
            }
        }