1

So, I'm using tesseract, with this implementation https://github.com/charlesw/tesseract

The code to get text from an image is,

Bitmap img = new Bitmap("image.JPG");
TesseractEngine engine = new TesseractEngine("tessdata", "eng", EngineMode.Default);
Page page = engine.Process(img, PageSegMode.Auto);
string result = page.GetText(); 
Console.WriteLine(result);         

And that works as expected, but the thing is what I want is for the program to continuously watch the screen and get any text that comes up in real time.

Now, what I could do, I guess, is take a screenshot every iteration of the theoretical loop I'm gonna make, replace the old image and just scan the new one for text.

That seems rather inefficient what with the constant creation of new screenshots and replacing the old.

So, what I'd like to know is just... is there any way to scan the screen at all times, without having to make screenshots?

Perhaps somehow turn the contents of the screen into a Bitmap directly, so that Bitmap img = new Bitmap("image.JPG"); can be skipped?

  • 1
    This sounds extremely implementation specific. Ultimately you have to give Tesseract a bitmap, right? The question is how to get that bitmap at all times? If you were using DirectX for example you would have access to the frame buffer at all times, and could copy that into RAM, and feed it to Tesseract as often as you wanted. I assume that's not your situation though. What is this application and what platform does it run on? – Emperor Eto May 31 '21 at 20:27
  • 1
    "turn the contents of the screen into a Bitmap directly" Yes that's possible, you don't have to go through a file. See https://stackoverflow.com/a/363008/103167 – Ben Voigt May 31 '21 at 21:34
  • @BenVoigt Right well, that seems to do the trick, but I'm faced with a new problem. I need to show the text on an overlay of some kind, but if I do that, it would read the text that it's already read, I assume. So is there a way to make it scan only a specific window? – AmDesperate Jun 01 '21 at 15:05
  • You can blit from a single window but depending on window manager and settings, the window might not be painting areas that are covered by other windows. So there might not be anything there for you to grab if you're putting your OCR results over the top. Start with `Graphics.FromHwnd` but you may quickly find that you need some p/invoke. – Ben Voigt Jun 01 '21 at 15:09

0 Answers0