Hi,
I downloaded the official OpenCV 4.5.5 release for windows from Releases - OpenCV.
I wirte a very simple demo to open a usb camera, when using CAP_ANY or CAP_DSHOW, the camera can be opened, but when change the apiPreference to CAP_MSMF, VideoCapture::open always return false. i have copied the opencv_videoio_msmf455_64d.dll to the build dir.
I can open the camera using the built-in Camera app in Windows or some sdk examples of microsoft media foundtaion.
below is the log when debugging the demo.
Opening camera 0, width: 1280, height: 720
[ INFO:0@0.758] global C:\build\master_winpack-build-win64-vc15\opencv\modules\videoio\src\videoio_registry.cpp (223) cv::`anonymous-namespace'::VideoBackendRegistry::VideoBackendRegistry VIDEOIO: Enabled backends(8, sorted by priority): FFMPEG(1000); GSTREAMER(990); INTEL_MFX(980); MSMF(970); DSHOW(960); CV_IMAGES(950); CV_MJPEG(940); UEYE(930)
[ INFO:0@0.758] global C:\build\master_winpack-build-win64-vc15\opencv\modules\videoio\src\backend_plugin.cpp (383) cv::impl::getPluginCandidates Found 2 plugin(s) for MSMF
[ INFO:0@0.760] global c:\build\master_winpack-build-win64-vc15\opencv\modules\core\src\utils\plugin_loader.impl.hpp (67) cv::plugin::impl::DynamicLib::libraryLoad load D:\githubenterprise\MultiCamPrototype\out\build\x64-Debug\opencv_videoio_msmf455_64d.dll => OK
[ INFO:0@0.760] global C:\build\master_winpack-build-win64-vc15\opencv\modules\videoio\src\backend_plugin.cpp (50) cv::impl::PluginBackend::initCaptureAPI Found entry: 'opencv_videoio_capture_plugin_init_v1'
[ INFO:0@0.760] global C:\build\master_winpack-build-win64-vc15\opencv\modules\videoio\src\backend_plugin.cpp (169) cv::impl::PluginBackend::checkCompatibility Video I/O: initialized 'Microsoft Media Foundation OpenCV Video I/O plugin': built with OpenCV 4.5 (ABI/API = 1/1), current OpenCV version is '4.5.5' (ABI/API = 1/1)
[ INFO:0@0.760] global C:\build\master_winpack-build-win64-vc15\opencv\modules\videoio\src\backend_plugin.cpp (69) cv::impl::PluginBackend::initCaptureAPI Video I/O: plugin is ready to use 'Microsoft Media Foundation OpenCV Video I/O plugin'
[ INFO:0@0.760] global C:\build\master_winpack-build-win64-vc15\opencv\modules\videoio\src\backend_plugin.cpp (84) cv::impl::PluginBackend::initWriterAPI Found entry: 'opencv_videoio_writer_plugin_init_v1'
[ INFO:0@0.760] global C:\build\master_winpack-build-win64-vc15\opencv\modules\videoio\src\backend_plugin.cpp (169) cv::impl::PluginBackend::checkCompatibility Video I/O: initialized 'Microsoft Media Foundation OpenCV Video I/O plugin': built with OpenCV 4.5 (ABI/API = 1/1), current OpenCV version is '4.5.5' (ABI/API = 1/1)
[ INFO:0@0.760] global C:\build\master_winpack-build-win64-vc15\opencv\modules\videoio\src\backend_plugin.cpp (103) cv::impl::PluginBackend::initWriterAPI Video I/O: plugin is ready to use 'Microsoft Media Foundation OpenCV Video I/O plugin'
Could not open camera 0
could someone help figure out what the reason is? thanks a lot.
what can you tell about the camera?
there are two cameras, one is the build-in camera of my notebook, another one is an external usb camera.
Both could be opened when using CAP_ANY or CAP_DSHOW. Both support 720p/30fps.
Do you want to know other specific info? or maybe you can teach me how to fetch those info you are interested.
Thanks a lot.
I would suggest that you set OPENCV_VIDEOIO_DEBUG=1
(environment variable) and then run your program again with MSMF requested. OpenCV should be more talkative now.
if it doesn’t get more talkative, verify that setting the environment variable was successful. check the value of the variable from within your program.
here’s some information on that variable: OpenCV: Query I/O API backends registry
check that you can open the other two cameras (built-in color and IR) using MSMF. if that works, the issue is specific to that external camera. if that doesn’t work either, that would indicate a larger issue with MSMF.
it’s likely that this is a bug in OpenCV.
it would be useful to know the exact model of that camera. it’s a “hikvision” brand, which you should have known and stated already. I can guess from the screenshot of the device manager.
you say you can access the camera with DSHOW. that’s great. if you only care about using the camera, go with DSHOW then. I don’t see a reason to explicitly require MSMF.
Both cameras can’t be opened when using MSMF.
After setting the env, the log contains two more lines compared with before, but doesn’t have much helpful infomation, i guess. Below is the new log.
Opening camera 0, width: 1280, height: 720
[ INFO:0@1.173] global C:\build\master_winpack-build-win64-vc15\opencv\modules\videoio\src\videoio_registry.cpp (223) cv::`anonymous-namespace'::VideoBackendRegistry::VideoBackendRegistry VIDEOIO: Enabled backends(8, sorted by priority): FFMPEG(1000); GSTREAMER(990); INTEL_MFX(980); MSMF(970); DSHOW(960); CV_IMAGES(950); CV_MJPEG(940); UEYE(930)
[ WARN:0@1.174] global C:\build\master_winpack-build-win64-vc15\opencv\modules\videoio\src\cap.cpp (246) cv::VideoCapture::open VIDEOIO(MSMF): trying capture cameraNum=0 ...
[ INFO:0@1.174] global C:\build\master_winpack-build-win64-vc15\opencv\modules\videoio\src\backend_plugin.cpp (383) cv::impl::getPluginCandidates Found 2 plugin(s) for MSMF
[ INFO:0@1.191] global c:\build\master_winpack-build-win64-vc15\opencv\modules\core\src\utils\plugin_loader.impl.hpp (67) cv::plugin::impl::DynamicLib::libraryLoad load D:\githubenterprise\MultiCamPrototype\out\build\x64-Debug\opencv_videoio_msmf455_64d.dll => OK
[ INFO:0@1.191] global C:\build\master_winpack-build-win64-vc15\opencv\modules\videoio\src\backend_plugin.cpp (50) cv::impl::PluginBackend::initCaptureAPI Found entry: 'opencv_videoio_capture_plugin_init_v1'
[ INFO:0@1.191] global C:\build\master_winpack-build-win64-vc15\opencv\modules\videoio\src\backend_plugin.cpp (169) cv::impl::PluginBackend::checkCompatibility Video I/O: initialized 'Microsoft Media Foundation OpenCV Video I/O plugin': built with OpenCV 4.5 (ABI/API = 1/1), current OpenCV version is '4.5.5' (ABI/API = 1/1)
[ INFO:0@1.191] global C:\build\master_winpack-build-win64-vc15\opencv\modules\videoio\src\backend_plugin.cpp (69) cv::impl::PluginBackend::initCaptureAPI Video I/O: plugin is ready to use 'Microsoft Media Foundation OpenCV Video I/O plugin'
[ INFO:0@1.191] global C:\build\master_winpack-build-win64-vc15\opencv\modules\videoio\src\backend_plugin.cpp (84) cv::impl::PluginBackend::initWriterAPI Found entry: 'opencv_videoio_writer_plugin_init_v1'
[ INFO:0@1.191] global C:\build\master_winpack-build-win64-vc15\opencv\modules\videoio\src\backend_plugin.cpp (169) cv::impl::PluginBackend::checkCompatibility Video I/O: initialized 'Microsoft Media Foundation OpenCV Video I/O plugin': built with OpenCV 4.5 (ABI/API = 1/1), current OpenCV version is '4.5.5' (ABI/API = 1/1)
[ INFO:0@1.191] global C:\build\master_winpack-build-win64-vc15\opencv\modules\videoio\src\backend_plugin.cpp (103) cv::impl::PluginBackend::initWriterAPI Video I/O: plugin is ready to use 'Microsoft Media Foundation OpenCV Video I/O plugin'
[ WARN:0@1.191] global C:\build\master_winpack-build-win64-vc15\opencv\modules\videoio\src\cap.cpp (269) cv::VideoCapture::open VIDEOIO(MSMF): can't create capture
Could not open camera 0
The reason i want to try MSMF is because when using DSHOW, it can not set parameters when opening, it only supports set parameters one bye one after the camera is opened. Frome what i observed through the LED status of the camera and the long time used, the camera was opened several times during the process.