mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-12-16 19:57:57 +01:00
37405 Advanced Paste: Image To Text doesn't work with English (Canada) (#37806)
* [AdvancedPaste] [Fix Bug] Create ocrEngine from user profile language GetOCRLanguage may fail based on language tag not matching (en-CA does not match en-GB or en-US), however user profile language may be valid. * Update exception message. Signed-off-by: Shawn Yuan <shuai.yuan.zju@gmail.com> * update Signed-off-by: Shawn Yuan <shuai.yuan.zju@gmail.com> --------- Signed-off-by: Shawn Yuan <shuai.yuan.zju@gmail.com> Co-authored-by: Shawn Yuan <shuai.yuan.zju@gmail.com>
This commit is contained in:
@@ -18,10 +18,19 @@ public static class OcrHelpers
|
|||||||
{
|
{
|
||||||
public static async Task<string> ExtractTextAsync(SoftwareBitmap bitmap, CancellationToken cancellationToken)
|
public static async Task<string> ExtractTextAsync(SoftwareBitmap bitmap, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
var ocrLanguage = GetOCRLanguage() ?? throw new InvalidOperationException("Unable to determine OCR language");
|
var ocrLanguage = GetOCRLanguage();
|
||||||
cancellationToken.ThrowIfCancellationRequested();
|
cancellationToken.ThrowIfCancellationRequested();
|
||||||
|
|
||||||
var ocrEngine = OcrEngine.TryCreateFromLanguage(ocrLanguage) ?? throw new InvalidOperationException("Unable to create OCR engine");
|
OcrEngine ocrEngine;
|
||||||
|
if (ocrLanguage is not null)
|
||||||
|
{
|
||||||
|
ocrEngine = OcrEngine.TryCreateFromLanguage(ocrLanguage) ?? throw new InvalidOperationException("Unable to create OCR engine from specified language");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ocrEngine = OcrEngine.TryCreateFromUserProfileLanguages() ?? throw new InvalidOperationException("Unable to create OCR engine from user profile language");
|
||||||
|
}
|
||||||
|
|
||||||
cancellationToken.ThrowIfCancellationRequested();
|
cancellationToken.ThrowIfCancellationRequested();
|
||||||
|
|
||||||
var ocrResult = await ocrEngine.RecognizeAsync(bitmap);
|
var ocrResult = await ocrEngine.RecognizeAsync(bitmap);
|
||||||
|
|||||||
Reference in New Issue
Block a user