How to select a different webcam using cv2 in python - python

I am trying to stream live video from an external camera using cv2. I was able to write the simple code to stitch the frames and stream it. But am struggling to find how to change the camera.
I tried to run it after disabling the main webcam from the task manager, but it still did not work.
So, if anyone can help me with some clue regarding the same, that would be a great help.

Cameras are numbered for Windows. You can try a few indeces and check which camera index belongs to the camera you want.
capture = cv2.VideoCapture(index)

Related

Python OpenCV with Imaging device USB3 Vision compliant camera - VideoCapture() index of camera not found

I have a problem with using external camera in Python OpenCV.
I am using Windows.
In device manager, camera is not under "Cameras", but under "Imaging devices" and is called USB3 Vision compliant camera.
The camera is working fine on app given by company (UcamViewer).
I want to connect to this camera using cv2.VideoCapture().
I have of course tried:
cv2.VideoCapture(k)
for k = [0..100]
Only k = 0 is occupied and works - that is my webcam.
I have also tried adding multiple possible values to the second parameter of the VideoCapture(), which did not work.
how to get video from a "USB3 Vision" device?
This question suggested to use cv.CAP_XIMEA as the second parameter of VideoCapture(), but CAP_XIMEA does not seem to be a possible value.
If I can not fix this issue and use VideoCapture(), what would you suggest to use to capture the video and convert it to format that can be used by openCV methods?
Any ideas how could I solve this issue will be appreciated.
Thank you for your help.

Speeding up frame capture in openCV (python)

I'm working on an application in python using opencv for use in athletic coaching. I'd like it to run at 60fps, but I can't seem to get it to that speed. I've determined that the part that is slowing everything down is the capture process; frames aren't getting from the camera to the cpu fast enough.
Now, I know it is possible for the camera to run at 60fps, because when I open up the same camera in guvcview (at the same resolution), I can get a full 60fps.
I don't want to share my entire project, but here's the part that manages frame capture: https://pastebin.com/nnx32rQK
Any help would be welcome!

How would I go about playing a video file with sound in Python and setting the play position?

I'm using ffmpeg to process video files using Python, but I want to be able to open a local video file and use a few sliders to control the timeline in the video, that way I can get the timestamp from where those sliders were moved.
The goal is to get the beginning and end time of the set positions using the sliders, that way I can cut the video at those times using ffmpeg.
Any help would be appreciated...
Thanks
I ended up using python-vlc which works great in Tkinter.
Here's an example VLC has on their website which was a big help.
http://git.videolan.org/?p=vlc/bindings/python.git;a=blob;f=examples/tkvlc.py;h=55314cab09948fc2b7c84f14a76c6d1a7cbba127;hb=HEAD
Here you can find the documentation:
https://wiki.videolan.org/PythonBinding

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.

Embed usb web camera video in to wxpython

I need to display the USB camera video of raspberry-pi in Wxpython with control buttons in it. I have managed to embed vlc in to Wxpython with control buttons (Got it from Google) to play existing video. Is there any way to stream the USB camera video in it?
Thanks in advance :)
If you've managed to embed VLC, you should just be able to point it at the v4l address for the webcam.
The v4l address should be along the lines of v4l:/dev/video0:size=640x480 (but it'll vary depending on your machine I guess). You may find it easier to use the standalone VLC client to get the address you need and then put it into your program.
This StackOverflow thread may be useful for later depending on what you're doing.

Categories

Resources