How I can retrieve webcam info in python? - python

I need to retrieve the number of webcams instaled in my system and the brand, manufacturer, device id, etc., of the webcam.
Is there any way to do that in Python, and independent of the operating system?

There's no truly cross-platform solution, but on Linux you can use os.popen('lsusb') (or something along those lines) and then just scrape the screen (using grep or something else). For finding out on Windows, you can try using a TWAIN binding for Python (it's the Windows webcam protocol, a Python binding exists here, but it's not actively maintained). VideoCapture might have what you need.

I found a partial solution, which is to use the command:
v4l2-ctl --list-devices
But only works on Linux, but on Windows I have no way of detecting the amount and the name of the installed webcams.

Related

Is it possible to use socketCAN protocol on MacOS

I am looking to connect to a car wirelessly using socketCAN protocol on MacOS using the module python-can on python3. I don't know how to install the socketCAN protocol on MacOS. Pls help.
This cat managed to get it basically working:
socketcanx
I have compiled it on my hackintosh (running Mojave) and it works from the terminal. I have not played around with it more than that, as it was just easier to use Liunx in a VM or docker or one of my Linux machines. When compiled, I was able to use all of my makeshift CAN devices and a USB2CAN device without issue. I am sure with some work, it can be used with Python-CAN, though you would need to write your own interface module for Python-CAN. As far as I can tell, it should work more or less the same, though the code is old (4 years since last update).
As stated in the accepted answer, you can use a native CAN device that is compatible with macOS and as long as it's compatible with Python-CAN, then you are good to go (or if it works on mac and not compatible, you can create and interface for the device and submit a pull-request on github for Python-CAN).
SocketCAN is implemented only for the Linux kernel. So it is not available on other operating systems. But as long as your CAN adapter is supported by python-can, you don't need SocketCAN.

How to capture screen on Wayland(Gnome) in Python code?

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 ;-)

How to control Enttec Open DMX USB via Python?

I'm wondering is that possible to control lights connected to Enttec Open DMX USB via Python shell. If it is, how to?
The Open Lighting Project (formerly known as opendmx) provides a Python API, as part of their Open Lighting Architecture (OLA), for use the OpenDMX USB on OSX and Linux. If you're on Windows then I've not found anything apart from the code from Enttec's website which uses the FTD2XX.DLL libraries.
However it should be noted that one cannot use normal serial based libraries (pyserial etc). Basically OLA either needs to use a special kernel module on Linux, or use the generic FTDI non-serial kernel driver in combination with libftdi on Mac or Linux - for details see their device specific page. There is now pre-built support for Raspberry Pi's on the OLA website.
The communication and protocols used are completely different from Enttec Pro range (which one can just control using simple serial commands with something like pyserial, though OLA also talks to them too).
I know this is quite an old post, however DmxPy has worked very well for me the last few months. It only works for Python 2 but I know there's some Python 3 ports out there.
It's stupid simple to use. I personally use it in my companies quality control software. While it only work for DMX (not RDM) I think it's much easier to use than OLA's Python Wrapper. It works flawlessly with our ENTTEC as well!
UPDATE: Here's my Python 3 port: https://github.com/trevordavies095/DmxPy
I had the exact same problem, so I wrote a simple python programm for all those that are running windows; have a look: https://github.com/Coronon/PyOpenDmxUsb
It uses a C# Server (Because their C# interface was the only one that worked for me) and a Python Client and is super easy to use.
It is compatible with the non pro version too. (The Pro Version is way easier to use and I would use the AcceptedAnswer instead [But the normal one isnt supported])
Edit: This may be 'advertisement' but my project is Open-Source and super easy to use, so I believe this can be useful to others :)

Tablet Pressure with Python on Linux

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.

is there an API for python to work with pressure-sensitive pen-tablets? (Mac OS, Linux)

I want to write a cross-platform wxPython app, and I'm wondering if there a single API to work with pen-tablets on different platforms? I'm only interested to get pressure value and ereaser flag - but I couldn't fined anything cross-platform for python.
UPD. so far, I found only windows-specific solution, what are the options for Mac OS and Linux?
https://bitbucket.org/AnomalousUnderdog/pythonmactabletlib
A small Python library to allow Python scripts to access pen tablet
input data in Mac OS X.
The library exists as plain C code compiled as a dynamic
library/shared object. It interfaces with the Mac OS X's API to get
data on pen tablet input.
Then, Python scripts can use ctypes to get the data.
Send me a message if you have any problems with it.
If your target tablets are HIDs, which they probably are, you can use python-hid.

Categories