3

I have a screenshot of a window. I would like to find the bounds of a string that is in the image. For example, I would like to get the bounds of the text "label2" in the following image:

enter image description here

I realize that this probably requires re-scaling the image and using OCR. Unfortunately, information I could find about OCR revolves around reading the text, not finding it. What can I use in .NET to accomplish this (and how)?

Tamás Szelei
  • 23,169
  • 18
  • 105
  • 180
  • Do you have access to that window? It sounds like you're asking for a window outside your solution. Also, are you taking the screenshot, or are you processing a screenshot taken at a different time/place? – Shannon Holsinger Sep 13 '16 at 13:03
  • @ShannonHolsinger the window belongs to an application that runs on the same computer as mine does. I can't use the `GetWindowText` WinAPI because the text does not belong to a control as its text, it is just drawn there by other means. I'm taking the screenshot in my application. – Tamás Szelei Sep 13 '16 at 13:04
  • Is the text you're after always the same or does it fluctuate (different letters/font or same letters/font). – Shannon Holsinger Sep 13 '16 at 13:06
  • @ShannonHolsinger I can't make assumptions about the font, but for one string in the same application it stays the same. So I can assume that "label2" in the same application always looks the same. "label1" might look different. – Tamás Szelei Sep 13 '16 at 13:10
  • You might want to look into using [Tesseract](https://www.nuget.org/packages/Tesseract/). Like most OCR engines it will give you bounding boxes for the characters that it reads. It would be up to you to determine which ones are what you are looking for which you haven't really made clear here. – juharr Sep 13 '16 at 13:11
  • @juharr Tesseract is definitely on my radar, but I couldn't find information about how to get the bounding boxes and how to use it from .NET (I found old wrappers with bad documentation) – Tamás Szelei Sep 13 '16 at 13:13
  • That's where I was going... IDK if spy++ allows for that functionality. – Shannon Holsinger Sep 13 '16 at 13:15
  • There's also this I used for something similar. It's been a while and I don't recall the specific functionality but maybe it will help... http://www.codeproject.com/Articles/9741/Screen-Captures-Window-Captures-and-Window-Icon-Ca – Shannon Holsinger Sep 13 '16 at 13:21
  • Id' really appreciate it if you'd share your answer when/if you find one. Wish I had more to help with. Good luck!! – Shannon Holsinger Sep 13 '16 at 13:28
  • May be you can try Sikulix ( http://sikulix-2014.readthedocs.io/en/latest/index.html) , i think it has c# wrapper – Ram Sep 13 '16 at 13:44

0 Answers0