Categories
Linux Mastering Development

Is it possible to use GDK to get the image/pixel data of any arbitrary X11 window using the window’s name?

Summary

I am writing a script (in Python 3.X) to do image detection on a number of different GUI’s in Linux. Can GDK be used to get a pixel buffer of any X11 window? If so, how? I am currently using the wnck library

I’m aware of this thread, but it only shows getting the current processes window.

Elaboration

When I say "image data" i’m essentially referring to a screenshot, but I don’t necessarily care about saving it. A pixel buffer might be the more appropriate terminology.

This is a variation of a question I asked on StackOverflow about how to achieve getting image data specifically with Python.

To prevent an XY problem: I need to do some image detection on GUIs running in both Linux and Windows. I have working code for Windows 10 that gets an applications image data using the win32 API and puts it into a numpy array for using with OpenCV. I now need a similar approach for Linux. I have started researching X11 and available python libraries, but I keep coming back to a thread that shows using gdk in python to get the screenshot of the invoking process. I want to be able to do it for any X11 window.

Leave a Reply

Your email address will not be published. Required fields are marked *