Exemple #1
0
        public void ProcessFile(string sourceFilePath, string outputFileBase, ProcessingSettings settings)
        {
            Console.WriteLine("Uploading..");
            Task task = restClient.ProcessImage(sourceFilePath, settings);

            task = waitForTask(task);

            if (task.Status == TaskStatus.Completed)
            {
                Console.WriteLine("Processing completed.");
                for (int i = 0; i < settings.OutputFormats.Count; i++)
                {
                    var    outputFormat = settings.OutputFormats[i];
                    string ext          = settings.GetOutputFileExt(outputFormat);
                    restClient.DownloadUrl(task.DownloadUrls[i], outputFileBase + ext);
                }
                Console.WriteLine("Download completed.");
            }
            else if (task.Status == TaskStatus.NotEnoughCredits)
            {
                Console.WriteLine("Not enough credits to process the file. Please add more pages to your application balance.");
            }
            else
            {
                Console.WriteLine("Error while processing the task");
            }
        }
Exemple #2
0
        public void ProcessDocument(IEnumerable <string> _sourceFiles, string outputFileBase,
                                    ProcessingSettings settings)
        {
            string[] sourceFiles = _sourceFiles.ToArray();
            Console.WriteLine(String.Format("Recognizing {0} images as a document",
                                            sourceFiles.Length));

            Task task = null;

            for (int fileIndex = 0; fileIndex < sourceFiles.Length; fileIndex++)
            {
                string filePath = sourceFiles[fileIndex];
                Console.WriteLine("{0}: uploading {1}", fileIndex + 1, Path.GetFileName(filePath));

                task = restClient.UploadAndAddFileToTask(filePath, task == null ? null : task.Id);
            }

            // Start task
            Console.WriteLine("Starting task..");
            restClient.StartProcessingTask(task.Id, settings);

            while (true)
            {
                task = restClient.GetTaskStatus(task.Id);
                if (!Task.IsTaskActive(task.Status))
                {
                    break;
                }

                Console.WriteLine(String.Format("Task status: {0}", task.Status));
                System.Threading.Thread.Sleep(1000);
            }

            if (task.Status == TaskStatus.Completed)
            {
                Console.WriteLine("Processing completed.");
                for (int i = 0; i < settings.OutputFormats.Count; i++)
                {
                    var    outputFormat = settings.OutputFormats[i];
                    string ext          = settings.GetOutputFileExt(outputFormat);
                    restClient.DownloadUrl(task.DownloadUrls[i], outputFileBase + ext);
                }
                Console.WriteLine("Download completed.");
            }
            else
            {
                Console.WriteLine("Error while processing the task");
            }
        }
Exemple #3
0
        private void Fire(string filePath)
        {
            txtEditor.Text = "Start";

            System.Drawing.Bitmap bitmap = GetBitMap(filePath);

            string tempFilePath = System.IO.Path.GetTempFileName();

            bitmap.Save(tempFilePath, System.Drawing.Imaging.ImageFormat.Tiff);

            string outputDir = getOutputDir();

            UserTask task = new UserTask(tempFilePath);

            task.TaskStatus       = "Uploading";
            task.SourceIsTempFile = true;
            task.IsFieldLevel     = true;
            task.SourceImage      = bitmap;

            //TextFieldProcessingSettings settings = new TextFieldProcessingSettings();
            //restClientAsync.ProcessTextFieldAsync(tempFilePath, settings, task);


            ///
            ProcessingSettings settings = new ProcessingSettings();

            task.OutputFilePath = System.IO.Path.Combine(
                outputDir,
                System.IO.Path.GetFileNameWithoutExtension(filePath) + settings.GetOutputFileExt(settings.OutputFormats[0]));

            settings.Description = String.Format("{0} -> {1}",
                                                 System.IO.Path.GetFileName(filePath),
                                                 settings.GetOutputFileExt(settings.OutputFormats[0]));

            restClientAsync.ProcessImageAsync(filePath, settings, task);
        }
Exemple #4
0
        public void ProcessFile(string sourceFilePath, string outputFileBase, ProcessingSettings settings)
        {
            Console.WriteLine("Uploading..");
            Task task = restClient.ProcessImage(sourceFilePath, settings);

            TaskId taskId = task.Id;

            while (Task.IsTaskActive(task.Status))
            {
                task = restClient.GetTaskStatus(taskId);
                if (!Task.IsTaskActive(task.Status))
                {
                    break;
                }

                Console.WriteLine(String.Format("Task status: {0}", task.Status));
                System.Threading.Thread.Sleep(1000);
            }

            if (task.Status == TaskStatus.Completed)
            {
                Console.WriteLine("Processing completed.");
                for (int i = 0; i < settings.OutputFormats.Count; i++)
                {
                    var    outputFormat = settings.OutputFormats[i];
                    string ext          = settings.GetOutputFileExt(outputFormat);
                    restClient.DownloadUrl(task.DownloadUrls[i], outputFileBase + ext);
                }
                Console.WriteLine("Download completed.");
            }
            else if (task.Status == TaskStatus.NotEnoughCredits)
            {
                Console.WriteLine("Not enough credits to process the file. Please add more pages to your application balance.");
            }
            else
            {
                Console.WriteLine("Error while processing the task");
            }
        }
Exemple #5
0
        void addFileTask(string filePath)
        {
            // Initialize output directory
            string outputDir = getOutputDir();

            // Different behavior for full-text recognition and business card recognition

            if (modeGeneral.IsChecked == true)
            {
                ProcessingSettings settings = GetProcessingSettings();

                UserTask task = new UserTask(filePath);
                task.TaskStatus     = "Uploading";
                task.OutputFilePath = System.IO.Path.Combine(
                    outputDir,
                    System.IO.Path.GetFileNameWithoutExtension(filePath) + settings.GetOutputFileExt(settings.OutputFormats[0]));

                _userTasks.Add(task);

                settings.Description = String.Format("{0} -> {1}",
                                                     Path.GetFileName(filePath),
                                                     settings.GetOutputFileExt(settings.OutputFormats[0]));

                restClientAsync.ProcessImageAsync(filePath, settings, task);
            }
            else if (modeBcr.IsChecked == true)
            {
                // Business-card recognition
                BusCardProcessingSettings settings = GetBusCardProcessingSettings();
                string ext;
                if (formatVCard.IsChecked == true)
                {
                    settings.OutputFormat = BusCardProcessingSettings.OutputFormatEnum.vCard;
                    ext = ".vcf";
                }
                else
                {
                    settings.OutputFormat = BusCardProcessingSettings.OutputFormatEnum.xml;
                    ext = ".xml";
                }


                UserTask task = new UserTask(filePath);
                task.TaskStatus     = "Uploading";
                task.OutputFilePath = System.IO.Path.Combine(
                    outputDir,
                    System.IO.Path.GetFileNameWithoutExtension(filePath) + ext);

                _userTasks.Add(task);

                restClientAsync.ProcessBusinessCardAsync(filePath, settings, task);
            }
            else
            {
                // Machine-readable zone recognition

                UserTask task = new UserTask(filePath);
                task.TaskStatus     = "Uploading";
                task.OutputFilePath = System.IO.Path.Combine(
                    outputDir,
                    System.IO.Path.GetFileNameWithoutExtension(filePath) + ".xml");

                _userTasks.Add(task);
                restClientAsync.ProcessMrzAsync(filePath, task);
            }
        }