title: How to find specific text on the screen and its location? C#
body: <p>I wanted to be able to <strong>check if specific text is displayed somewhere on the screen</strong> and, if possible, <strong>determine its location</strong> so that the program could display a popup above the specific text.</p>
  <p><strong>I tried to use OCR</strong> (Tesseract) to scan screenshots but it correctly sees the text about <strong>20% of the time</strong>, even after trying multiple image formats. Is this a common problem, is Tesseract not a great OCR, or are there any ways to improve the quality of the screenshots for the OCR to work better?</p>
  <p>I capture and save the screenshots this way:</p>
  <pre><code>Bitmap captureBitmap = new Bitmap(1920, 1080, PixelFormat.Format32bppPArgb);
  Rectangle captureRectangle = Screen.AllScreens[0].Bounds;
  Graphics captureGraphics = Graphics.FromImage(captureBitmap);
  captureGraphics.CopyFromScreen(captureRectangle.Left, captureRectangle.Top, 0, 0, captureRectangle.Size);
  captureBitmap.Save(@&quot;./Capture.png&quot;, System.Drawing.Imaging.ImageFormat.Png);
  </code></pre>
  <p>The OCR (Tesseract) is implemented this way:</p>
  <pre><code>var ImagePath = &quot;./Capture.png&quot;; 
  
  using (var engine = new TesseractEngine(@&quot;./tessdata&quot;, &quot;eng&quot;, EngineMode.Default))
  {
       using (var img = Pix.LoadFromFile(ImagePath))
       {
            using (var page = engine.Process(img))
            {
                  var text = page.GetText();
                  if (text.Contains(selectedword))
                  {
                        MessageBox.Show(&quot;This word is here&quot;);
                  }
            }
       }
   }
  </code></pre>
  <p><strong>Are there any better ways to scan the screen / screenshots for specific text?</strong></p>