Tesseract: C#Tesseract3.02画像から単語の各文字にアクセスする方法

作成日 2014年01月12日  ·  3コメント  ·  ソース: charlesw/tesseract

こんにちは、私はここの初心者です。
まず、画像から単語の各文字に長方形を描く必要があります。
古いバージョンのtesseractでは、次の方法で各文字にアクセスできることがわかりました。

foreach(tessnet2.word.CharListの文字c)
e.Graphics.DrawRectangle.........。

demo

しかし、今私はTesseract 3.02でC#winformに取り組んでいます

TesseractEngine a = new TesseractEngine(@ "./ tessdata"、 "eng"、EngineMode.TesseractAndCube);
Tesseract.Page page1 = a.Process(image);
foreach(.......ページ1)
{{
//(各文字のバウンディングボックス)から長方形を描画します
}

質問1:page1の各文字にアクセスする方法。

PageIteratorLevelのような多くのメソッドを試し、最初の行、最初の単語、最初のブロックなどのページの一部を取得しますが、それらの最初の文字を取得できません。
さて、page1のHOCRtextの結果テキストでは、word、line、blockなどの各要素に境界ボックスの値があることに気付きました。

質問2:各要素のバウンディングボックスの値を取得するにはどうすればよいですか。 (ブール値のみを返すメソッド「TryGetBoundingBox」が1つだけ見つかりました。

ありがとうございました。

question

最も参考になるコメント

Q1の回答:

結果を反復処理する方法の例を示しているので、提供されているコンソールサンプルを確認してください。ただし、次のようなものが機能するはずです。

using (var iter = page.GetIterator()) {
    do {
        do {
            do {
                if (iter.IsAtBeginningOf(PageIteratorLevel.Block)) {
                    // do whatever you need to do when a block (top most level result) is encountered.
                }
                if (iter.IsAtBeginningOf(PageIteratorLevel.Para)) {
                    // do whatever you need to do when a paragraph is encountered.
                }
                if (iter.IsAtBeginningOf(PageIteratorLevel.TextLine)) {
                    // do whatever you need to do when a line of text is encountered is encountered.
                }                                               
                if (iter.IsAtBeginningOf(PageIteratorLevel.Word)) {
                    // do whatever you need to do when a word is encountered is encountered.
                }

                // get bounding box for symbol
                Rect symbolBounds;
                if(iter.TryGetBoundingBox(PageIteratorLevel.Symbol, out symbolBounds)) {
                    // do whatever you want with bounding box for the symbol
                }
            } while(iter.Next(PageIteratorLevel.Word, PageIteratorLevel.Block));
        } while (iter.Next(PageIteratorLevel.TextLine, PageIteratorLevel.Word));
    } while (iter.Next(PageIteratorLevel.Para, PageIteratorLevel.TextLine));
}

一般的な結果の階層は次のとおりであることに注意してください。

ブロック->パラ->テキストライン->ワード->シンボル

つまり、結果セットには多くのブロックを含めることができ、ブロックには多くの段落などを含めることができます。

質問2の回答:

上記のように、 TryGetBoundingBoxメソッドはoutパラメーターの境界を返します。 Dictionary.TryGetValue同じように。

全てのコメント3件

Q1の回答:

結果を反復処理する方法の例を示しているので、提供されているコンソールサンプルを確認してください。ただし、次のようなものが機能するはずです。

using (var iter = page.GetIterator()) {
    do {
        do {
            do {
                if (iter.IsAtBeginningOf(PageIteratorLevel.Block)) {
                    // do whatever you need to do when a block (top most level result) is encountered.
                }
                if (iter.IsAtBeginningOf(PageIteratorLevel.Para)) {
                    // do whatever you need to do when a paragraph is encountered.
                }
                if (iter.IsAtBeginningOf(PageIteratorLevel.TextLine)) {
                    // do whatever you need to do when a line of text is encountered is encountered.
                }                                               
                if (iter.IsAtBeginningOf(PageIteratorLevel.Word)) {
                    // do whatever you need to do when a word is encountered is encountered.
                }

                // get bounding box for symbol
                Rect symbolBounds;
                if(iter.TryGetBoundingBox(PageIteratorLevel.Symbol, out symbolBounds)) {
                    // do whatever you want with bounding box for the symbol
                }
            } while(iter.Next(PageIteratorLevel.Word, PageIteratorLevel.Block));
        } while (iter.Next(PageIteratorLevel.TextLine, PageIteratorLevel.Word));
    } while (iter.Next(PageIteratorLevel.Para, PageIteratorLevel.TextLine));
}

一般的な結果の階層は次のとおりであることに注意してください。

ブロック->パラ->テキストライン->ワード->シンボル

つまり、結果セットには多くのブロックを含めることができ、ブロックには多くの段落などを含めることができます。

質問2の回答:

上記のように、 TryGetBoundingBoxメソッドはoutパラメーターの境界を返します。 Dictionary.TryGetValue同じように。

こんにちはチャールズ、

あなたがうまくやっていることを願っています。

私はこのようなものに不慣れです。小さな画像やテスト画像から必要なテキストを取得できますが、実際の画像からは取得できません。

  1. 写真からBIB#を抽出する方法。
    NotWorking

  2. 写真全体からBIB#エリアを認識する方法。
    H1764

ありがとう。

opencvを使用して、地域を見つけてトリミングします。 .netに翻訳するのはそれほど難しくないPythonで書かれたデモを持っている人がいます。

このページは役に立ちましたか?
0 / 5 - 0 評価