MODI MiSelectRects的坐标错误

本文关键字:错误 坐标 MiSelectRects MODI | 更新日期: 2023-09-27 18:20:50

我有一个Windows窗体应用程序,在执行时,它会启动Firefox,获取窗口的进程和句柄,并对Firefox进行屏幕捕获,将其保存到磁盘(temp.bmp)并调用ProcessGetWindow。我基本上是在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();
        }

MODI MiSelectRects的坐标错误

我正在使用相同的程序来查找位置。

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

你可以用它找到文本的确切中点。

但这个程序总是给出单词第一次出现的位置,而不是接下来出现的位置。请告诉我如何在任何情况下找到文本的位置。

我不熟悉所提供的工具,但根据我所读到的内容,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);
 MODI.Document modiDoc = null;
    MODI.MiDocSearch modiSearch = null;
    MODI.IMiSelectableItem modiTextSel = null;
    MODI.MiSelectRects modiSelectRects = null;
    MODI.MiSelectRect modiSelectRect = null;
    MODI.MiRects modiRects = null;
    int intSelInfoPN;
    int intSelInfoTop;
    int intSelInfoBottom;
    int intSelInfoLeft;
    int intSelInfoRight;
    // Load an existing image file.
    modiDoc = new MODI.Document();
    modiDoc.Create(@"C:'Users'h117953'Desktop'OCR'1.jpg");
    // Perform OCR.
    //modiDoc.Images[0].OCR();
    //MODI.Image image = (MODI.Image)modiDoc.Images[0];
    modiDoc.OCR(MiLANGUAGES.miLANG_ENGLISH);
    MODI.Image modiImage = (modiDoc.Images[0] as MODI.Image);

    //string ocrtext = @"C:'Users'h117953'Desktop'OCR'Sample.txt";
    //File.WriteAllText(ocrtext, modiImage.Layout.Text);
    // Search for the selected word.
    //int wordindex
    modiSearch = new MODI.MiDocSearch();
    //date to search 
    modiSearch.Initialize(modiDoc, "Deer", 0, 2, false, false);
    modiSearch.Search(null, ref modiTextSel);
    if (modiTextSel == null)
    {
        Response.Write("'nText not found 'n");

    }
    else
    {
        Response.Write("'nText is found 'n");
        try
        {
            modiSelectRects = modiTextSel.GetSelectRects();
        }
        catch (Exception)
        {
            Response.Write("Me thinks that the OCR didn't work right!");
        }
        int centerwidth = 0;
        int centerheight = 0;
        foreach (MODI.MiSelectRect mr in modiSelectRects)
        {  
            //intSelInfoPN = mr.PageNumber.ToString();
            intSelInfoTop = mr.Top;
            intSelInfoBottom = mr.Bottom;
            intSelInfoLeft = mr.Left;
            intSelInfoRight = mr.Right;

            // MessageBox.Show("Coordinates: " + intSelInfoLeft + ", " + intSelInfoTop, "Coordinates", MessageBoxButtons.OK);
            //  MessageBox.Show("Coordinates: " + intSelInfoRight + ", " + intSelInfoBottom, "Coordinates", MessageBoxButtons.OK);
            centerwidth = (intSelInfoRight - intSelInfoLeft) / 2;
            centerwidth = intSelInfoLeft + centerwidth;
            centerwidth = (intSelInfoBottom - intSelInfoTop) / 2;
            centerheight = centerheight + intSelInfoTop;
            //MessageBox.Show("Coordinates: " + centerwidth + ", " + centerheight, "Coordinates", MessageBoxButtons.OK);
            Response.Write("the Widht and Height co-ordinates are (Width,Height)= ({0},{1})" + centerwidth + ","+ centerheight);

        }