Exemplo n.º 1
0
        private void CreateDistortedImages(List <IImageProcessor> selectedDistorsions, int samples)
        {
            string tempPath = Path.GetTempPath();

            Debug.WriteLine(tempPath);
            foreach (StorageFile file in this.pickedFiles)
            {
                string fileFolderPath = Directory.CreateDirectory(Path.Combine(tempPath, Path.GetFileName(file.Path))).FullName;
                distortedImages[Path.GetFileName(file.Path)] = new List <DistortedImage>();
                originalImages[Path.GetFileName(file.Path)]  = file;
                foreach (IImageProcessor distorsion in selectedDistorsions)
                {
                    string distortionFolderPath = Directory.CreateDirectory(Path.Combine(fileFolderPath, distorsion.GetType().ToString())).FullName;
                    if (samples == 1)
                    {
                        distorsion.Execute(distorsion.lastValue, file, distortionFolderPath);
                    }
                    else
                    {
                        for (int i = 1; i <= samples; i++)
                        {
                            Informator.Log("   Executing " + distorsion.GetType().ToString() + " - " + i + " out of " + samples);
                            float value = distorsion.startValue + (distorsion.lastValue - distorsion.startValue) / samples * i;
                            distorsion.Execute(value, file, distortionFolderPath);
                            distortedImages[Path.GetFileName(file.Path)].Add(new DistortedImage(distorsion.GetType().ToString(), distortionFolderPath, value));
                        }
                    }
                }
                Informator.Log("Finished distorting image: " + Path.GetFileName(file.Path));
                Informator.Log("");
            }
            Informator.Log("Finished creation of distorted images");
            Informator.Log("");
        }
Exemplo n.º 2
0
        private async void Recognize_Text(object sender, RoutedEventArgs e)
        {
            if (this.pickedFiles.Count <= 0)
            {
                return;
            }
            Informator.Clear();
            this.ClearTempFolder();
            this.distortedImages.Clear();
            this.originalImages.Clear();

            List <IImageProcessor> selectedDistorsions = this.GetSelectedDistorsions();
            int samples = Convert.ToInt32(SamplesSlider.Value);
            await Task.Run(() => CreateDistortedImages(selectedDistorsions, samples));

            // run recognition for each selected engine
            List <IOcrEngine> selectedEngines = this.GetSelectedEngines();

            foreach (IOcrEngine engine in selectedEngines)
            {
                var keys = distortedImages.Keys;
                for (int i = 0; i < keys.Count; i++)
                {
                    string             resultsPath = Directory.CreateDirectory(Path.Combine(Path.GetTempPath(), keys.ElementAt(i), "OCR-output")).FullName;
                    List <StorageFile> filesToOcr  = await this.GetFiles(keys.ElementAt(i));

                    List <string> ocrOutput = null;
                    await Task.Run(async() => {
                        ocrOutput = await engine.RecognizeAsync(filesToOcr);
                    });

                    File.WriteAllText(Path.Combine(resultsPath, "originalImage" + ".txt"), ocrOutput[0]);
                    for (int j = 1; j < ocrOutput.Count; j++)
                    {
                        File.WriteAllText(Path.Combine(resultsPath, this.distortedImages[keys.ElementAt(i)][j - 1].distortion + "_" + filesToOcr[j].Name + ".txt"), ocrOutput[j]);
                    }
                    this.AnalizeOcrResults(engine.GetType().ToString(), keys.ElementAt(i), ocrOutput);
                    Informator.Log("Finished analizing image: " + keys.ElementAt(i));
                    Informator.Log("");
                }
                Informator.Log(engine.GetType().ToString() + " has finished");
                Informator.Log("");
            }
            Informator.Log("");
            Informator.Log("FINISHED");
            Informator.Log("Results can be found at: " + Path.GetTempPath());
        }