MODI MiSelectRects 坐标错误

发布于 2024-12-27 14:08:48 字数 2436 浏览 1 评论 0原文

我有一个 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();
        }

I have a Windows Form app that, when executed, launches Firefox, grabs the process and handle of the window, and does a screen capture of Firefox, saves it to disk (temp.bmp) and calls ProcessGetWindow. I'm basically using MiSelectRects in MODI to capture the rectangle around the word that I'm looking for, and then I use AutoIT to mouse click on the word.

The problem is that my coordinates are off by about 10 pixels from the top.

Any ideas what might be wrong? Here's the function that does the processing. I have commented out the AutoIT processing, and I'm just debugging with a MessageBox to show me the actual coordinates. I then confirm with AutoIT's Window Info tool and it's definitely off... am I doing something wrong or is there something screwed up with 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();
        }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

如果没有你 2025-01-03 14:08:48

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

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

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

但是这个程序总是给出单词第一次出现的位置,而不是下一次出现的位置。请让我知道如何找到所有出现的文本位置。

I am using the same program to find the location.

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

u can find the exact middle point of the text using it.

But this programs always gives the location of the 1st occurence of the word and not for the next occurences. Please let me know how to find the location of the text at all occurences.

热血少△年 2025-01-03 14:08:48

我不熟悉所提供的工具,但根据我的阅读,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);

I'm not familiar with the tools presented, but from what I read the GetSelectRects function returns a bounding rectangle, that is the smallest rectangle that contains the whole selection, in this case the word you searched for. I believe what happens is that you're clicking the corner of the bounding rectangle instead of in the middle, where the word is.

Calculate the co-ordinates for the center of the rectangle and try clicking that:

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);
梓梦 2025-01-03 14:08:48
 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);



        }
 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);



        }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文