5

I'm trying to capture my screen using Python because I'll use it on OpenCV, but I couldn't find a way to make it work on Gnome, since Gnome uses Wayland and all libraries that I've found only work with X11.

For now I'm not considering change my interface. I'm searching a solution to this problem. Does someone know a solution?

To be more specific, I'll use the images to train an AI and so I need they continuously.

EDIT: I've found this but how can I pass frames to OpenCV in Python instead of save a video file?

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
  • as of May 2017, Wayland is not used by any major Linux distribution by default. I guess it will take another year or two to be fully adopted by Debian and even longer for other distors. Also, I'm pretty sure X11 fallback will be kept for compatibility. Did you actually try using X11 libraries? – Marat May 22 '17 at 04:12
  • They don't work, throwing some error, or give me a black picture. Using pyscreenshot, it "works" giving me black images. I've tryied using different backend options, PyQt, PyGTK and Imagemagick, on the grab() function. – Pedro Vinicius May 22 '17 at 04:47
  • @Marat Fedora already uses Wayland by default (if drivers support it). Debian GNOME team at least planned to switch to Wayland after Stretch is released. – Jussi Kukkonen May 22 '17 at 08:24
  • @jku I would not say Fedora is a terribly popular distribution, and Stretch takes more time than initially planned. Pedro, do you happen to test this on Fedora 25? – Marat May 22 '17 at 13:07
  • "Fedora is not a terribly popular distribution" - okay then :) – Jussi Kukkonen May 22 '17 at 13:38
  • @Marat I'm using Arch Linux. – Pedro Vinicius May 22 '17 at 21:28
  • @PedroVinicius then, if you did not explicitly switch to Wayland, I assume the problem is not in X11 compatibility – Marat May 22 '17 at 23:31

1 Answers1

1

The proper way to do screencasting these days is by using the Screencast portal, which is part of XDG desktop portals and is already supported by GNOME, KDE, wlroots (and more). As an added advantage, this will also work in containerized formats like Flatpaks.

You can find an example on how to do screencasting in Pyhon using this snippet, created by one of the Mutter maintainers. If you look for parse_launch(), you will see a GStreamer pipeline which you can modify to include the GStreamer OpenCV elements that can do the processing for you.

Note: in your edit, you link to a predecessor of that portal, which is GNOME-specifc, internal API, so I wouldn't rely on it ;-)

nielsdg
  • 2,318
  • 1
  • 13
  • 22