2012-01-19 4 views
1

У меня есть приложение Windows Form, которое при запуске запускает Firefox, захватывает процесс и дескриптор окна и делает захват экрана Firefox, сохраняет его на диск (temp.bmp) и вызывает ProcessGetWindow. Я в основном использую MiSelectRects в MODI, чтобы захватить прямоугольник вокруг слова, которое я ищу, а затем я использую AutoIT, чтобы щелкнуть мышью по слову.MODI MiSelectRects получает неправильные координаты

Проблема в том, что мои координаты отключены примерно на 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(); 
     } 
+0

FYI, Microsoft устарел MODI. Когда ваши пользователи перейдут на Office 2010, у вас возникнут проблемы. – TrueWill

ответ

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

Я использую ту же программу, чтобы найти место.

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

u можете найти точную среднюю точку текста, используя его.

Но эти программы всегда дают местоположение первого появления слова, а не для следующих случаев. Пожалуйста, дайте мне знать, как найти расположение текста во всех случаях.

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



     } 
Смежные вопросы