/// <summary> /// WindowsのOCRエンジンによる文字認識及び, 後処理を実行 /// </summary> /// <param name="softwareBitmap">ビットマップ</param> /// <param name="languageCode">言語コード</param> /// <returns>テキスト</returns> public async Task <string> UwpOcrEngineWithPostProcessing(SoftwareBitmap softwareBitmap, UwpLanguage languageCode) { string resultText = string.Empty; if (this.currentLanguageCode != languageCode) { this.ocrEngine = UwpOcrEngine.TryCreateFromLanguage(languageCode); } UwpOcrResult ocrResult = await ocrEngine.RecognizeAsync(softwareBitmap); foreach (var ocrLine in ocrResult.Lines) { resultText += (ocrLine.Text + " "); } return(resultText.Replace("- ", "")); }
public void ParseResponseData(object response) { #if (!UNITY_EDITOR) Windows.Media.Ocr.OcrResult responseTemp = (Windows.Media.Ocr.OcrResult)response; if (responseTemp.Text == "" || responseTemp.Text == null) { // Debug.LogError("<MediaOCR> " + "No Text recognized"); this.OcrResult = new OcrResult("", new UnityEngine.Rect(0, 0, 0, 0), OcrService.MICROSOFTMEDIAOCR); } else { // Find bounding box coords which surround the entire recognized text block float xMin, yMin, xMax, yMax; xMin = yMin = xMax = yMax = 0; float xMinTemp, yMinTemp, xMaxTemp, yMaxTemp; for (int i = 0; i < responseTemp.Lines.Count; i++) { for (int j = 0; j < responseTemp.Lines[i].Words.Count; j++) { xMinTemp = (float)responseTemp.Lines[i].Words[j].BoundingRect.X; yMinTemp = (float)responseTemp.Lines[i].Words[j].BoundingRect.Y; xMaxTemp = (float)(responseTemp.Lines[i].Words[j].BoundingRect.X + responseTemp.Lines[i].Words[j].BoundingRect.Width); yMaxTemp = (float)(responseTemp.Lines[i].Words[j].BoundingRect.Y + responseTemp.Lines[i].Words[j].BoundingRect.Height); if (i == 0 && j == 0) { xMin = xMinTemp; xMax = xMaxTemp; yMin = yMinTemp; yMax = yMaxTemp; } else { if (xMinTemp < xMin) { xMin = xMinTemp; } if (xMaxTemp > xMax) { xMax = xMaxTemp; } if (yMinTemp < yMin) { yMin = yMinTemp; } if (yMaxTemp > yMax) { yMax = yMaxTemp; } } } } this.OcrResult = new OcrResult(responseTemp.Text, new UnityEngine.Rect(xMin, yMin, (xMax - xMin), (yMax - yMin)), OcrService.MICROSOFTMEDIAOCR); // Debug.LogError("<MediaOCR> " + this.OcrResult.Text); } #endif }