记录win11 vs2022 opencv 4.10下 camshift等示例程序的单步debug启动方式,方便了解源码。
-
debug版本编译通过,但运行时报出大量日志信息(部分dll加载FAILED后会自动找兼容dll)。但也能继续运行,效果如下
-
release版本可以直接运行,help信息如下
这种自描述的help信息挺好的,一开始猜测使用lena.jpg明显无法运行。
-
下载 https://www.bogotobogo.com/python/OpenCV_Python/images/mean_shift_tracking/slow_traffic_small.mp4 后,放在C:/code/opencv/samples/data/slow_traffic_small.mp4
-
运行example_tutorial_camshift.exe C:/code/opencv/samples/data/slow_traffic_small.mp4的效果如下
-
debug版本输出信息主要是日志,解释如下:
C:\code\opencv\build\x64\bin\Debug>example_tutorial_camshift.exe C:/code/opencv/samples/data/slow_traffic_small.mp4
[ INFO:0@0.003] global videoio_registry.cpp:244 cv::`anonymous-namespace'::VideoBackendRegistry::VideoBackendRegistry VIDEOIO: Enabled backends(9, sorted by priority): FFMPEG(1000); GSTREAMER(990); INTEL_MFX(980); MSMF(970); DSHOW(960); CV_IMAGES(950); CV_MJPEG(940); UEYE(930); OBSENSOR(920)
[ INFO:0@0.003] global backend_plugin.cpp:383 cv::impl::getPluginCandidates Found 3 plugin(s) for FFMPEG
[ INFO:0@0.004] global plugin_loader.impl.hpp:67 cv::plugin::impl::DynamicLib::libraryLoad load C:\code\opencv\build\x64\bin\Debug\opencv_videoio_ffmpeg4100_64d.dll => FAILED
[ INFO:0@0.005] global plugin_loader.impl.hpp:67 cv::plugin::impl::DynamicLib::libraryLoad load opencv_videoio_ffmpeg4100_64d.dll => FAILED
[ INFO:0@0.007] global plugin_loader.impl.hpp:67 cv::plugin::impl::DynamicLib::libraryLoad load opencv_videoio_ffmpeg4100_64.dll => OK
[ INFO:0@0.007] global backend_plugin.cpp:50 cv::impl::PluginBackend::initCaptureAPI Found entry: 'opencv_videoio_capture_plugin_init_v1'
[ INFO:0@0.008] global backend_plugin.cpp:169 cv::impl::PluginBackend::checkCompatibility Video I/O: initialized 'FFmpeg OpenCV Video I/O Capture plugin': built with OpenCV 4.10 (ABI/API = 1/1), current OpenCV version is '4.10.0' (ABI/API = 1/1)
[ INFO:0@0.008] global backend_plugin.cpp:69 cv::impl::PluginBackend::initCaptureAPI Video I/O: plugin is ready to use 'FFmpeg OpenCV Video I/O Capture plugin'
[ INFO:0@0.008] global backend_plugin.cpp:84 cv::impl::PluginBackend::initWriterAPI Found entry: 'opencv_videoio_writer_plugin_init_v1'
[ INFO:0@0.008] global backend_plugin.cpp:169 cv::impl::PluginBackend::checkCompatibility Video I/O: initialized 'FFmpeg OpenCV Video I/O Writer plugin': built with OpenCV 4.10 (ABI/API = 1/1), current OpenCV version is '4.10.0' (ABI/API = 1/1)
[ INFO:0@0.008] global backend_plugin.cpp:103 cv::impl::PluginBackend::initWriterAPI Video I/O: plugin is ready to use 'FFmpeg OpenCV Video I/O Writer plugin'
[ INFO:0@0.072] global registry_parallel.impl.hpp:96 cv::parallel::ParallelBackendRegistry::ParallelBackendRegistry core(parallel): Enabled backends(3, sorted by priority): ONETBB(1000); TBB(990); OPENMP(980)
[ INFO:0@0.073] global plugin_loader.impl.hpp:67 cv::plugin::impl::DynamicLib::libraryLoad load C:\code\opencv\build\x64\bin\Debug\opencv_core_parallel_onetbb4100_64d.dll => FAILED
[ INFO:0@0.075] global plugin_loader.impl.hpp:67 cv::plugin::impl::DynamicLib::libraryLoad load opencv_core_parallel_onetbb4100_64d.dll => FAILED
[ INFO:0@0.075] global plugin_loader.impl.hpp:67 cv::plugin::impl::DynamicLib::libraryLoad load C:\code\opencv\build\x64\bin\Debug\opencv_core_parallel_tbb4100_64d.dll => FAILED
[ INFO:0@0.077] global plugin_loader.impl.hpp:67 cv::plugin::impl::DynamicLib::libraryLoad load opencv_core_parallel_tbb4100_64d.dll => FAILED
[ INFO:0@0.077] global plugin_loader.impl.hpp:67 cv::plugin::impl::DynamicLib::libraryLoad load C:\code\opencv\build\x64\bin\Debug\opencv_core_parallel_openmp4100_64d.dll => FAILED
[ INFO:0@0.078] global plugin_loader.impl.hpp:67 cv::plugin::impl::DynamicLib::libraryLoad load opencv_core_parallel_openmp4100_64d.dll => FAILED
[ INFO:0@0.088] global registry.impl.hpp:114 cv::highgui_backend::UIBackendRegistry::UIBackendRegistry UI: Enabled backends(4, sorted by priority): GTK(1000); GTK3(990); GTK2(980); WIN32(970) + BUILTIN(WIN32UI)
[ INFO:0@0.088] global plugin_loader.impl.hpp:67 cv::plugin::impl::DynamicLib::libraryLoad load C:\code\opencv\build\x64\bin\Debug\opencv_highgui_gtk4100_64.dll => FAILED
[ INFO:0@0.090] global plugin_loader.impl.hpp:67 cv::plugin::impl::DynamicLib::libraryLoad load opencv_highgui_gtk4100_64.dll => FAILED
[ INFO:0@0.090] global plugin_loader.impl.hpp:67 cv::plugin::impl::DynamicLib::libraryLoad load C:\code\opencv\build\x64\bin\Debug\opencv_highgui_gtk34100_64.dll => FAILED
[ INFO:0@0.091] global plugin_loader.impl.hpp:67 cv::plugin::impl::DynamicLib::libraryLoad load opencv_highgui_gtk34100_64.dll => FAILED
[ INFO:0@0.091] global plugin_loader.impl.hpp:67 cv::plugin::impl::DynamicLib::libraryLoad load C:\code\opencv\build\x64\bin\Debug\opencv_highgui_gtk24100_64.dll => FAILED
[ INFO:0@0.093] global plugin_loader.impl.hpp:67 cv::plugin::impl::DynamicLib::libraryLoad load opencv_highgui_gtk24100_64.dll => FAILED
[ INFO:0@0.094] global backend.cpp:90 cv::highgui_backend::createUIBackend UI: using backend: WIN32 (priority=970)
[ INFO:0@0.094] global window_w32.cpp:2993 cv::impl::Win32BackendUI::createWindow OpenCV/UI: Creating Win32UI window: img2 (1)
[ INFO:1@45.156] global plugin_loader.impl.hpp:74 cv::plugin::impl::DynamicLib::libraryRelease unload opencv_videoio_ffmpeg4100_64.dll
从错误信息的分析来看,Debug版本中的信息输出是OpenCV库在Debug模式下为开发者提供的详细日志。这些日志帮助开发者了解模块加载过程,特别是动态库加载、插件初始化以及后端选择的情况。
错误信息分析
以下是详细解读:
1. 视频 I/O 后端初始化
[ INFO:0@0.003] global videoio_registry.cpp:244 cv::`anonymous-namespace'::VideoBackendRegistry::VideoBackendRegistry VIDEOIO: Enabled backends...
- OpenCV支持多种视频I/O后端(如FFMPEG、GStreamer等),这些后端按优先级排序。
- 日志表示OpenCV在尝试加载这些后端插件,并会选择最优的后端。
2. FFMPEG动态库加载
[ INFO:0@0.004] global plugin_loader.impl.hpp:67 cv::plugin::impl::DynamicLib::libraryLoad load C:\code\opencv\build\x64\bin\Debug\opencv_videoio_ffmpeg4100_64d.dll => FAILED
- OpenCV在尝试加载动态库
opencv_videoio_ffmpeg4100_64d.dll
失败。 - 随后尝试加载非Debug版本的库
opencv_videoio_ffmpeg4100_64.dll
成功:[ INFO:0@0.007] global plugin_loader.impl.hpp:67 cv::plugin::impl::DynamicLib::libraryLoad load opencv_videoio_ffmpeg4100_64.dll => OK
- 这是因为Debug模式下需要Debug版本的动态库(通常以
d
结尾),但该库可能未正确构建或路径未配置。加载失败后,OpenCV默认回退到Release库。
3. 并行计算后端
[ INFO:0@0.073] global plugin_loader.impl.hpp:67 cv::plugin::impl::DynamicLib::libraryLoad load C:\code\opencv\build\x64\bin\Debug\opencv_core_parallel_onetbb4100_64d.dll => FAILED
- 类似于FFMPEG动态库,OpenCV尝试加载并行计算的动态库(如ONETBB、TBB等)均失败。
- 即使加载失败,也不会影响运行,因为OpenCV可能会选择备用实现(如单线程)。
4. UI 后端初始化
[ INFO:0@0.088] global registry.impl.hpp:114 cv::highgui_backend::UIBackendRegistry::UIBackendRegistry UI: Enabled backends...
- OpenCV支持多种UI后端(如GTK、WIN32等)。在日志中,尝试加载GTK相关的动态库均失败:
[ INFO:0@0.093] global plugin_loader.impl.hpp:67 cv::plugin::impl::DynamicLib::libraryLoad load opencv_highgui_gtk24100_64.dll => FAILED
- 最终选择了WIN32作为后端:
[ INFO:0@0.094] global backend.cpp:90 cv::highgui_backend::createUIBackend UI: using backend: WIN32 (priority=970)
为什么这些信息不会影响运行?
-
插件加载机制具有容错性
- OpenCV在尝试加载动态库失败后,会回退到其他可用的库或默认实现(如Release版本的FFMPEG库)。
-
运行时依赖检查
- 如果没有找到适合的插件,OpenCV仍会使用内置的基本实现(如单线程计算)。
-
日志仅用于Debug模式
- Debug版本输出的这些日志旨在帮助开发者调试,Release版本中不会显示这些信息,因为动态库加载已被优化。
如何改进?
-
确保Debug动态库可用
- 确认
opencv_videoio_ffmpeg4100_64d.dll
和其他带d
的库是否存在。如果缺失,可以尝试重新编译OpenCV的Debug版本。
- 确认
-
调整路径配置
- 检查环境变量
PATH
或使用set
命令,确保Debug版本库的路径已正确配置。
- 检查环境变量
-
避免干扰正常输出
- 可以在Debug模式下通过设置日志级别减少不必要的日志输出:
cv::utils::logging::setLogLevel(cv::utils::logging::LOG_LEVEL_WARNING);
- 可以在Debug模式下通过设置日志级别减少不必要的日志输出:
总结
上述错误信息显示的是Debug模式下的详细加载日志,而非运行时错误。只要最终动态库加载成功(如Release库被使用),程序功能不会受到影响。优化路径配置和动态库编译可以消除这些无意义的失败信息,从而简化调试过程。
-
release版本的调试,设置3处:
“链接器”->“调试”->“生成调试信息”,设置为“是(/DEBUG)”。
“C/C++”->“优化”,设置为“禁止(/Od)”
“C/C++”->“常规”->“调试信息格式”,设置为“程序数据库(/Zi)” -
debug/release版本设置命令参数后启动调试
debug/release版本调试效果类似。
-
opencv的部分python例程可以右键直接运行,有些不行的,估计是环境缺失,例如测试文件缺失、参数不全之类的。