Exemple #1
0
        private static GoogleOcrEngine GetGoogleOcrEngine()
        {
            Console.WriteLine("To OCR process an image you need a google account and access to their vision API.");
            Console.WriteLine("Input google API key:");
            string apiKey = null;

            while (string.IsNullOrWhiteSpace(apiKey))
            {
                apiKey = Console.ReadLine();
            }

            var ocr = GoogleOcrEngine.Build(new GoogleOcrConfigurations(apiKey, "OcrWrapperDemo"));

            Console.WriteLine("Google ocr engine instantiated.");
            Console.WriteLine();
            return(ocr);
        }
Exemple #2
0
        private static GoogleOcrEngine GetGoogleOcrEngine()
        {
            Console.WriteLine("To OCR process an image you need a google account and access to their vision API.");
            Console.WriteLine("Input path to your google application credentials .json file:");
            string googleCredentials = null;

            while (string.IsNullOrWhiteSpace(googleCredentials))
            {
                googleCredentials = Console.ReadLine();
            }

            var ocr = GoogleOcrEngine.Build(new GoogleOcrConfigurations(googleCredentials));

            Console.WriteLine("Google ocr engine instantiated.");
            Console.WriteLine();
            return(ocr);
        }
Exemple #3
0
        static void Main(string[] args)
        {
            Console.WriteLine("###### OCR Wrapper demo project ######");
            GoogleOcrEngine googleOcrEngine = null;
            AzureOcrEngine  azureOcrEngine  = null;
            string          visionApiChoice = null;

            while (true)
            {
                Console.WriteLine("Input file path:");
                var userChoice = Console.ReadLine();
                if (userChoice == null || userChoice.ToLower().Equals("q"))
                {
                    return;
                }

                var imageFormat = GetImageFormat(userChoice);
                if (imageFormat == FileFormatEnum.Unsupported)
                {
                    Console.WriteLine("Unsupported file format. Supported types are; jpg, jpeg, png and pdf.");
                    continue;
                }

                if (imageFormat == FileFormatEnum.Pdf)
                {
                    PerformAction(DoPdfExtraction(userChoice)).ContinueWith(t => Pause()).Wait();
                }
                else
                {
                    if (visionApiChoice == null)
                    {
                        Console.WriteLine("What vision API do you wish to use, Google or Azure? \nOr you can use an installation of Tranym ocr if you have it installed on this machine. \n(Options: azure, google, transym).");
                        while (string.IsNullOrWhiteSpace(visionApiChoice) ||
                               (visionApiChoice != "google" && visionApiChoice != "azure" && visionApiChoice != "transym"))
                        {
                            visionApiChoice = Console.ReadLine()?.ToLower();
                        }
                    }

                    if (visionApiChoice == "google")
                    {
                        if (googleOcrEngine == null)
                        {
                            googleOcrEngine = GetGoogleOcrEngine();
                        }
                        PerformAction(DoGoogleOcr(googleOcrEngine, imageFormat, userChoice)).ContinueWith(t => Pause()).Wait();
                    }
                    else if (visionApiChoice == "azure")
                    {
                        if (azureOcrEngine == null)
                        {
                            azureOcrEngine = GetAzureOcrEngine();
                        }
                        PerformAction(DoAzureOcr(azureOcrEngine, imageFormat, userChoice)).ContinueWith(t => Pause()).Wait();
                    }
                    else if (visionApiChoice == "transym")
                    {
                        Console.WriteLine("Do you have a licensed Transym installation on this machine? (y/n)\nOtherwise the ocr will fail.");
                        var isTransymInstalled = Console.ReadLine()?.ToLower();
                        if (isTransymInstalled == "y")
                        {
                            PerformAction(DoTransymOcr(userChoice)).ContinueWith(t => Pause()).Wait();
                        }
                    }
                }
            }
        }
Exemple #4
0
 private static async Task <OcrResult> DoGoogleOcr(GoogleOcrEngine googleOcrEngine, FileFormatEnum fileFormat, string file)
 {
     return(await googleOcrEngine.OcrImage(file, fileFormat));
 }
 public void ItShouldMakeAValidRequestToGoogleVision()
 {
     var bytes  = File.ReadAllBytes(@"C:\Git\luval-vision\Code\luval.tests\TestFiles\sample1.png");
     var vision = new GoogleOcrEngine();
     var result = vision.Execute("sample1.png", bytes);
 }