Python Switching Active Cameras - python

Here is the objective I wish to achieve: I would like to connect multiple web cameras to a single Windows machine and take snapshots from one of them at different instances (so one camera must active at one point of time, while another must be active at another). From what I have tried, an user has to go to the control panel and set which camera should be active at a given moment to use it. Is there a way to achieve this objective via python? (If there is a way to keep all cameras active at once, how should I specify which camera should take a snapshot?

I have investigated a couple options since then. One of the tools that I could utilize is devcon, through which usb cameras could be disabled/enabled to take snapshots. Another (simpler) option is to use a function in python opencv - cv2.VideoCapture(i) will automatically allow the program to iterate through different camera devices connected to the computer via usb.

Related

OpenCV connection ps3 eye camera (python)

Heading I need to get an image at the same time (almost, it is possible to take turns in a loop) from two PS3 Eye cameras, and then work with them using OpenCV.
We need drivers for the ps3 eye multicam (for example, these are not suitable https://codelaboratories.com/downloads/)
As an option for drivers there is a program zadig(https://zadig.akeo.ie/), and in particular WinUSB (libusb), but OpenCV Python (the standard function cv2.VideoCapture) sees only one camera. I found a project that can use several cameras at once in OpenCV with WinUSB drivers (libusb) - https://github.com/psmoveservice/PSMoveService/releases (Open bin/test_camera.exe). But it is written in C++ and due to its incompetence in this programming language, I could not port the code to python.
In the end, I need drivers and Python code to use the ps3 eye multicam in OpenCV.
Try checking this. Get the environment you want to build.
https://github.com/bensondaled/pseyepy
Let's you configure the camera as well.

How to access webcam stream by ID on Windows

I am working with two webcams, currently using Python and OpenCV. The system is set up in a way that one camera is on the right and one camera is on the left. For the system to work correctly, knowing which camera is in which position is required.
The following is a way to stream video from the two webcams at once:
camera1 = cv2.VideoCapture(0)
camera2 = cv2.VideoCapture(1)
However, this is not ideal for me since there is a possibility that the left and right camera would switch index if they are unplugged and re-plugged. Is there a way, through OpenCV or otherwise, to open a video stream from a camera based on some sort of camera ID?
For a follow up question, although it would not be ideal, I would be ok with having to always plug each camera into specific USB ports. Is there a way to stream a camera from a designated port? For the VideoCapture function I mentioned earlier, is the index based on USB port or is it arbitrary? If the index assignment is consistent (i.e. the lowest active USB port always gets assigned 0, etc.), then this could be a solution to my problem. Through my testing this seems to be the case, but I would like to be sure.

Embedded linux printer using cups raster driver

I'm busy with a project to make a custom printer. basically a RPi/beaglebone connected to a gantry with stepper motors and a print-head.
I'm working on getting this setup to print an image from memory (with python), but I want to be able to print essentially any format from any application.
At this point I think the easiest way would be to setup CUPS on RPi to appear as a network printer over Wi-Fi. I've seen a few tutorials showing how to do this with a regular USB printer.
So I'd like to know how to write a custom CUPS raster driver that just takes the file and saves it as a raster image in memory at a specific dpi.
Otherwise, I'd like to know if there is an easier way to do this. It seems one should be able to simply query CUPS for a raster version of any job in the queue, not so?

python-wnck how to get monitor properties

python-wnck has Screen object which combines the areas of multiple monitors and gives it in get_screen_size(). How to get the size of individual monitors. I am trying to move a window from one monitor to another
There are a lot of methods listed here : How do I get monitor resolution in Python?
I'm not sure if all the methods works for multiple screens. If you're using Window, try to run this code : http://code.activestate.com/recipes/460509-get-the-actual-and-usable-sizes-of-all-the-monitor/

Duplicate device input events on unix (/dev/input/event)

I'm using linux/ubuntu, and I would like to play a little bit with my touchpad. I'm trying to use python-evdev to read events from /dev/input/events, for now just printing them:
import evdev
dev = evdev.InputDevice('/dev/input/event6')
import time
while True:
try:
for event in dev.read():
print event
except:
print " ~ "
time.sleep(.5)
If I do run that script in with root privilege in a virtual console (outside X, pressing ctrl+alt+F1), the script does print events when I touch the touchpad. Yet, if X is on screen and I run this in a gnome-terminal console, nothing is printed; I somehow guess this is normal, the inputs are intercepted by X. Yet I would like to get them anyway. Is there a way to duplicate whatever comes from /dev/input/event6 so thqt both X and my script can read all events ?
sorry, a bit late on the answer here.
Up until version 1.8, the xorg synaptics driver used the EVIOCGRAB ioctl to prevent events to be delivered to other clients. That's disabled now by default, you can still use the GrabEventDevice option to disable it on your machine for older versions (see man synaptics).
In short, nothing wrong with your script, it's the synaptics driver that's the problem here. You'll find that your script will work on other devices just fine (though the xorg wacom driver did also grab the device until recently).
upstream commit in synaptics:
http://cgit.freedesktop.org/xorg/driver/xf86-input-synaptics/commit/?id=f1948e08ee9894864254a18098e4f4fceb6e322f
So, your idea is, X got the data from your touchpad, so that your python code is blocked from receiving touchpad signal, right? Or, may I repeat your words as: at least for some specific kind of device, an application can't get /dev/input/event*, when another is reading from that device?
Theoritically, since linux make all devices as a file, you are accessing a file as read-only, while X is also read-only accessing the file.
I just did another experiment as: I have a infrared reciver on my archlinux, and I connected to the system in two ssh consoles. I use two ways to access IR, that is, two applications to read the file of /dev/input/event0 (event0 is the SF on my arch):
1, a piece of python code, with evdev;
2, a shell command as: sudo cat /dev/input/event0 | hexdump
You can look on the 2nd as working as your X. If you were reasoning correctly, they both should not receive data from the IR (event0) on the same time, when I sending signal from a IR remote controller, right? But, I really got date on the two ssh consoles(I wish I could post image, but I am new with too low reputation to do so).
So, I think it should not be the reason. I guess it might be because of your touchpad itself. You know, some devices can only work on a single application. e.g., keyboard can only enter characters on the active application, and some input method just make itself as active over other applications, and redirect after it processed. Also, say, if you had a VM running on your system, and you use only one mouse, what would happen if you are moving pointer on the host desktop? Will the pointer in VM move? Or vice versa?
So I need more info about your touchpad. If your TP works only with a single active applicatio, I am afraid you need somethink like a hook to get touchpad signal ahead of X, and redirec it to X and your python code, which might be beyond evdev.
You could create a kernel input handler based on evdev so that the device input is distributed both to the normal /dev/input/eventN and, let's say, /dev/input/copied_eventN
X would read from /dev/input/eventN but you would still be able to read from /dev/input/copied_eventN
Actually you could very easily create a kernel module by copy-pasting the code in drivers/input/evdev.c

Categories

Resources