0
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Mat画像をTesseractのPixクラスに変換

Posted at

すぐには分からなかった。結局Matをバイト配列に変換させてPix.LoadFromMemory関数で変換している。

環境

  • Tessaract 5.2.0
  • OpenCvSharp 4
  • C#

画像の一部を切り抜いて、切り抜いた部分の文字列を取得するコードの切り抜き。

OpenCvSharp.Rect retval = Cv2.BoundingRect(contour);
OpenCvSharp.Rect rect = new OpenCvSharp.Rect(retval.TopLeft, new OpenCvSharp.Size(retval.Width, retval.Height));
Mat rectMat = _thresholdMat.Clone(rect);

byte[] bytes = rectMat.ToBytes(); // バイト配列に変換
Pix pix = Pix.LoadFromMemory(bytes); // Pixクラスに変換
TesseractEngine engine = new TesseractEngine(dataPath, "jpn");
Page page = engine.Process(pix);
0
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?