peter.arun has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I am trying to get text from a window. i was able to capture the window as a screenshot. is there anyway to get text from a screenshot. or do i have to convert it to an image. Please help me in resolving the issue. Thanks and Advance, Peter..

Replies are listed 'Best First'.
Re: getting text from a window
by almut (Canon) on Jun 26, 2008 at 11:08 UTC
    is there any way to get text

    This may be difficult...  Which window/application, which OS? Can you select the text (with the mouse) for cut-n-pasting?  If all you can obtain is an image, you'd have to resort to OCR...

      Hi, Thanks for the reply. the OS is Windows XP . I am able to select the text with the mouse manually and paste it. Actually i captured the window as a screenshot with the help of Imager::screenshot module. Now iam trying to get the text from the screenshot. Thanks and Regards Peter...
Re: getting text from a window
by BrowserUk (Patriarch) on Jun 26, 2008 at 13:35 UTC

    Converting the text in a window to an image and then attempting to convert it back to text is a very complicated and error prone way of achieving your goal.

    If you can select the text you want to capture with the mouse, then you can obtain that selected text within a perl program very easily using Win32::Clipboard.

    If the text you wish to capture is non-selectable, then you might need to look at Win32::GUI::Test and the GetWindowText() method.


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
Re: getting text from a window
by wazoox (Prior) on Jun 26, 2008 at 13:37 UTC
    That sounds pretty tricky... You should search CPAN for some of the OLE:: or Win32:: to see if something may select text and/or copy selection to clipboard, for instance Win32::CtrlGUI. From there Win32::Clipboard will allow you to manipulate clipboard content.
Re: getting text from a window
by swampyankee (Parson) on Jun 26, 2008 at 12:56 UTC

    Usually, e.g., in my experience, screenshots are images. If this is the case, you'll have to use an OCR application to convert the image to text. I would suggest that you try to capture the actual text, vs the rendered image of the text. How you would do this is dependent on the O/S and application(s) involved; you will have to be forthcoming with much more detail to get any kind of specific help.


    Information about American English usage here and here. Floating point issues? Please read this before posting. — emc