Errors opening webcams with VIdeoCapture

I’m using 4 Logitech C920 cameras with OpenCV 4.5.1 on Windows 10 (Version 20H2) and I’m getting errors opening the four streams.

Loading takes a long time with a verbose log (to follow shortly)

I’ve also tested with:

  • OpenCV 2.4.13: can open all 4 streams with no issues
  • OpenCV 3.4.13: same issues as OpenCV 4.5.1, verbose loading log then this:
[ WARN:0] terminating async callback
[ WARN:0] terminating async callback
cap0 backend name: DSHOW
cap1 backend name: DSHOW
cap2 backend name: DSHOW
cap3 backend name: MSMF
[ WARN:1] videoio(MSMF): OnReadSample() is called with error status: -1072875772
[ WARN:1] videoio(MSMF): async ReadSample() call is failed with error status: -1072875772
[ WARN:0] videoio(MSMF): can't grab frame. Error: -1072875772
error reading frame0

C:\dev\cv-tests\CVPrototypes\x64\Release\CV3Test.exe (process 38060) exited with code -1.
To automatically close the console when debugging stops, enable Tools->Options->Debugging->Automatically close the console when debugging stops.
Press any key to close this window . . .

If I set all 4 captures to be DirectShow I get the same 1 camera stream repeated 4 times.
If I leave the defaults I get 3 camera LEDs on, the rest off and 3 imshow windows with a duplicated stream frozen and the output:

[ WARN:0] terminating async callback
[ WARN:0] terminating async callback
cap0 backend name: DSHOW
cap1 backend name: DSHOW
cap2 backend name: MSMF
cap3 backend name: MSMF
[ WARN:1] videoio(MSMF): OnReadSample() is called with error status: -1072875772
[ WARN:1] videoio(MSMF): async ReadSample() call is failed with error status: -1072875772
[ WARN:0] videoio(MSMF): can't grab frame. Error: -1072875772
error reading frame0 

This is the basic snippet I’ve used for the test:

void main(){
    cv::VideoCapture cap0;
    cv::VideoCapture cap1;
    cv::VideoCapture cap2;
    cv::VideoCapture cap3;

    cap0.open(0);
    cap1.open(1);
    cap2.open(2);
    cap3.open(4);

    std::cout << "cap0 backend name: " << cap0.getBackendName() << std::endl;
    std::cout << "cap1 backend name: " << cap1.getBackendName() << std::endl;
    std::cout << "cap2 backend name: " << cap2.getBackendName() << std::endl;
    std::cout << "cap3 backend name: " << cap3.getBackendName() << std::endl;

    cv::Mat frame0;
    cv::Mat frame1;
    cv::Mat frame2;
    cv::Mat frame3;

    while (1) {
        cap0 >> frame0;
        cap1 >> frame1;
        cap2 >> frame2;
        cap3 >> frame3;


        if (frame0.empty()) {
            std::cerr << "error reading frame0" << std::endl;
        }
        else {
            cv::imshow("frame0", frame0);
        }
        if (frame1.empty()) {
            std::cerr << "error reading frame0" << std::endl;
        }
        else {
            cv::imshow("frame1", frame0);
        }
        if (frame2.empty()) {
            std::cerr << "error reading frame0" << std::endl;
        }
        else {
            cv::imshow("frame2", frame0);
        }
        if (frame3.empty()) {
            std::cerr << "error reading frame0" << std::endl;
        }
        else {
            cv::imshow("frame3", frame0);
        }



        if (cv::waitKey(15) == 27) {
            break;
        }
    }
}

The indices are indeed 0, 1, 2 and 4 as index 3 is a separate camera not in use.

Has anyone else experienced this ? Any tips/suggestions on how I might be able to get past these errors and use all 4 cameras in OpenCV 4 ?

Many thanks,
George

example log:

CVPrototypes.exe' (Win32): Loaded 'C:\dev\cv-tests\CVPrototypes\x64\Release\CVPrototypes.exe'. Symbols loaded.
'CVPrototypes.exe' (Win32): Loaded 'C:\Windows\System32\ntdll.dll'. 
'CVPrototypes.exe' (Win32): Loaded 'C:\Windows\System32\kernel32.dll'. 
'CVPrototypes.exe' (Win32): Loaded 'C:\Windows\System32\KernelBase.dll'. 
'CVPrototypes.exe' (Win32): Loaded 'C:\Windows\System32\ucrtbase.dll'. 
'CVPrototypes.exe' (Win32): Loaded 'C:\dev\vcpkg\packages\opencv4_x64-windows\bin\opencv_core.dll'. Symbols loaded.
'CVPrototypes.exe' (Win32): Loaded 'C:\dev\vcpkg\packages\opencv4_x64-windows\bin\opencv_highgui.dll'. Symbols loaded.
'CVPrototypes.exe' (Win32): Loaded 'C:\Windows\System32\gdi32.dll'. 
'CVPrototypes.exe' (Win32): Loaded 'C:\Windows\System32\win32u.dll'. 
'CVPrototypes.exe' (Win32): Loaded 'C:\Windows\System32\gdi32full.dll'. 
'CVPrototypes.exe' (Win32): Loaded 'C:\Windows\System32\msvcp_win.dll'. 
'CVPrototypes.exe' (Win32): Loaded 'C:\Windows\System32\user32.dll'. 
'CVPrototypes.exe' (Win32): Loaded 'C:\Windows\System32\comdlg32.dll'. 
'CVPrototypes.exe' (Win32): Loaded 'C:\Windows\System32\msvcrt.dll'. 
'CVPrototypes.exe' (Win32): Loaded 'C:\Windows\System32\combase.dll'. 
'CVPrototypes.exe' (Win32): Loaded 'C:\Windows\System32\rpcrt4.dll'. 
'CVPrototypes.exe' (Win32): Loaded 'C:\Windows\System32\SHCore.dll'. 
'CVPrototypes.exe' (Win32): Loaded 'C:\Windows\System32\shlwapi.dll'. 
'CVPrototypes.exe' (Win32): Loaded 'C:\Windows\System32\shell32.dll'. 
'CVPrototypes.exe' (Win32): Loaded 'C:\Windows\System32\advapi32.dll'. 
'CVPrototypes.exe' (Win32): Loaded 'C:\Windows\System32\sechost.dll'. 
'CVPrototypes.exe' (Win32): Loaded 'C:\dev\vcpkg\packages\opencv4_x64-windows\bin\opencv_videoio.dll'. Symbols loaded.
'CVPrototypes.exe' (Win32): Loaded 'C:\Windows\System32\ole32.dll'. 
'CVPrototypes.exe' (Win32): Loaded 'C:\Windows\System32\oleaut32.dll'. 
'CVPrototypes.exe' (Win32): Loaded 'C:\Windows\System32\msvcp140.dll'. 
'CVPrototypes.exe' (Win32): Loaded 'C:\Windows\System32\vcruntime140_1.dll'. 
'CVPrototypes.exe' (Win32): Loaded 'C:\Windows\System32\vcruntime140.dll'. 
'CVPrototypes.exe' (Win32): Loaded 'C:\dev\cv-tests\CVPrototypes\x64\Release\zlib1.dll'. Symbols loaded.
'CVPrototypes.exe' (Win32): Loaded 'C:\Windows\System32\concrt140.dll'. 
'CVPrototypes.exe' (Win32): Loaded 'C:\dev\vcpkg\packages\opencv4_x64-windows\bin\opencv_imgcodecs.dll'. Symbols loaded.
'CVPrototypes.exe' (Win32): Loaded 'C:\dev\vcpkg\packages\opencv4_x64-windows\bin\opencv_imgproc.dll'. Symbols loaded.
'CVPrototypes.exe' (Win32): Loaded 'C:\Windows\WinSxS\amd64_microsoft.windows.common-controls_6595b64144ccf1df_5.82.19041.844_none_423537bff6b9828c\comctl32.dll'. 
'CVPrototypes.exe' (Win32): Loaded 'C:\Windows\System32\mfplat.dll'. 
'CVPrototypes.exe' (Win32): Loaded 'C:\Windows\System32\cfgmgr32.dll'. 
'CVPrototypes.exe' (Win32): Loaded 'C:\Windows\System32\mf.dll'. 
'CVPrototypes.exe' (Win32): Loaded 'C:\Windows\System32\mfreadwrite.dll'. 
'CVPrototypes.exe' (Win32): Loaded 'C:\Windows\System32\d3d11.dll'. 
'CVPrototypes.exe' (Win32): Loaded 'C:\dev\cv-tests\CVPrototypes\x64\Release\jpeg62.dll'. Symbols loaded.
'CVPrototypes.exe' (Win32): Loaded 'C:\dev\cv-tests\CVPrototypes\x64\Release\webp.dll'. Symbols loaded.
'CVPrototypes.exe' (Win32): Loaded 'C:\dev\vcpkg\packages\libpng_x64-windows\bin\libpng16.dll'. Symbols loaded.
'CVPrototypes.exe' (Win32): Loaded 'C:\dev\cv-tests\CVPrototypes\x64\Release\tiff.dll'. Symbols loaded.
'CVPrototypes.exe' (Win32): Loaded 'C:\Windows\System32\dxgi.dll'. 
'CVPrototypes.exe' (Win32): Loaded 'C:\dev\cv-tests\CVPrototypes\x64\Release\lzma.dll'. Symbols loaded.
'CVPrototypes.exe' (Win32): Loaded 'C:\Windows\System32\mfcore.dll'. 
'CVPrototypes.exe' (Win32): Loaded 'C:\Windows\System32\crypt32.dll'. 
'CVPrototypes.exe' (Win32): Loaded 'C:\Windows\System32\bcrypt.dll'. 
'CVPrototypes.exe' (Win32): Loaded 'C:\Windows\System32\powrprof.dll'. 
'CVPrototypes.exe' (Win32): Loaded 'C:\Windows\System32\ksuser.dll'. 
'CVPrototypes.exe' (Win32): Loaded 'C:\Windows\System32\kernel.appcore.dll'. 
'CVPrototypes.exe' (Win32): Loaded 'C:\Windows\System32\cryptbase.dll'. 
'CVPrototypes.exe' (Win32): Loaded 'C:\Windows\System32\imm32.dll'. 
'CVPrototypes.exe' (Win32): Loaded 'C:\Windows\System32\bcryptprimitives.dll'. 
'CVPrototypes.exe' (Win32): Loaded 'C:\Windows\System32\RTWorkQ.dll'. 
'CVPrototypes.exe' (Win32): Loaded 'C:\Windows\System32\umpdc.dll'. 
The thread 0x7798 has exited with code 0 (0x0).
'CVPrototypes.exe' (Win32): Loaded 'C:\Windows\System32\uxtheme.dll'. 
'CVPrototypes.exe' (Win32): Loaded 'C:\Windows\System32\ResourcePolicyClient.dll'. 
'CVPrototypes.exe' (Win32): Unloaded 'C:\Windows\System32\ResourcePolicyClient.dll'
'CVPrototypes.exe' (Win32): Loaded 'C:\Windows\System32\DriverStore\FileRepository\nv_dispwi.inf_amd64_83680483eb310824\nvldumdx.dll'. 
'CVPrototypes.exe' (Win32): Loaded 'C:\Windows\System32\version.dll'. 
'CVPrototypes.exe' (Win32): Loaded 'C:\Windows\System32\msasn1.dll'. 
'CVPrototypes.exe' (Win32): Loaded 'C:\Windows\System32\cryptnet.dll'. 
'CVPrototypes.exe' (Win32): Loaded 'C:\Windows\System32\wintrust.dll'. 
'CVPrototypes.exe' (Win32): Loaded 'C:\Windows\System32\imagehlp.dll'. 
'CVPrototypes.exe' (Win32): Loaded 'C:\Windows\System32\cryptsp.dll'. 
'CVPrototypes.exe' (Win32): Loaded 'C:\Windows\System32\rsaenh.dll'. 
'CVPrototypes.exe' (Win32): Loaded 'C:\Windows\System32\DriverStore\FileRepository\nv_dispwi.inf_amd64_83680483eb310824\nvwgf2umx.dll'. 
'CVPrototypes.exe' (Win32): Loaded 'C:\Windows\System32\winmm.dll'. 
'CVPrototypes.exe' (Win32): Loaded 'C:\Windows\System32\DriverStore\FileRepository\nv_dispwi.inf_amd64_83680483eb310824\NvCamera\NvCameraWhitelisting64.dll'. 
'CVPrototypes.exe' (Win32): Unloaded 'C:\Windows\System32\DriverStore\FileRepository\nv_dispwi.inf_amd64_83680483eb310824\NvCamera\NvCameraWhitelisting64.dll'
'CVPrototypes.exe' (Win32): Loaded 'C:\Windows\System32\windows.storage.dll'. 
'CVPrototypes.exe' (Win32): Loaded 'C:\Windows\System32\wldp.dll'. 
The thread 0x5ab8 has exited with code 0 (0x0).
'CVPrototypes.exe' (Win32): Loaded 'C:\Windows\System32\DXCore.dll'. 
'CVPrototypes.exe' (Win32): Loaded 'C:\Windows\System32\CompPkgSup.dll'. 
'CVPrototypes.exe' (Win32): Loaded 'C:\Windows\System32\clbcatq.dll'. 
'CVPrototypes.exe' (Win32): Loaded 'C:\Windows\System32\Windows.Media.dll'. 
'CVPrototypes.exe' (Win32): Loaded 'C:\Windows\System32\Windows.ApplicationModel.dll'. 
'CVPrototypes.exe' (Win32): Loaded 'C:\Windows\System32\twinapi.appcore.dll'. 
'CVPrototypes.exe' (Win32): Loaded 'C:\Windows\System32\AppXDeploymentClient.dll'. 
'CVPrototypes.exe' (Win32): Loaded 'C:\Windows\System32\FrameServerClient.dll'. 
'CVPrototypes.exe' (Win32): Loaded 'C:\Windows\System32\mfsensorgroup.dll'. 
'CVPrototypes.exe' (Win32): Loaded 'C:\Windows\System32\avrt.dll'. 
'CVPrototypes.exe' (Win32): Loaded 'C:\Windows\System32\vidcap.ax'. 
'CVPrototypes.exe' (Win32): Loaded 'C:\Windows\System32\Kswdmcap.ax'. 
'CVPrototypes.exe' (Win32): Loaded 'C:\Windows\System32\mfc42.dll'. 
Exception thrown at 0x00007FF8B522D759 (KernelBase.dll) in CVPrototypes.exe: WinRT originate error - 0xC00D36B3 : 'The stream number provided was invalid.'.
'CVPrototypes.exe' (Win32): Loaded 'C:\Windows\System32\Windows.StateRepositoryPS.dll'. 
'CVPrototypes.exe' (Win32): Loaded 'C:\Windows\System32\WinTypes.dll'. 
'CVPrototypes.exe' (Win32): Loaded 'C:\Windows\System32\DriverStore\FileRepository\nv_dispwi.inf_amd64_83680483eb310824\nvDecMFTMjpegx.dll'. 
'CVPrototypes.exe' (Win32): Loaded 'C:\Windows\System32\DriverStore\FileRepository\nv_dispwi.inf_amd64_83680483eb310824\NvCamera\NvCameraWhitelisting64.dll'. 
'CVPrototypes.exe' (Win32): Unloaded 'C:\Windows\System32\DriverStore\FileRepository\nv_dispwi.inf_amd64_83680483eb310824\NvCamera\NvCameraWhitelisting64.dll'
'CVPrototypes.exe' (Win32): Loaded 'C:\Windows\System32\DriverStore\FileRepository\nv_dispwi.inf_amd64_83680483eb310824\NvCamera\NvCameraWhitelisting64.dll'. 
'CVPrototypes.exe' (Win32): Unloaded 'C:\Windows\System32\DriverStore\FileRepository\nv_dispwi.inf_amd64_83680483eb310824\NvCamera\NvCameraWhitelisting64.dll'
'CVPrototypes.exe' (Win32): Loaded 'C:\Windows\System32\mfmjpegdec.dll'. 
'CVPrototypes.exe' (Win32): Loaded 'C:\Windows\System32\mfperfhelper.dll'. 

The thread 0x6074 has exited with code 0 (0x0).
The thread 0x3e4 has exited with code 0 (0x0).
'CVPrototypes.exe' (Win32): Loaded 'C:\Windows\System32\DriverStore\FileRepository\nv_dispwi.inf_amd64_83680483eb310824\NvCamera\NvCameraWhitelisting64.dll'. 
'CVPrototypes.exe' (Win32): Unloaded 'C:\Windows\System32\DriverStore\FileRepository\nv_dispwi.inf_amd64_83680483eb310824\NvCamera\NvCameraWhitelisting64.dll'
'CVPrototypes.exe' (Win32): Loaded 'C:\Windows\System32\DriverStore\FileRepository\nv_dispwi.inf_amd64_83680483eb310824\NvCamera\NvCameraWhitelisting64.dll'. 
'CVPrototypes.exe' (Win32): Unloaded 'C:\Windows\System32\DriverStore\FileRepository\nv_dispwi.inf_amd64_83680483eb310824\NvCamera\NvCameraWhitelisting64.dll'
The thread 0x64d4 has exited with code 0 (0x0).
The thread 0x5c34 has exited with code 0 (0x0).
The thread 0x1808 has exited with code 0 (0x0).
The thread 0x7018 has exited with code 0 (0x0).
The thread 0x8520 has exited with code 0 (0x0).
The thread 0x2594 has exited with code 0 (0x0).
The thread 0x546c has exited with code 0 (0x0).
The thread 0x4aac has exited with code 0 (0x0).
The thread 0x71f4 has exited with code 0 (0x0).
The thread 0x803c has exited with code 0 (0x0).
The thread 0x3988 has exited with code 0 (0x0).
The thread 0x7024 has exited with code 0 (0x0).
The thread 0x1828 has exited with code 0 (0x0).
The thread 0x8688 has exited with code 0 (0x0).
The thread 0x65f8 has exited with code 0 (0x0).
The thread 0x584c has exited with code 0 (0x0).
The thread 0x7dec has exited with code 0 (0x0).
The thread 0x6f9c has exited with code 0 (0x0).
The thread 0x8224 has exited with code 0 (0x0).
The thread 0x3450 has exited with code 0 (0x0).
The thread 0x2bdc has exited with code 0 (0x0).
The thread 0x56cc has exited with code 0 (0x0).
The thread 0x3100 has exited with code 0 (0x0).
The thread 0x2c5c has exited with code 0 (0x0).
The thread 0x752c has exited with code 0 (0x0).
The thread 0x5d44 has exited with code 0 (0x0).
The thread 0x80a4 has exited with code 0 (0x0).
The thread 0x4fc0 has exited with code 0 (0x0).
The thread 0x6440 has exited with code 0 (0x0).
The thread 0x83d4 has exited with code 0 (0x0).
The thread 0x67a8 has exited with code 0 (0x0).
The thread 0x5638 has exited with code 0 (0x0).
The thread 0x7dd0 has exited with code 0 (0x0).
The thread 0x86f8 has exited with code 0 (0x0).
The thread 0x7d20 has exited with code 0 (0x0).
The thread 0x875c has exited with code 0 (0x0).
The thread 0x663c has exited with code 0 (0x0).
The thread 0x6f20 has exited with code 0 (0x0).
The thread 0x4b80 has exited with code 0 (0x0).
The thread 0x6a7c has exited with code 0 (0x0).
The thread 0x6b10 has exited with code 0 (0x0).
The thread 0x5e6c has exited with code 0 (0x0).
The thread 0x66e4 has exited with code 0 (0x0).
The thread 0x6e10 has exited with code 0 (0x0).
The thread 0x7bd4 has exited with code 0 (0x0).
The thread 0x84a0 has exited with code 0 (0x0).
The thread 0x6e98 has exited with code 0 (0x0).
The thread 0x6a14 has exited with code 0 (0x0).
The thread 0x16c8 has exited with code 0 (0x0).
The thread 0x7918 has exited with code 0 (0x0).
The thread 0x4aa8 has exited with code 0 (0x0).
The thread 0x6dec has exited with code 0 (0x0).
The thread 0x82ec has exited with code 0 (0x0).
The thread 0x8020 has exited with code 0 (0x0).
The thread 0x5670 has exited with code 0 (0x0).
The thread 0x72c4 has exited with code 0 (0x0).
The thread 0x6f54 has exited with code 0 (0x0).
The thread 0x5b20 has exited with code 0 (0x0).
The thread 0x7fc8 has exited with code 0 (0x0).
The thread 0x7eec has exited with code 0 (0x0).
The thread 0x7a8c has exited with code 0 (0x0).
The thread 0x7e30 has exited with code 0 (0x0).
The thread 0x5c60 has exited with code 0 (0x0).
The thread 0x7f2c has exited with code 0 (0x0).
The thread 0x868c has exited with code 0 (0x0).
The thread 0x8600 has exited with code 0 (0x0).
The thread 0x4e38 has exited with code 0 (0x0).
The thread 0x6f00 has exited with code 0 (0x0).
'CVPrototypes.exe' (Win32): Loaded 'C:\Windows\System32\DriverStore\FileRepository\nv_dispwi.inf_amd64_83680483eb310824\NvCamera\NvCameraWhitelisting64.dll'. 
'CVPrototypes.exe' (Win32): Unloaded 'C:\Windows\System32\DriverStore\FileRepository\nv_dispwi.inf_amd64_83680483eb310824\NvCamera\NvCameraWhitelisting64.dll'
'CVPrototypes.exe' (Win32): Loaded 'C:\Windows\System32\DriverStore\FileRepository\nv_dispwi.inf_amd64_83680483eb310824\NvCamera\NvCameraWhitelisting64.dll'. 
'CVPrototypes.exe' (Win32): Unloaded 'C:\Windows\System32\DriverStore\FileRepository\nv_dispwi.inf_amd64_83680483eb310824\NvCamera\NvCameraWhitelisting64.dll'
The thread 0x8498 has exited with code 0 (0x0).
The thread 0x85a0 has exited with code 0 (0x0).
The thread 0x681c has exited with code 0 (0x0).
The thread 0x7b10 has exited with code 0 (0x0).
The thread 0x5ad8 has exited with code 0 (0x0).
The thread 0x347c has exited with code 0 (0x0).
The thread 0x7264 has exited with code 0 (0x0).
The thread 0x3018 has exited with code 0 (0x0).
The thread 0x6520 has exited with code 0 (0x0).
The thread 0x6804 has exited with code 0 (0x0).
The thread 0x64e8 has exited with code 0 (0x0).
The thread 0x2d98 has exited with code 0 (0x0).
The thread 0x4270 has exited with code 0 (0x0).
The thread 0x6da4 has exited with code 0 (0x0).
The thread 0x7ea4 has exited with code 0 (0x0).
The thread 0x199c has exited with code 0 (0x0).
The thread 0x568c has exited with code 0 (0x0).
The thread 0x437c has exited with code 0 (0x0).
The thread 0x65fc has exited with code 0 (0x0).
The thread 0x7e18 has exited with code 0 (0x0).
The thread 0x32c4 has exited with code 0 (0x0).
The thread 0x87b0 has exited with code 0 (0x0).
The thread 0x4ea0 has exited with code 0 (0x0).
The thread 0x7954 has exited with code 0 (0x0).
The thread 0x2e84 has exited with code 0 (0x0).
The thread 0x3e8 has exited with code 0 (0x0).
The thread 0x7c54 has exited with code 0 (0x0).
The thread 0x82f8 has exited with code 0 (0x0).
The thread 0x6598 has exited with code 0 (0x0).
The thread 0x7318 has exited with code 0 (0x0).
The thread 0x6840 has exited with code 0 (0x0).
The thread 0x820 has exited with code 0 (0x0).
The thread 0x3bc has exited with code 0 (0x0).
The thread 0x78dc has exited with code 0 (0x0).
The thread 0x4ac8 has exited with code 0 (0x0).
The thread 0x6aec has exited with code 0 (0x0).
The thread 0x69fc has exited with code 0 (0x0).
The thread 0x780c has exited with code 0 (0x0).
The thread 0x30b8 has exited with code 0 (0x0).
The thread 0x84e8 has exited with code 0 (0x0).
The thread 0x82a8 has exited with code 0 (0x0).
The thread 0x1750 has exited with code 0 (0x0).
The thread 0x825c has exited with code 0 (0x0).
The thread 0x6158 has exited with code 0 (0x0).
The thread 0x56b4 has exited with code 0 (0x0).
The thread 0x63d4 has exited with code 0 (0x0).
The thread 0x1354 has exited with code 0 (0x0).
The thread 0x4380 has exited with code 0 (0x0).
The thread 0x7528 has exited with code 0 (0x0).
The thread 0x53c8 has exited with code 0 (0x0).
The thread 0x6660 has exited with code 0 (0x0).
The thread 0x49d4 has exited with code 0 (0x0).
The thread 0x1194 has exited with code 0 (0x0).
The thread 0x529c has exited with code 0 (0x0).
The thread 0x75f4 has exited with code 0 (0x0).
The thread 0x5fcc has exited with code 0 (0x0).
The thread 0x3a38 has exited with code 0 (0x0).
The thread 0x8324 has exited with code 0 (0x0).
The thread 0x518c has exited with code 0 (0x0).
The thread 0x5108 has exited with code 0 (0x0).
The thread 0x7e60 has exited with code 0 (0x0).
The thread 0x5144 has exited with code 0 (0x0).
The thread 0x7040 has exited with code 0 (0x0).
The thread 0x87ac has exited with code 0 (0x0).
The thread 0x83c has exited with code 0 (0x0).
The thread 0x7648 has exited with code 0 (0x0).
The thread 0x6b80 has exited with code 0 (0x0).
The thread 0x3cd4 has exited with code 0 (0x0).
'CVPrototypes.exe' (Win32): Loaded 'C:\Windows\System32\DriverStore\FileRepository\nv_dispwi.inf_amd64_83680483eb310824\NvCamera\NvCameraWhitelisting64.dll'. 
'CVPrototypes.exe' (Win32): Unloaded 'C:\Windows\System32\DriverStore\FileRepository\nv_dispwi.inf_amd64_83680483eb310824\NvCamera\NvCameraWhitelisting64.dll'
'CVPrototypes.exe' (Win32): Loaded 'C:\Windows\System32\DriverStore\FileRepository\nv_dispwi.inf_amd64_83680483eb310824\NvCamera\NvCameraWhitelisting64.dll'. 
'CVPrototypes.exe' (Win32): Unloaded 'C:\Windows\System32\DriverStore\FileRepository\nv_dispwi.inf_amd64_83680483eb310824\NvCamera\NvCameraWhitelisting64.dll'
The thread 0x7028 has exited with code 0 (0x0).
The thread 0x8564 has exited with code 0 (0x0).
The thread 0x68a8 has exited with code 0 (0x0).
The thread 0xa58 has exited with code 0 (0x0).
The thread 0x6394 has exited with code 0 (0x0).
The thread 0x6b64 has exited with code 0 (0x0).
The thread 0x73d8 has exited with code 0 (0x0).
The thread 0x5284 has exited with code 0 (0x0).
The thread 0xcdc has exited with code 0 (0x0).
The thread 0x3430 has exited with code 0 (0x0).
The thread 0x7db8 has exited with code 0 (0x0).
The thread 0x54d0 has exited with code 0 (0x0).
The thread 0x4630 has exited with code 0 (0x0).
The thread 0x849c has exited with code 0 (0x0).
The thread 0x61d4 has exited with code 0 (0x0).
The thread 0x67f8 has exited with code 0 (0x0).
The thread 0x7fc0 has exited with code 0 (0x0).
The thread 0x5298 has exited with code 0 (0x0).
The thread 0x5d6c has exited with code 0 (0x0).
The thread 0x7e2c has exited with code 0 (0x0).
The thread 0x1310 has exited with code 0 (0x0).
The thread 0x7700 has exited with code 0 (0x0).
The thread 0x58c4 has exited with code 0 (0x0).
The thread 0x5218 has exited with code 0 (0x0).
The thread 0x6420 has exited with code 0 (0x0).
The thread 0x6e90 has exited with code 0 (0x0).
The thread 0x1ecc has exited with code 0 (0x0).
The thread 0x64dc has exited with code 0 (0x0).
The thread 0x7008 has exited with code 0 (0x0).
The thread 0x5c6c has exited with code 0 (0x0).
The thread 0x831c has exited with code 0 (0x0).
The thread 0x3a18 has exited with code 0 (0x0).
The thread 0x7798 has exited with code 0 (0x0).
The thread 0x85ec has exited with code 0 (0x0).
The thread 0x77c4 has exited with code 0 (0x0).
The thread 0x6778 has exited with code 0 (0x0).
The thread 0x4ed4 has exited with code 0 (0x0).
The thread 0x7e8c has exited with code 0 (0x0).
The thread 0x1974 has exited with code 0 (0x0).
The thread 0x807c has exited with code 0 (0x0).
The thread 0x6e50 has exited with code 0 (0x0).
The thread 0x4870 has exited with code 0 (0x0).
The thread 0x6df0 has exited with code 0 (0x0).
The thread 0x782c has exited with code 0 (0x0).
The thread 0x19a0 has exited with code 0 (0x0).
The thread 0x392c has exited with code 0 (0x0).
The thread 0x6b98 has exited with code 0 (0x0).
The thread 0x869c has exited with code 0 (0x0).
The thread 0x6e68 has exited with code 0 (0x0).
The thread 0x63d8 has exited with code 0 (0x0).
The thread 0x7930 has exited with code 0 (0x0).
The thread 0x84a4 has exited with code 0 (0x0).
The thread 0x841c has exited with code 0 (0x0).
The thread 0x7074 has exited with code 0 (0x0).
The thread 0x767c has exited with code 0 (0x0).
The thread 0xcd4 has exited with code 0 (0x0).
The thread 0x8468 has exited with code 0 (0x0).
The thread 0x7ffc has exited with code 0 (0x0).
The thread 0x4b64 has exited with code 0 (0x0).
The thread 0x8434 has exited with code 0 (0x0).
The thread 0x56b0 has exited with code 0 (0x0).
The thread 0x7f60 has exited with code 0 (0x0).
The thread 0x75cc has exited with code 0 (0x0).
The thread 0x2b28 has exited with code 0 (0x0).
The thread 0x87cc has exited with code 0 (0x0).
The thread 0x3a28 has exited with code 0 (0x0).
The thread 0x64cc has exited with code 0 (0x0).
The thread 0x7d7c has exited with code 0 (0x0).
'CVPrototypes.exe' (Win32): Loaded 'C:\Windows\System32\msvproc.dll'. 
'CVPrototypes.exe' (Win32): Loaded 'C:\Windows\System32\msctf.dll'. 
'CVPrototypes.exe' (Win32): Loaded 'C:\Windows\System32\TextInputFramework.dll'. 
'CVPrototypes.exe' (Win32): Loaded 'C:\Windows\System32\CoreUIComponents.dll'. 
'CVPrototypes.exe' (Win32): Loaded 'C:\Windows\System32\CoreMessaging.dll'. 
'CVPrototypes.exe' (Win32): Loaded 'C:\Windows\System32\ws2_32.dll'. 
'CVPrototypes.exe' (Win32): Loaded 'C:\Windows\System32\ntmarta.dll'. 

This last section ("…has exited with code 0 and loaded / unloaded NvCameraWhitelisting64) repeats about 111 times before imshow gets to open a window.

Hi,

Why have you got 4 for cap3?

Please forget opencv2.4.13 and use lastest opencv version 4.5.1 (or 3.4.13)

use the apiPreference argument for VideoCapture constructors. pass the device id in the constructor already, no need for separate open() call.

Thank you for the suggestions.

@laurent.berger That is because index 3 is used by another camera and I am interested in using the Logitech cameras:

 0) Logitech HD Pro Webcam C920
 1) Logitech HD Pro Webcam C920
 2) Logitech HD Pro Webcam C920
 3) Blackmagic WDM Capture
 4) Logitech HD Pro Webcam C920

@crackwitz I’ve tried using the index and apiPreference in the constructor directly but I get the same behaviour:

    cv::VideoCapture cap0(0, cv::CAP_MSMF);
    cv::VideoCapture cap1(1, cv::CAP_MSMF);
    cv::VideoCapture cap2(2, cv::CAP_MSMF);
    cv::VideoCapture cap3(4, cv::CAP_MSMF);

seems to get stuck in a loop outputting

The thread 0x8e28 has exited with code 0 (0x0).
The thread 0xb18c has exited with code 0 (0x0).
The thread 0xb6b0 has exited with code 0 (0x0).
'CV3Test.exe' (Win32): Loaded 'C:\Windows\System32\DriverStore\FileRepository\nv_dispwi.inf_amd64_83680483eb310824\NvCamera\NvCameraWhitelisting64.dll'. 
'CV3Test.exe' (Win32): Unloaded 'C:\Windows\System32\DriverStore\FileRepository\nv_dispwi.inf_amd64_83680483eb310824\NvCamera\NvCameraWhitelisting64.dll'
'CV3Test.exe' (Win32): Loaded 'C:\Windows\System32\DriverStore\FileRepository\nv_dispwi.inf_amd64_83680483eb310824\NvCamera\NvCameraWhitelisting64.dll'. 
'CV3Test.exe' (Win32): Unloaded 'C:\Windows\System32\DriverStore\FileRepository\nv_dispwi.inf_amd64_83680483eb310824\NvCamera\NvCameraWhitelisting64.dll'
The thread 0xa9c0 has exited with code 0 (0x0).

using DSHOW:

    cv::VideoCapture cap0(0, cv::CAP_DSHOW);
    cv::VideoCapture cap1(1, cv::CAP_DSHOW);
    cv::VideoCapture cap2(2, cv::CAP_DSHOW);
    cv::VideoCapture cap3(4, cv::CAP_DSHOW);

opens the same camera 4 times even though I’ve passed different indices.

I don’t know enough about this NvCameraWhitelisting64.dll and how to bypass it.

What else could I try ?

the implementation for MSMF is somewhat green. I’d expect DSHOW to fare better.

I have two C920. I’ll try to reproduce this.

are they all attached to the same USB controller?

DSHOW doesn’t freeze like MSMF, however I get the same one stream for all 4 indices.

Regarding the controller I’ll need to double check the motherboard datasheet,
but I have cameras connected to USB ports as far apart form each other as possible in the hope that internally they land on different buses.

1 Like

I’ve checked the motherboard specs ( Prime TRX40-Pro) and should be more than enough. There are plenty of chipsets and USB 3.1 and 3.2 ports available. These are all USB 2.0 cameras so I’m hoping bandwidth isn’t the issue.

I’ve tested with various camera indices :

  • 2 cameras: 0, 1 / 0, 2 / 0, 4 / 1, 2 / 1, 4 / 2 , 4
  • 3 cameras: 0, 1, 2 / 0, 1, 4 / 0, 2, 4 / 1, 2, 4

and I can replicate the issue with one OpenCV 4.5.1 build (vcpkg install), but luckily have a solution with another 4.5.1 build (from source):

For reference here are the build configs:

4.5.1 via vcpkg:

General configuration for OpenCV 4.5.1 =====================================
  Version control:               unknown

  Platform:
    Timestamp:                   2021-02-14T01:56:23Z
    Host:                        Windows 10.0.19042 AMD64
    CMake:                       3.19.4
    CMake generator:             Ninja
    CMake build tool:            C:/dev/vcpkg/downloads/tools/ninja/1.10.1-windows/ninja.exe
    MSVC:                        1928
    Configuration:               Release

  CPU/HW features:
    Baseline:                    SSE SSE2 SSE3
      requested:                 SSE3
    Dispatched code generation:  SSE4_1 SSE4_2 FP16 AVX AVX2 AVX512_SKX
      requested:                 SSE4_1 SSE4_2 AVX FP16 AVX2 AVX512_SKX
      SSE4_1 (14 files):         + SSSE3 SSE4_1
      SSE4_2 (1 files):          + SSSE3 SSE4_1 POPCNT SSE4_2
      FP16 (0 files):            + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 AVX
      AVX (4 files):             + SSSE3 SSE4_1 POPCNT SSE4_2 AVX
      AVX2 (28 files):           + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 FMA3 AVX AVX2
      AVX512_SKX (4 files):      + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 FMA3 AVX AVX2 AVX_512F AVX512_COMMON AVX512_SKX

  C/C++:
    Built as dynamic libs?:      YES
    C++ standard:                11
    C++ Compiler:                C:/Program Files (x86)/Microsoft Visual Studio/2019/Professional/VC/Tools/MSVC/14.28.29333/bin/Hostx64/x64/cl.exe  (ver 19.28.29334.0)
    C++ flags (Release):         /nologo /DWIN32 /D_WINDOWS /W4 /utf-8 /GR /MP   /D _CRT_SECURE_NO_DEPRECATE /D _CRT_NONSTDC_NO_DEPRECATE /D _SCL_SECURE_NO_WARNINGS /Gy /bigobj /Oi  /fp:precise /FS     /EHa /wd4127 /wd4251 /wd4324 /wd4275 /wd4512 /wd4589  /MD /O2 /Oi /Gy /DNDEBUG /Z7
    C++ flags (Debug):           /nologo /DWIN32 /D_WINDOWS /W4 /utf-8 /GR /MP   /D _CRT_SECURE_NO_DEPRECATE /D _CRT_NONSTDC_NO_DEPRECATE /D _SCL_SECURE_NO_WARNINGS /Gy /bigobj /Oi  /fp:precise /FS     /EHa /wd4127 /wd4251 /wd4324 /wd4275 /wd4512 /wd4589  /D_DEBUG /MDd /Z7 /Ob0 /Od /RTC1
    C Compiler:                  C:/Program Files (x86)/Microsoft Visual Studio/2019/Professional/VC/Tools/MSVC/14.28.29333/bin/Hostx64/x64/cl.exe
    C flags (Release):           /nologo /DWIN32 /D_WINDOWS /W3 /utf-8 /MP   /D _CRT_SECURE_NO_DEPRECATE /D _CRT_NONSTDC_NO_DEPRECATE /D _SCL_SECURE_NO_WARNINGS /Gy /bigobj /Oi  /fp:precise /FS       /MD /O2 /Oi /Gy /DNDEBUG /Z7
    C flags (Debug):             /nologo /DWIN32 /D_WINDOWS /W3 /utf-8 /MP   /D _CRT_SECURE_NO_DEPRECATE /D _CRT_NONSTDC_NO_DEPRECATE /D _SCL_SECURE_NO_WARNINGS /Gy /bigobj /Oi  /fp:precise /FS     /D_DEBUG /MDd /Z7 /Ob0 /Od /RTC1
    Linker flags (Release):      /machine:x64  /nologo /DEBUG /INCREMENTAL:NO /OPT:REF /OPT:ICF    /debug
    Linker flags (Debug):        /machine:x64  /nologo    /debug /INCREMENTAL
    ccache:                      NO
    Precompiled headers:         NO
    Extra dependencies:
    3rdparty dependencies:

  OpenCV modules:
    To be built:                 calib3d core dnn features2d flann highgui imgcodecs imgproc ml objdetect photo stitching video videoio
    Disabled:                    world
    Disabled by dependency:      -
    Unavailable:                 gapi java python2 python3 ts
    Applications:                -
    Documentation:               NO
    Non-free algorithms:         NO

  Windows RT support:            NO

  GUI:
    Win32 UI:                    YES

  Media I/O:
    ZLib:                        optimized C:/dev/vcpkg/installed/x64-windows/lib/zlib.lib debug C:/dev/vcpkg/installed/x64-windows/debug/lib/zlibd.lib (ver 1.2.11)
    JPEG:                        optimized C:/dev/vcpkg/installed/x64-windows/lib/jpeg.lib debug C:/dev/vcpkg/installed/x64-windows/debug/lib/jpegd.lib (ver 62)
    WEBP:                        optimized C:/dev/vcpkg/installed/x64-windows/lib/webp.lib debug C:/dev/vcpkg/installed/x64-windows/debug/lib/webpd.lib (ver 1.1.0)
    PNG:                         optimized C:/dev/vcpkg/installed/x64-windows/lib/libpng16.lib debug C:/dev/vcpkg/installed/x64-windows/debug/lib/libpng16d.lib (ver 1.6.37)
    TIFF:                        optimized C:/dev/vcpkg/installed/x64-windows/lib/tiff.lib debug C:/dev/vcpkg/installed/x64-windows/debug/lib/tiffd.lib optimized C:/dev/vcpkg/installed/x64-windows/lib/lzma.lib debug C:/dev/vcpkg/installed/x64-windows/debug/lib/lzmad.lib optimized C:/dev/vcpkg/installed/x64-windows/lib/jpeg.lib debug C:/dev/vcpkg/installed/x64-windows/debug/lib/jpegd.lib optimized C:/dev/vcpkg/installed/x64-windows/lib/zlib.lib debug C:/dev/vcpkg/installed/x64-windows/debug/lib/zlibd.lib (ver 42 / 4.1.0)
    HDR:                         YES
    SUNRASTER:                   YES
    PXM:                         YES
    PFM:                         YES

  Video I/O:
    DC1394:                      NO
    GStreamer:                   NO
    DirectShow:                  YES
    Media Foundation:            YES
      DXVA:                      YES

  Parallel framework:            Concurrency

  Trace:                         YES (built-in)

  Other third-party libraries:
    Custom HAL:                  NO
    Protobuf:                    C:/dev/vcpkg/installed/x64-windows/lib/libprotobuf.lib (3.14.0)

  OpenCL:                        YES (NVD3D11)
    Include path:                C:/dev/vcpkg/buildtrees/opencv4/src/4.5.1-e92f755db3.clean/3rdparty/include/opencl/1.2
    Link libraries:              Dynamic load

  Python (for build):            NO

  Install to:                    C:/dev/vcpkg/packages/opencv4_x64-windows
-----------------------------------------------------------------

4.5.1 from source:

General configuration for OpenCV 4.5.1-dev =====================================
  Version control:               4.5.1-214-ge5d78960c6

  Extra modules:
    Location (extra):            C:/dev/cv/opencv_contrib/modules
    Version control (extra):     4.5.1-60-g4e85f8c6

  Platform:
    Timestamp:                   2021-02-13T17:47:39Z
    Host:                        Windows 10.0.19042 AMD64
    CMake:                       3.19.4
    CMake generator:             Visual Studio 16 2019
    CMake build tool:            C:/Program Files (x86)/Microsoft Visual Studio/2019/Professional/MSBuild/Current/Bin/MSBuild.exe
    MSVC:                        1928
    Configuration:               Debug Release

  CPU/HW features:
    Baseline:                    SSE SSE2 SSE3
      requested:                 SSE3
    Dispatched code generation:  SSE4_1 SSE4_2 FP16 AVX AVX2 AVX512_SKX
      requested:                 SSE4_1 SSE4_2 AVX FP16 AVX2 AVX512_SKX
      SSE4_1 (15 files):         + SSSE3 SSE4_1
      SSE4_2 (1 files):          + SSSE3 SSE4_1 POPCNT SSE4_2
      FP16 (0 files):            + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 AVX
      AVX (4 files):             + SSSE3 SSE4_1 POPCNT SSE4_2 AVX
      AVX2 (29 files):           + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 FMA3 AVX AVX2
      AVX512_SKX (4 files):      + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 FMA3 AVX AVX2 AVX_512F AVX512_COMMON AVX512_SKX

  C/C++:
    Built as dynamic libs?:      YES
    C++ standard:                11
    C++ Compiler:                C:/Program Files (x86)/Microsoft Visual Studio/2019/Professional/VC/Tools/MSVC/14.28.29333/bin/Hostx64/x64/cl.exe  (ver 19.28.29334.0)
    C++ flags (Release):         /DWIN32 /D_WINDOWS /W4 /GR  /D _CRT_SECURE_NO_DEPRECATE /D _CRT_NONSTDC_NO_DEPRECATE /D _SCL_SECURE_NO_WARNINGS /Gy /bigobj /Oi  /fp:precise     /EHa /wd4127 /wd4251 /wd4324 /wd4275 /wd4512 /wd4589 /MP  /MD /O2 /Ob2 /DNDEBUG
    C++ flags (Debug):           /DWIN32 /D_WINDOWS /W4 /GR  /D _CRT_SECURE_NO_DEPRECATE /D _CRT_NONSTDC_NO_DEPRECATE /D _SCL_SECURE_NO_WARNINGS /Gy /bigobj /Oi  /fp:precise     /EHa /wd4127 /wd4251 /wd4324 /wd4275 /wd4512 /wd4589 /MP  /MDd /Zi /Ob0 /Od /RTC1
    C Compiler:                  C:/Program Files (x86)/Microsoft Visual Studio/2019/Professional/VC/Tools/MSVC/14.28.29333/bin/Hostx64/x64/cl.exe
    C flags (Release):           /DWIN32 /D_WINDOWS /W3  /D _CRT_SECURE_NO_DEPRECATE /D _CRT_NONSTDC_NO_DEPRECATE /D _SCL_SECURE_NO_WARNINGS /Gy /bigobj /Oi  /fp:precise     /MP   /MD /O2 /Ob2 /DNDEBUG
    C flags (Debug):             /DWIN32 /D_WINDOWS /W3  /D _CRT_SECURE_NO_DEPRECATE /D _CRT_NONSTDC_NO_DEPRECATE /D _SCL_SECURE_NO_WARNINGS /Gy /bigobj /Oi  /fp:precise     /MP /MDd /Zi /Ob0 /Od /RTC1
    Linker flags (Release):      /machine:x64  /INCREMENTAL:NO
    Linker flags (Debug):        /machine:x64  /debug /INCREMENTAL
    ccache:                      NO
    Precompiled headers:         YES
    Extra dependencies:          opengl32 glu32
    3rdparty dependencies:

  OpenCV modules:
    To be built:                 alphamat aruco bgsegm bioinspired calib3d ccalib core datasets dnn dnn_objdetect dnn_superres dpm face features2d flann fuzzy gapi hfs highgui img_hash imgcodecs imgproc intensity_transform line_descriptor mcc ml objdetect optflow phase_unwrapping photo plot quality rapid reg rgbd saliency sfm shape stereo stitching structured_light superres tracking ts video videoio videostab viz wechat_qrcode xfeatures2d ximgproc xobjdetect xphoto
    Disabled:                    java_bindings_generator js_bindings_generator python3 python_bindings_generator python_tests surface_matching text world
    Disabled by dependency:      -
    Unavailable:                 cnn_3dobj cudaarithm cudabgsegm cudacodec cudafeatures2d cudafilters cudaimgproc cudalegacy cudaobjdetect cudaoptflow cudastereo cudawarping cudev cvv freetype hdf java julia matlab ovis python2
    Applications:                examples apps
    Documentation:               NO
    Non-free algorithms:         YES

  Windows RT support:            NO

  GUI:
    Win32 UI:                    YES
    OpenGL support:              YES (opengl32 glu32)
    VTK support:                 YES (ver 9.0.1)

  Media I/O:
    ZLib:                        build (ver 1.2.11)
    JPEG:                        build-libjpeg-turbo (ver 2.0.6-62)
    WEBP:                        build (ver encoder: 0x020f)
    PNG:                         build (ver 1.6.37)
    TIFF:                        build (ver 42 - 4.0.10)
    JPEG 2000:                   build (ver 2.3.1)
    OpenEXR:                     build (ver 2.3.0)
    HDR:                         YES
    SUNRASTER:                   YES
    PXM:                         YES
    PFM:                         YES

  Video I/O:
    DC1394:                      NO
    FFMPEG:                      YES (prebuilt binaries)
      avcodec:                   YES (58.91.100)
      avformat:                  YES (58.45.100)
      avutil:                    YES (56.51.100)
      swscale:                   YES (5.7.100)
      avresample:                YES (4.0.0)
    GStreamer:                   NO
    DirectShow:                  YES
    Media Foundation:            YES
      DXVA:                      YES

  Parallel framework:            Concurrency

  Trace:                         YES (with Intel ITT)

  Other third-party libraries:
    Intel IPP:                   2020.0.0 Gold [2020.0.0]
           at:                   C:/dev/cv/opencv/build/3rdparty/ippicv/ippicv_win/icv
    Intel IPP IW:                sources (2020.0.0)
              at:                C:/dev/cv/opencv/build/3rdparty/ippicv/ippicv_win/iw
    Lapack:                      NO
    Eigen:                       YES (ver 3.3.9)
    Custom HAL:                  NO
    Protobuf:                    build (3.5.1)

  OpenCL:                        YES (NVD3D11)
    Include path:                C:/dev/cv/opencv/3rdparty/include/opencl/1.2
    Link libraries:              Dynamic load

  Python (for build):            C:/Users/DVP/.pyenv/pyenv-win/versions/3.6.4/python.exe

  Install to:                    C:/dev/cv/opencv/build/install
-----------------------------------------------------------------

It’s great this version works, but I have no idea why the vcpkg version doesn’t.