问:System.InvalidOperationException:Xamarin中首先调用初始化(OCR TESSERACT)错误

时间:2018-09-04 00:40:00

标签: xamarin

if (tessResult)始终为假,执行tesseract OCR必须为真,有人可以帮助我吗?

if (!_tesseractApi.Initialized)
    await _tesseractApi.Init("eng"); 

  var photo = await TakePic();
  if (photo != null)
  {
      // When setting an ImageSource using a stream, 
      // the stream gets closed, so to avoid that I backed up
      // the image into a byte array with the following code:
      var imageBytes = new byte[photo.Source.Length];
      photo.Source.Position = 0;
      photo.Source.Read(imageBytes, 0, (int)photo.Source.Length);
      photo.Source.Position = 0;

      var tessResult = await _tesseractApi.SetImage(imageBytes);

      if (tessResult) 
      {
        _takenImage.Source = ImageSource.FromStream(() => photo.Source);
        _recognizedTextLabel.Text = _tesseractApi.Text;
      }
  }
}

2 个答案:

答案 0 :(得分:0)

将Tesseract火车文件(在您的情况下为英语tesseract火车文件)放在资产文件夹中。

答案 1 :(得分:0)

尝试将tessdata导入您的项目:
try to import tessdata to your project