示例#1
0
        private void StartOCR(Stream stream, string filename)
        {
            if (stream != null && stream.Length > 0 && !string.IsNullOrEmpty(filename))
            {
                cbLanguages.Enabled = btnStartOCR.Enabled = txtResult.Enabled = false;
                pbProgress.Visible  = true;

                TaskEx.Run(() =>
                {
                    try
                    {
                        OCRSpace ocr = new OCRSpace(Language, false);
                        OCRSpaceResponse response = ocr.DoOCR(stream, filename);

                        if (response != null && !response.IsErroredOnProcessing && response.ParsedResults.Count > 0)
                        {
                            Result = response.ParsedResults[0].ParsedText;
                        }
                    }
                    catch (Exception e)
                    {
                        DebugHelper.WriteException(e);
                    }
                },
                           () =>
                {
                    if (!IsDisposed)
                    {
                        UpdateControls();
                        cbLanguages.Enabled = btnStartOCR.Enabled = txtResult.Enabled = true;
                        pbProgress.Visible  = false;
                    }
                });
            }
        }
示例#2
0
        public async Task <string> ReadImageText(Uri uri)
        {
            string apiKey = _gitHubActionContext.GetParameter(Parameters.OcrSpaceApiKey);

            string uriImage = HttpUtility.UrlEncode(uri.ToString());

            StringBuilder stringBuilder = new StringBuilder("parse/imageurl?");

            stringBuilder.Append($"apikey={apiKey}&");
            stringBuilder.Append($"url={uriImage}");

            OCRSpaceResponse response = await _httpClient.GetFromJsonAsync <OCRSpaceResponse>(stringBuilder.ToString());

            return(response.ParsedResults.First().ParsedText);
        }