Reputation: 51
I've recently come across the need for identifying which device (device name) is associated to which source input (device index) for OpenCV's VideoCapture() for my project.
Since I'm using OpenCV's Python port (v3.3.0.10 according to PyCharm), there are various backend functionalities that, based on my research endeavors, are apparently not available to my manipulation from Python.
Being on Windows 10 Home 64-bit, and using Python 3.6.3, I came across this handy work done by Xiao Ling which creates a dedicated Python2 extension for exactly my needs. After rustling with the C++ file using Python3's documentation to make it Python3 compatible, it compiled successfully. I then ran a test and it worked to my expectation.
Out of sheer curiosity, and having Python 2.7.14 on-hand (Note: OpenCV v3.3.0.10 is also installed for my Python2 - according to PyCharm), I went ahead and compiled the same C++ extension for Python2, using the same setup.py. It compiled successfully, then, I ran the same test.py ...but got different results.
The results for when I run test.py for Python 3 is (correctly) as follows:
Note: I stopped the code during runtime while it waited for user input.
OpenCV version: 3.3.0
0: DroidCam Source 3
1: Integrated Webcam
Select a camera (0 to 1):
Process finished with exit code 1
And, the results for Python2... also "correct":
OpenCV version: 3.3.0
0: DroidCam Source 3
1: Integrated Webcam
2: DroidCam Source 1
3: DroidCam Source 2
4: DroidCam Source Mini (240p)
Select a camera (0 to 4):
Process finished with exit code 1
My camera setup on my laptop is as follows:
Note: DroidCamX has a desktop application that works in conjunction with the Android DroidCamX app.
Note2: I am using DroidCamX over a (physical/wired) USB connection.
I am infact, only using 2 physical cameras - (expected) device indexes 0
and 1
- which makes the output of the Python3 completely correct and therefore works as intended. However, using Python2, when I access device indexes 2-4
, all return a "correct" video feed from my phone - including index 4
which specifies a 240p video feed.
Hence, my question; Why is the output from Python2 and Python3 different? Why is Python2 showing 3 other available video feeds (which all seem to be "correct")?
Note: "correct" is in reference to using the correct physical device, in the correct mode, despite being incorrect with respect to the number of physical cameras.
Note2: All code is linked to this question using hyperlinks in an attempt to minimize the length of this question.
Upvotes: 2
Views: 135
Reputation: 51
DroidCam Source 1, 2, and Mini (240p) are DirectShow video source filters. I assume python 3 either does not support DirectShow, or its use is somehow disabled by default. Source 3 and the integrated webcam use full blown kernel drivers.
Upvotes: 2