Made Image to Text raise error on empty output
Some checks are pending
Spell checking / Spell checking (push) Waiting to run
Spell checking / Report (Push) (push) Blocked by required conditions
Spell checking / Report (PR) (push) Blocked by required conditions
Spell checking / Update PR (push) Waiting to run

This commit is contained in:
Ani 2024-11-20 16:44:54 +01:00
parent a0754023d2
commit ddbf4a30a8

View File

@ -22,7 +22,9 @@ public static class OcrHelpers
var ocrEngine = OcrEngine.TryCreateFromLanguage(ocrLanguage) ?? throw new InvalidOperationException("Unable to create OCR engine");
var ocrResult = await ocrEngine.RecognizeAsync(bitmap);
return ocrResult.Text;
return string.IsNullOrWhiteSpace(ocrResult.Text)
? throw new InvalidOperationException("Unable to extract text from image or image does not contain text")
: ocrResult.Text;
}
private static Language GetOCRLanguage()