public string Process(string imagePath, ProcessingSettings settings)
        {
            string result = null;

            setProgress(5);

            setStep("Uploading image...");
            OcrSdkTask task = restClient.ProcessImage(imagePath, settings);

            setProgress(70);
            setStep("Processing...");
            task = waitForTask(task);

            if (task.Status == TaskStatus.Completed)
            {
                Console.WriteLine("Processing completed.");
                result = restClient.DownloadUrl(task.DownloadUrls[0]);
                setStep("Download completed.");
            }
            else if (task.Status == TaskStatus.NotEnoughCredits)
            {
                throw new Exception("Not enough credits to process the file. Please add more pages to your application balance.");
            }
            else
            {
                throw new Exception("Error while processing the task");
            }
            setProgress(100);
            return(result);
        }
Beispiel #2
0
        /// <summary>
        /// Upload a file to service synchronously and start processing
        /// </summary>
        /// <param name="filePath">Path to an image to process</param>
        /// <param name="settings">Language and output format</param>
        /// <returns>Id of the task. Check task status to see if you have enough units to process the task</returns>
        /// <exception cref="ProcessingErrorException">thrown when something goes wrong</exception>
        public OcrSdkTask ProcessImage(string filePath, ProcessingSettings settings)
        {
            string url = String.Format("{0}processReceipt?{1}", ServerUrl, settings.AsUrlParams);

            try
            {
                // Build post request
                WebRequest request = createPostRequest(url);
                writeFileToRequest(filePath, request);

                XDocument  response = performRequest(request);
                OcrSdkTask task     = ServerXml.GetTaskStatus(response);

                return(task);
            }
            catch (System.Net.WebException e)
            {
                String friendlyMessage = retrieveFriendlyMessage(e);
                if (friendlyMessage != null)
                {
                    throw new ProcessingErrorException(friendlyMessage, e);
                }
                throw new ProcessingErrorException("Cannot upload file", e);
            }
        }
Beispiel #3
0
        public string Process( string imagePath, ProcessingSettings settings )
        {
            string result = null;
            setProgress( 5 );

            setStep( "Uploading image..." );
            OcrSdkTask task = restClient.ProcessImage(imagePath, settings);

            setProgress( 70 );
            setStep("Processing...");
            task = waitForTask(task);

            if (task.Status == TaskStatus.Completed)
            {
                Console.WriteLine("Processing completed.");
                result = restClient.DownloadUrl(task.DownloadUrls[0]);
                setStep("Download completed.");
            }
            else if (task.Status == TaskStatus.NotEnoughCredits)
            {
                throw new Exception("Not enough credits to process the file. Please add more pages to your application balance.");
            }
            else
            {
                throw new Exception("Error while processing the task");
            }
            setProgress( 100 );
            return result;
        }
Beispiel #4
0
        private void startRecognition_Click( object sender, EventArgs e )
        {
            try {
                sourceDataSplitContainer.Enabled = false;
                resultSplitContainer.Enabled = false;

                ProgressBarForm progress = new ProgressBarForm( this );
                try {
                    processor.StepChangedAction = progress.ShowMessage;
                    processor.ProgressChangedAction = progress.ShowProgress;

                    ProcessingSettings settings = new ProcessingSettings();
                    settings.Country = (CountryOfOrigin)receiptCountries[countryComboBox.Text];
                    settings.TreatAsPhoto = treatAsPhotoCheckBox.Checked;

                    string result = processor.Process( imageFileTextBox.Text, settings );
                    receiptPictureBox.Image = sourceFilePictureBox.Image;
                    if( !String.IsNullOrEmpty( result ) ) {
                        fillReceiptFields( result );
                    }

                    resultSplitContainer.Panel1Collapsed = true;
                    //refreshGraphics();
                    showReceipt();
                } finally {
                    processor.ProgressChangedAction = null;
                    processor.StepChangedAction = null;
                    progress.EndProgress();
                }
            } catch( Exception exception ) {
                MessageBox.Show( this, exception.Message, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error );
            } finally {
                sourceDataSplitContainer.Enabled = true;
                resultSplitContainer.Enabled = true;
            }
        }
Beispiel #5
0
        private bool initDefaults()
        {
            try {
                activeFieldColor = Color.FromArgb( 50, Color.Blue );

                initReceiptCountries();
                fillCountryComboBox();
                processor = new Processor();
                ProcessingSettings defaultSettings = new ProcessingSettings();

                countryComboBox.Text = "USA";
                treatAsPhotoCheckBox.Checked = defaultSettings.TreatAsPhoto;

                showPrompt( "Select image file and country, then click \"Start Recognition\"", Color.Black );

                imageFileTextBox.Select();
            } catch( Exception exception ) {
                MessageBox.Show( this, exception.Message, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error );
                return false;
            }
            return true;
        }