使用 vcpkg 时如何包含 OpenCV 的 cv::VideoWriter?

how to include OpenCV's cv::VideoWriter when using vcpkg?

我正在使用 vcpkg 在 Windows 上安装 OpenCV4。但是当我尝试 link 我的应用程序时,我正在使用的 OpenCV classes 之一给我带来了麻烦:

2>main.obj : error LNK2019: unresolved external symbol "public: __cdecl cv::VideoWriter::VideoWriter(void)" (??0VideoWriter@cv@@QEAA@XZ) referenced in function main
2>main.obj : error LNK2019: unresolved external symbol "public: virtual __cdecl cv::VideoWriter::~VideoWriter(void)" (??1VideoWriter@cv@@UEAA@XZ) referenced in function main
2>main.obj : error LNK2019: unresolved external symbol "public: virtual bool __cdecl cv::VideoWriter::open(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,int,double,class cv::Size_<int>,bool)" (?open@VideoWriter@cv@@UEAA_NAEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@HNV?$Size_@H@2@_N@Z) referenced in function main

所以我想我需要启用一个非默认功能。 OpenCV最初是这样安装的:

vcpkg install --triplet x64-windows-static-md opencv4

默认情况下,这似乎安装 [dnn,jpeg,opengl,png,tiff,webp]

我还尝试添加了一些可选功能,包括:

vcpkg install --triplet x64-windows-static-md opencv4[core,jpeg,opengl,png,tiff,webp,ffmpeg,openmp]

输出:

...cut...
The package opencv4:x64-windows-static-md provides CMake targets:

find_package(OpenCV CONFIG REQUIRED)
# Note: 14 target(s) were omitted.
target_link_libraries(main PRIVATE quirc opencv_ml libprotobuf opencv_core)

我在调用 cmake 创建项目时使用了 vcpkg 工具链文件。根据 vcpkg 的指示,我的 CMakeLists.txt 文件的相关部分包含以下内容:

FIND_PACKAGE(OpenCV CONFIG REQUIRED)
INCLUDE_DIRECTORIES ( BEFORE ${OpenCV_INCLUDE_DIRS} )
ADD_EXECUTABLE ( mytest main.cpp )
TARGET_LINK_LIBRARIES ( mytest PRIVATE quirc opencv_ml libprotobuf opencv_core )

部分问题是 vcpkg ports/opencv4/control 文件包含大约 20 个可选功能,描述几乎毫无用处。

我的问题:

有人知道访问 cv::VideoWriter class 需要什么 vcpkg 功能,或者在代码中查找什么以便我找出需要哪个可选功能?

正如@squareskittles 评论的那样,解决方案是由于 vcpkg 生成的 TARGET_LINK_LIBRARIES 行中缺少一些名称。

我的解决方案是更改此行:

TARGET_LINK_LIBRARIES ( mytest PRIVATE quirc opencv_ml libprotobuf opencv_core )

...改为看起来像这样:

TARGET_LINK_LIBRARIES ( mytest PRIVATE quirc opencv_ml libprotobuf opencv_core opencv_videoio )

并且在我的其他测试应用程序之一中,我还必须添加 opencv_highgui。看起来 vcpkg 生成的“目标”行不包含所需的所有内容。