win11 vs2022 opencv 4.10 camshift示例程序运行

记录win11 vs2022 opencv 4.10下 camshift等示例程序的单步debug启动方式,方便了解源码。

  1. debug版本编译通过,但运行时报出大量日志信息(部分dll加载FAILED后会自动找兼容dll)。但也能继续运行,效果如下

  2. release版本可以直接运行,help信息如下

    这种自描述的help信息挺好的,一开始猜测使用lena.jpg明显无法运行。

  3. 下载 https://www.bogotobogo.com/python/OpenCV_Python/images/mean_shift_tracking/slow_traffic_small.mp4 后,放在C:/code/opencv/samples/data/slow_traffic_small.mp4

  4. 运行example_tutorial_camshift.exe C:/code/opencv/samples/data/slow_traffic_small.mp4的效果如下

  5. debug版本输出信息主要是日志,解释如下:

c 复制代码
C:\code\opencv\build\x64\bin\Debug>example_tutorial_camshift.exe C:/code/opencv/samples/data/slow_traffic_small.mp4
[ INFO:[email protected]] 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:[email protected]] global backend_plugin.cpp:383 cv::impl::getPluginCandidates Found 3 plugin(s) for FFMPEG
[ INFO:[email protected]] 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:[email protected]] global plugin_loader.impl.hpp:67 cv::plugin::impl::DynamicLib::libraryLoad load opencv_videoio_ffmpeg4100_64d.dll => FAILED
[ INFO:[email protected]] global plugin_loader.impl.hpp:67 cv::plugin::impl::DynamicLib::libraryLoad load opencv_videoio_ffmpeg4100_64.dll => OK
[ INFO:[email protected]] global backend_plugin.cpp:50 cv::impl::PluginBackend::initCaptureAPI Found entry: 'opencv_videoio_capture_plugin_init_v1'
[ INFO:[email protected]] 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:[email protected]] 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:[email protected]] global backend_plugin.cpp:84 cv::impl::PluginBackend::initWriterAPI Found entry: 'opencv_videoio_writer_plugin_init_v1'
[ INFO:[email protected]] 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:[email protected]] 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:[email protected]] 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:[email protected]] 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:[email protected]] global plugin_loader.impl.hpp:67 cv::plugin::impl::DynamicLib::libraryLoad load opencv_core_parallel_onetbb4100_64d.dll => FAILED
[ INFO:[email protected]] 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:[email protected]] global plugin_loader.impl.hpp:67 cv::plugin::impl::DynamicLib::libraryLoad load opencv_core_parallel_tbb4100_64d.dll => FAILED
[ INFO:[email protected]] 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:[email protected]] global plugin_loader.impl.hpp:67 cv::plugin::impl::DynamicLib::libraryLoad load opencv_core_parallel_openmp4100_64d.dll => FAILED
[ INFO:[email protected]] 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:[email protected]] 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:[email protected]] global plugin_loader.impl.hpp:67 cv::plugin::impl::DynamicLib::libraryLoad load opencv_highgui_gtk4100_64.dll => FAILED
[ INFO:[email protected]] 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:[email protected]] global plugin_loader.impl.hpp:67 cv::plugin::impl::DynamicLib::libraryLoad load opencv_highgui_gtk34100_64.dll => FAILED
[ INFO:[email protected]] 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:[email protected]] global plugin_loader.impl.hpp:67 cv::plugin::impl::DynamicLib::libraryLoad load opencv_highgui_gtk24100_64.dll => FAILED
[ INFO:[email protected]] global backend.cpp:90 cv::highgui_backend::createUIBackend UI: using backend: WIN32 (priority=970)
[ INFO:[email protected]] global window_w32.cpp:2993 cv::impl::Win32BackendUI::createWindow OpenCV/UI: Creating Win32UI window: img2 (1)
[ INFO:[email protected]] global plugin_loader.impl.hpp:74 cv::plugin::impl::DynamicLib::libraryRelease unload opencv_videoio_ffmpeg4100_64.dll

从错误信息的分析来看,Debug版本中的信息输出是OpenCV库在Debug模式下为开发者提供的详细日志。这些日志帮助开发者了解模块加载过程,特别是动态库加载、插件初始化以及后端选择的情况。

错误信息分析

以下是详细解读:

1. 视频 I/O 后端初始化
text 复制代码
[ INFO:[email protected]] global videoio_registry.cpp:244 cv::`anonymous-namespace'::VideoBackendRegistry::VideoBackendRegistry VIDEOIO: Enabled backends...
  • OpenCV支持多种视频I/O后端(如FFMPEG、GStreamer等),这些后端按优先级排序。
  • 日志表示OpenCV在尝试加载这些后端插件,并会选择最优的后端。
2. FFMPEG动态库加载
text 复制代码
[ INFO:[email protected]] 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 成功:

    text 复制代码
    [ INFO:[email protected]] global plugin_loader.impl.hpp:67 cv::plugin::impl::DynamicLib::libraryLoad load opencv_videoio_ffmpeg4100_64.dll => OK
  • 这是因为Debug模式下需要Debug版本的动态库(通常以d结尾),但该库可能未正确构建或路径未配置。加载失败后,OpenCV默认回退到Release库。

3. 并行计算后端
text 复制代码
[ INFO:[email protected]] 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 后端初始化
text 复制代码
[ INFO:[email protected]] global registry.impl.hpp:114 cv::highgui_backend::UIBackendRegistry::UIBackendRegistry UI: Enabled backends...
  • OpenCV支持多种UI后端(如GTK、WIN32等)。在日志中,尝试加载GTK相关的动态库均失败:

    text 复制代码
    [ INFO:[email protected]] global plugin_loader.impl.hpp:67 cv::plugin::impl::DynamicLib::libraryLoad load opencv_highgui_gtk24100_64.dll => FAILED
  • 最终选择了WIN32作为后端:

    text 复制代码
    [ INFO:[email protected]] global backend.cpp:90 cv::highgui_backend::createUIBackend UI: using backend: WIN32 (priority=970)

为什么这些信息不会影响运行?

  1. 插件加载机制具有容错性

    • OpenCV在尝试加载动态库失败后,会回退到其他可用的库或默认实现(如Release版本的FFMPEG库)。
  2. 运行时依赖检查

    • 如果没有找到适合的插件,OpenCV仍会使用内置的基本实现(如单线程计算)。
  3. 日志仅用于Debug模式

    • Debug版本输出的这些日志旨在帮助开发者调试,Release版本中不会显示这些信息,因为动态库加载已被优化。

如何改进?

  1. 确保Debug动态库可用

    • 确认 opencv_videoio_ffmpeg4100_64d.dll 和其他带d的库是否存在。如果缺失,可以尝试重新编译OpenCV的Debug版本。
  2. 调整路径配置

    • 检查环境变量 PATH 或使用 set 命令,确保Debug版本库的路径已正确配置。
  3. 避免干扰正常输出

    • 可以在Debug模式下通过设置日志级别减少不必要的日志输出:

      cpp 复制代码
      cv::utils::logging::setLogLevel(cv::utils::logging::LOG_LEVEL_WARNING);

总结

上述错误信息显示的是Debug模式下的详细加载日志,而非运行时错误。只要最终动态库加载成功(如Release库被使用),程序功能不会受到影响。优化路径配置和动态库编译可以消除这些无意义的失败信息,从而简化调试过程。

  1. release版本的调试,设置3处:

    "链接器"->"调试"->"生成调试信息",设置为"是(/DEBUG)"。

    "C/C++"->"优化",设置为"禁止(/Od)"

    "C/C++"->"常规"->"调试信息格式",设置为"程序数据库(/Zi)"

  2. debug/release版本设置命令参数后启动调试

    debug/release版本调试效果类似。

  3. opencv的部分python例程可以右键直接运行,有些不行的,估计是环境缺失,例如测试文件缺失、参数不全之类的。

相关推荐
羑悻的小杀马特25 分钟前
OpenCV 引擎:驱动实时应用开发的科技狂飙
人工智能·科技·opencv·计算机视觉
蹦蹦跳跳真可爱5891 小时前
Python----计算机视觉处理(Opencv:道路检测之提取车道线)
python·opencv·计算机视觉
qp9 小时前
21.OpenCV获取图像轮廓信息
javascript·opencv·webpack
I'mFAN11 小时前
QT_xcb 问题
人工智能·python·opencv·计算机视觉
www_pp_12 小时前
# 实时人脸识别系统:基于 OpenCV 和 Python 的实现
人工智能·python·opencv
巷95513 小时前
OpenCV图像形态学:原理、操作与应用详解
人工智能·opencv·计算机视觉
阿linlin14 小时前
OpenCV--图像预处理学习01
opencv·学习·计算机视觉
jndingxin17 小时前
OpenCV 图形API(10)用于执行标量除以矩阵的逐元素操作函数divRC()
人工智能·opencv
weixin_4424240319 小时前
Opencv计算机视觉编程攻略-第七节 提取直线、轮廓和区域
人工智能·opencv·计算机视觉
闲人编程19 小时前
形态学操作(腐蚀/膨胀/开闭运算)
python·opencv·图像识别