c++ - 通过带有Visual Studio 2015的NuGet包的OpenCV,如何配置?

标签 c++ visual-studio opencv nuget

我试图通过Visual Studio 2015的NuGet包使用OpenCV,但似乎无法完成所有配置。我不确定在某处犯错还是不支持我尝试的内容。

有一点背景知识,我在不久前制作了本教程:

https://www.youtube.com/watch?v=7SM5OD2pZKY
https://github.com/MicrocontrollersAndMore/OpenCV_3_Windows_10_Installation_Tutorial

如果可能的话,我想更新它以使用NuGets。我每天都在工作中使用NuGets,所以我对这个概念很熟悉,但是我以前只将NuGets与.Net(Visual Basic或C#)应用程序一起使用。

我试图使它与飞机简·C++ OpenCV一起使用,而不是在.NET或UWP应用程序内。

作为记录,在一个单独的.Net测试项目中,我尝试了EmguCV NuGet软件包:

enter image description here

使用Visual Studio 2015,一切都能按预期工作(对于不熟悉的人,Emgu CV可能是OpenCV的最旧/最知名/最稳定的.Net包装器)

这是我尝试使用NuGets使常规C++ OpenCV在Visual Studio 2015中工作的步骤:

启动Visual Studio 2015,创建一个空项目:

enter image description here

调出NuGet软件包管理器:

enter image description here

我选择OpenCV.Win.ImgProc,因为这似乎是唯一可用的OpenCV 3.x NuGet,这也按预期自动导入了Core:

enter image description here

enter image description here

然后,我添加了一个.cpp文件,并以已知良好的OpenCV代码复制/粘贴了该代码,但无法识别OpenCV库:

enter image description here

我试过Build-> Clean,Build-> Build,同样关注。我还尝试了将“Solution Configurations”和“Solution Platforms”设置为Debug / Release / x86 / x64,这同样引起关注。

我在这里错过了一步吗? NuGet是否仅在.Net或UWP之类的托管环境中工作,还是可以与常规C++一起工作?我确实注意到有关UWP的描述中提到的内容:

enter image description here

但是我没有使用VideoIO,所以我不确定这是否重要。

有人在这方面有成功吗?我总是可以回到直接引用Project->(项目名称)Properties中的库的“老派”方式,如上面链接到我的教程中所示,但是如果可能的话,我想使用NuGets。

-----------编辑---------------

我必须在此处放置对Leo-MSFT的回复,以允许足够的字符和屏幕截图。感谢您的建议Leo-MSFT,但这有两个问题。首先,该软件包是OpenCV 2.4.10,目前已经过时了:

enter image description here

第二,如果使用该软件包,红色的下划线消失了,但是在尝试构建和运行时出现以下链接器错误:

1> ------开始构建:项目:Test2,配置:Debug x64 ------
1> test.cpp
1> test.obj:错误LNK2019:未解析的外部符号“void __cdecl cv::fastFree(void *)”(?fastFree @ cv @@ YAXPEAX @ Z)在函数“public:__cdecl cv::Mat::〜Mat”中引用(void)”(?? 1Mat @ cv @@ QEAA @ XZ)
1> test.obj:错误LNK2019:未解决的外部符号“public:__cdecl cv::_ InputArray::_ InputArray(class cv::Mat const&)”(?? 0_InputArray @ cv @@ QEAA @ AEBVMat @ 1 @@@ Z)在函数main中引用
1> test.obj:错误LNK2019:未解决的外部符号“public:__cdecl cv::_ OutputArray::_ OutputArray(class cv::Mat&)”(?? 0_OutputArray @ cv @@ QEAA @ AEAVMat @ 1 @@ Z)在功能主体中
1> test.obj:错误LNK2019:未解决的外部符号“public:void __cdecl cv::Mat::deallocate(void)”(?deallocate @ Mat @ cv @@ QEAAXXZ)在函数“public:void __cdecl cv::中引用” Mat::release(void)”(?release @ Mat @ cv @@ QEAAXXZ)
1> test.obj:错误LNK2019:未解决的外部符号“public:void __cdecl cv::Mat::copySize(class cv::Mat const&)”(?copySize @ Mat @ cv @@ QEAAXAEBV12 @@ Z)函数“public:class cv::Mat&__cdecl cv::Mat::operator =(class cv::Mat const&)”(?? 4Mat @ cv @@ QEAAAEAV01 @ AEBV01 @@ Z)
1> test.obj:错误LNK2019:未解决的外部符号“int __cdecl cv::_ interlockedExchangeAdd(int *,int)”(?_ interlockedExchangeAdd @ cv @@ YAHPEAHH @ Z)在函数“public:class cv::Mat&__cdecl中引用” cv::Mat::operator =(class cv::Mat const&)“(?? 4Mat @ cv @@ QEAAAEAV01 @ AEBV01 @@ Z)
1> test.obj:错误LNK2019:未解决的外部符号“void __cdecl cv::namedWindow(class std::basic_string,class std::allocator> const&,int)”(?namedWindow @ cv @@ YAXAEBV?$ basic_string @函数main中引用的DU?$ char_traits @ D @ std @@ V?$ allocator @ D @ 2 @@ std @@ H @ Z)
1> test.obj:错误LNK2019:函数main中引用的未解析的外部符号“int __cdecl cv::waitKey(int)”(?waitKey @ cv @@ YAHH @ Z)
1> test.obj:错误LNK2019:未解决的外部符号“void __cdecl cv::imshow(class std::basic_string,class std::allocator> const&,class cv::_ InputArray const&)”(?imshow @ cv @函数主函数中引用的@YAXAEBV?$ basic_string @ DU?$ char_traits @ D @ std @@ V?$ allocator @ D @ 2 @@ std @@ AEBV_InputArray @ 1 @@ Z
1> test.obj:错误LNK2019:未解析的外部符号“class cv::Mat __cdecl cv::imread(class std::basic_string,class std::allocator> const&,int)”(?imread @ cv @@ YA函数main中引用的?AVMat @ 1 @ AEBV?$ basic_string @ DU?$ char_traits @ D @ std @@ V?$ allocator @ D @ 2 @@ std @@ H @ Z
1> test.obj:错误LNK2019:未解决的外部符号“void __cdecl cv::GaussianBlur(class cv::_ InputArray const&,class cv::OutputArray const&,class cv::Size,double,double,int)”(函数main中引用的?GaussianBlur @ cv @@ YAXAEBV_InputArray @ 1 @ AEBV_OutputArray @ 1 @ V?$ Size_ @ H @ 1 @ NNH @ Z
1> test.obj:错误LNK2019:未解决的外部符号“void __cdecl cv::Canny(class cv::_ InputArray const&,class cv::_ OutputArray const&,double,double,int,bool)”(?Canny @ cv函数main中引用的@@ YAXAEBV_InputArray @ 1 @ AEBV_OutputArray @ 1 @ NNH_N @ Z)
1> test.obj:错误LNK2019:未解决的外部符号“void __cdecl cv::cvtColor(class cv::_ InputArray const&,class cv::_ OutputArray const&,int,int)”(?cvtColor @ cv @@ YAXAEBV_InputArray @函数main中引用的1 @ AEBV_OutputArray @ 1 @ HH @ Z)
1> C:\ Users \ cdahms \ Documents \ Test2 \ x64 \ Debug \ Test2.exe:致命错误LNK1120:13无法解析的外部
==========构建:0成功,1失败,0最新,跳过0 ==========

在尝试了各种选择之后,我决定使用此软件包:

enter image description here

这似乎可行,尽管并不是很自信地鼓舞了它被明确标记为“非官方软件包”,而且它已经过时了(但是,从OpenCV 3.1.0到3.2.0的更改并不多)。我想我将使用它直到发布正确的更新程序包。

最佳答案

对于您的测试OpenCV代码,OpenCV库软件包是 OpenCV3.1 而不是OpenCV.Win.ImgProc。

以下是我的测试结果,因此对于该OpenCV代码,您只需要安装 OpenCV3.1 NuGet软件包而不是OpenCV.Win.ImgProc。

enter image description here

请注意:OpenCV3.1不是官方软件包。

关于c++ - 通过带有Visual Studio 2015的NuGet包的OpenCV,如何配置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42317398/

相关文章:

visual-studio - 如何扩展 CodeLens

visual-studio - 如何设置 Visual Studio 以显示首次机会异常的堆栈跟踪?

python-2.7 - python cv2.Videocapture() 不起作用,cap.isOpened() 返回 false

c++ - 另一个 OpenCV/cvBlob 和架构问题

c++ - 嵌入 C++ 的 MySql

c++ - 具有默认类型的可变参数模板

c++ - 当类型可能发生变化时,如何最好地处理警告 c4305?

python - OpenCV/python:如何使用公式更改图像像素的值?

c++ - 在 for 循环中初始化迭代计数器是否效率较低?

c++ - 模拟练习的时间复杂度