Example #1
0
        private async void PerformBtn_Click(object sender, RoutedEventArgs e)
        {
            if (OcrInProgress)
            {
                Dialog.IsOpen = true;
                return;
            }

            OcrInProgress = true;
            if (WindowState != WindowState.Minimized)
            {
                Hide();
            }

            await Task.Delay(180);

            var image = Screenshot.CaptureRegion();

            if (image == null)
            {
                OcrInProgress = false;
                ShowWindow();
                return;
            }

            var bitImage = await ConvertImage(image);

            ShowWindow();

            string recognizedText;

            try
            {
                IOcrHandler ocrHandler = AppSettings.Default.OcrEngine switch
                {
                    0 => new VisionApi(),
                    1 => new OcrSpace(),
                    _ => new VisionApi()
                };

                recognizedText = await RecognizeText(ocrHandler, bitImage);
            }
            catch (Exception exception)
            {
                DialogText.Text = exception.Message;
                AppSettings.Default.GOOGLE_APPLICATION_CREDENTIALS = "";
                OcrInProgress = false;
                ShowWindow();
                Dialog.IsOpen = true;

                return;
            }

            OpenNewWindow(recognizedText);

            if (AppSettings.Default.CopyToClipboard)
            {
                Clipboard.SetDataObject(recognizedText);
            }

            OcrInProgress = false;
        }
Example #2
0
 private static async Task <string> RecognizeText(IOcrHandler ocrHandler, byte[] bitImage)
 {
     return(await ocrHandler.RecognizeImage(bitImage));
 }