1

実行するとFirefoxを起動し、ウィンドウのプロセスとハンドルを取得し、Firefoxのスクリーンキャプチャを実行してディスク(temp.bmp)に保存し、ProcessGetWindowを呼び出すWindowsフォームアプリがあります。私は基本的にMODIでMiSelectRectsを使用して、探している単語の周りの長方形をキャプチャし、次にAutoITを使用して単語をマウスクリックします。

問題は、私の座標が上から約10ピクセルずれていることです。

何が間違っているのでしょうか?これが処理を行う関数です。AutoIT処理をコメントアウトしました。実際の座標を表示するために、MessageBoxを使用してデバッグしています。次に、AutoITのウィンドウ情報ツールで確認しましたが、間違いなくオフになっています...何か間違ったことをしているのですか、それともMODIに問題がありますか?

public void ProcessGetWindow(Bitmap image)
        {           
            Document modiDoc = null;
            MiDocSearch modiSearch = null;
            IMiSelectableItem modiTextSel = null;
            MiSelectRects modiSelectRects = null;
            MiSelectRect modiSelectRect = null;
            MiRects modiRects = null;
            int intSelInfoPN;
            string intSelInfoTop;
            int intSelInfoBottom;
            string intSelInfoLeft;
            int intSelInfoRight;            

            // Load an existing image file.
            modiDoc = new Document();
            modiDoc.Create(@"C:\\temp.bmp");

            // Perform OCR.
            modiDoc.Images[0].OCR();

            // Search for the selected word.
            modiSearch = new MiDocSearch();
            modiSearch.Initialize(modiDoc, "Click Me", 0, 0, false, false);
            modiSearch.Search(null, ref modiTextSel);       

            try
            {          
                modiSelectRects = modiTextSel.GetSelectRects();
            }
            catch (COMException)
            {
                MessageBox.Show("Me thinks that the OCR didn't work right!");
            }

            foreach (MiSelectRect mr in modiSelectRects)
            {
                //intSelInfoPN = mr.PageNumber.ToString();
                intSelInfoTop = mr.Top.ToString();
                //intSelInfoBottom = mr.Bottom;
                intSelInfoLeft = mr.Left.ToString();
                //intSelInfoRight = mr.Right;

                /*AutoItX3 auto = new AutoItX3();
                auto.AutoItSetOption("MouseCoordMode", 2);
                auto.MouseClick("", intSelInfoLeft, intSelInfoTop, 1, 80);*/

                MessageBox.Show("Coordinates: " + intSelInfoLeft + ", " + intSelInfoTop, "Coordinates", MessageBoxButtons.OK);            
            }

            //string textResult = modiTextSel.Text;

            //MessageBox.Show(textResult, "Search Results", MessageBoxButtons.OK);

            // Close this dialog.
            Application.Exit();
        }
4

3 に答える 3

1

同じプログラムを使用して場所を見つけています。

int centerwidth = (intSelInfoRight - intSelInfoLeft)/2;
                centerwidth = intSelInfoLeft + centerwidth;
                 int centerheight = (intSelInfoBottom - intSelInfoTop)/2;
                 centerheight = centerheight + intSelInfoTop;

それを使用して、テキストの正確な中間点を見つけることができます。

しかし、このプログラムは常に単語の最初の出現位置を提供し、次の出現位置を提供しません。すべての出現箇所でテキストの場所を見つける方法を教えてください。

于 2014-04-29T09:07:50.917 に答える
0

私は提示されたツールに精通していませんが、私が読んだところによると、GetSelectRects関数は外接する四角形を返します。これは、選択範囲全体を含む最小の四角形です。この場合は、検索した単語です。何が起こるかは、単語がある中央ではなく、外接する四角形の角をクリックしていると思います。

長方形の中心の座標を計算し、それをクリックしてみてください。

int height = mr.Bottom - mr.Top;
int width = mr.Right - mr.Left;

AutoItX3 auto = new AutoItX3();
auto.AutoItSetOption("MouseCoordMode", 2);
auto.MouseClick("", width/2, height/2, 1, 80);
于 2012-01-27T06:28:34.600 に答える