I'm learning Python now and I want to develop a screen capture tool in Python.How I can do this work?
If you're on windows, use ImageGrab module along with Imaging library.
Something like:
from PIL import ImageGrab
ImageGrab.grab().save("screenshot.jpg", "JPEG")
I think the best way to do this would be create a higher level interface to ffmpeg. Unless you want to write the code to deal with X11 and record the screen, then it would be the best option.
If you test it on various platforms, then give useful error messages on things like incompatible sound systems, where to get certain video drivers, etc then this could be a pretty useful program.
Related
I am having an issue with PIL (python image library). Same code running on standard raspbian and the same on custom Yocto OS don't have the same output. The yocto one is deformed, especially the 0 character
I am using python 2.7 and PIL 1.1.7.
I tested increasing gpu_mem to 128Mb on the yocto, use vc4graphics but this is not changing anything. I guess there's something I don't think about as I'm inexperienced with image rendering.
I would like to understand how to debug this.
Raspbian:
Custom Yocto:
Thanks
Well, there are too many assumptions to say anything definitely.
Are both systems using same graphical backend?
If not, you should probably match them.
It's not "Yocto OS", it's usual Linux, Yocto is just a tool to improve work-flow of building Linux.
What LCD are you using?
Usually when you are developing for board, with some new model of lcd, you also get a datasheet from vendor to tweak different parameters. I had the same problem with display not being crisp, look for lcd display section of .dts file. There should be parameters like "bits-per-pixel", which you should match to what is advised in a data-sheet.
In your case since you have 2 systems with one having a clear image and one having a fuzzy one, I can advice to look for .dts file on both systems and match lcd sections for them. Just an example of a path to .dts file in Yocto
build/tmp/work-shared/imx6ulevk/kernel-source/arch/arm/boot/dts/imx6ul-14x14-evk.dts
Find .dts files for both systems, look for what's different in lcd display section and copy raspbian lcd parameters to your Yocto .dts file.
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?
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 ;-)
Is there a simple way to get the pen pressure data from a usb tablet using python on Linux?
You can do it by reading input events on the input device node. I wrote some modules to do this. you can find it in the Pycopia project.
The disadvantage of this is that your program must run as root.
The powerdroid project also uses this, but that's old code now. You can see another example of synthesizing touch input in the devices module. It probably won't work anymore, but you might start with that.
Try using PySide, it's a QT Wrapper here: QTabletEvent.
Or you can use Python and PyGame: Here.
I googled and search stackoverflow before asking this question
Answers that I don't expect:
wxWidgets is the best Python GUIUse TkInter (BIM) for GUI development.
Q. How to make a GUI without using any module/library? i.e make a GUI from scratch. Modules like tkinter not allowed.
I've made several GUIs from scratch using SDL which is a low level drawing library. The advantage of doing that is that it will look exactly the same on any platform down to the pixel and you can get it to work on embedded systems. Full screen GUIs are really easy too. Disadvantages are that it is a lot of work.
In python the pygame library wraps SDL so you would use that, and in fact that is how I made the GUI for a lab instrument which had a large colour LCD screen. The controller ran linux, but not X-windows.
pygame is an extra library, yes, but I can't think of a way of making a GUI with only what python provides.
The easiest GUI to make without "module/library" is a web-based one. I.e. generate HTML with Javascript from your Python code, and let the Javascript interact via AJAX with your Python app. This can be implemented without too much effort with just the standard Python library (and some JS code, of course), or with modules that don't require "heavy" installation of platform-specific extensions.
What is the most suitable way to capture a still image from Python and convert to a PIL image?
Google gives me numerous ways with OpenCV and lesser-known libraries. I want an easy, reliable, mature, cross-platform library for this purpose. And with minimal dependencies and extra packages.
If possible, it must also support displaying live images with major windowing toolkits, although the performance (frame rate, clarity) is not important.
I use gphoto2 and with subprocess. But it should be possible to access this library from ctypes, if you prefer this.
OpenCV's Python API is pretty solid at this point, and OpenCV is easily installed on all major platforms. It's good, and it's probably your best bet. Getting a live feed from a webcam can be done in as little as 10 lines of code.
PIL or its newer fork Pillow are also good, mature, and cross platform.
PyGame also has a camera module, an intro is here: http://www.pygame.org/docs/tut/camera/CameraIntro.html but I have noticed that getting PyGame to integrate gracefully into other toolkits (wx, Qt) can be difficult.