通过带有Visual Studio 2015的NuGet包的OpenCV,如何配置? [英] OpenCV via NuGet packages with Visual Studio 2015, how to configure?

查看:184
本文介绍了通过带有Visual Studio 2015的NuGet包的OpenCV,如何配置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过Visual Studio 2015的NuGet包使用OpenCV,但似乎无法完成所有配置.我不确定我在某个地方犯了错误还是不支持我尝试的内容.

I'm trying to use OpenCV via NuGet packages with Visual Studio 2015 and I can't seem to get everything configured. I'm not sure if I'm making a mistake somewhere or what I'm trying is not supported.

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

A little background, I made this tutorial a while back:

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

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

And I'd like to update this to use NuGets if possible. I use NuGets on the job every day so I'm familiar with the concept, but I've only previously used NuGets with .Net (Visual Basic or C#) applications.

我正在尝试使它使用飞机简式C ++ OpenCV,而不是.NET或UWP应用程序内.

I'm trying to make this work with plane jane C++ OpenCV, not within a .NET or UWP app.

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

For the record, in a separate .Net test project, I tried the EmguCV NuGet package:

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

With Visual Studio 2015 and everything worked as expected (for those not familiar, Emgu CV is probably the oldest/best known/most stable .Net wrapper for OpenCV)

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

Here are the steps I tried to get regular C++ OpenCV to work within Visual Studio 2015 using NuGets:

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

Start Visual Studio 2015, make an Empty Project:

启动NuGet软件包管理器:

Bring up the NuGet package manager:

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

I choose OpenCV.Win.ImgProc as that seemed to be the only OpenCV 3.x NuGet available, this also auto imported Core as expected:

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

Then I added a .cpp file and copied/pasted in known-good OpenCV code, the OpenCV libraries are not recognized:

我尝试了Build-> Clean,Build-> Build,同样关注.我也尝试过将解决方案配置"和解决方案平台"设置为Debug/Release/x86/x64,这也是出于同样的考虑.

I tried Build -> Clean, Build -> Build, same concern. I also tried "Solution Configurations" and "Solution Platforms" set to Debug / Release / x86 / x64, same concern.

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

Am I missing a step here? Do NuGets only work within a managed environment such as .Net or UWP, or can they work with regular C++ as well? I did notice the mention in the Description about UWP:

但是我没有使用VideoIO,所以我不确定那应该很重要.

But I'm not using VideoIO, so I'm not sure that should matter.

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

Has anybody had any success with this? I can always go back to the "old school" way of directly referencing libraries in Project -> (project name) Properties as shown in my tutorial linked to above, but I'd like to use NuGets if possible.

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

----------- Edit ---------------

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

I had to place my response to Leo-MSFT here to allow for enough characters and screenshots. Thanks for the suggestion Leo-MSFT, but two problems with that. For one, that package is OpenCV 2.4.10, very outdated by now:

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

2nd, if I use that package the red underlines are gone, but I get the following linker errors when I try to build and run:

1> ------构建开始:项目:Test2,配置:调试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在函数main中引用 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函数主函数中引用的@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(类std :: basic_string,类std :: allocator> const& ;,类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 @@在函数main中引用的YA?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)(?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 @@ 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 @@函数main中引用的YAXAEBV_InputArray @ 1 @ AEBV_OutputArray @ 1 @ HH @ Z) 1> C:\ Users \ cdahms \ Documents \ Test2 \ x64 \ Debug \ Test2.exe:致命错误LNK1120:13无法解析的外部 ===========构建:0成功,1失败,0最新,跳过0 ==========

1>------ Build started: Project: Test2, Configuration: Debug x64 ------ 1> test.cpp 1>test.obj : error LNK2019: unresolved external symbol "void __cdecl cv::fastFree(void *)" (?fastFree@cv@@YAXPEAX@Z) referenced in function "public: __cdecl cv::Mat::~Mat(void)" (??1Mat@cv@@QEAA@XZ) 1>test.obj : error LNK2019: unresolved external symbol "public: __cdecl cv::_InputArray::_InputArray(class cv::Mat const &)" (??0_InputArray@cv@@QEAA@AEBVMat@1@@Z) referenced in function main 1>test.obj : error LNK2019: unresolved external symbol "public: __cdecl cv::_OutputArray::_OutputArray(class cv::Mat &)" (??0_OutputArray@cv@@QEAA@AEAVMat@1@@Z) referenced in function main 1>test.obj : error LNK2019: unresolved external symbol "public: void __cdecl cv::Mat::deallocate(void)" (?deallocate@Mat@cv@@QEAAXXZ) referenced in function "public: void __cdecl cv::Mat::release(void)" (?release@Mat@cv@@QEAAXXZ) 1>test.obj : error LNK2019: unresolved external symbol "public: void __cdecl cv::Mat::copySize(class cv::Mat const &)" (?copySize@Mat@cv@@QEAAXAEBV12@@Z) referenced in function "public: class cv::Mat & __cdecl cv::Mat::operator=(class cv::Mat const &)" (??4Mat@cv@@QEAAAEAV01@AEBV01@@Z) 1>test.obj : error LNK2019: unresolved external symbol "int __cdecl cv::_interlockedExchangeAdd(int *,int)" (?_interlockedExchangeAdd@cv@@YAHPEAHH@Z) referenced in function "public: class cv::Mat & __cdecl cv::Mat::operator=(class cv::Mat const &)" (??4Mat@cv@@QEAAAEAV01@AEBV01@@Z) 1>test.obj : error LNK2019: unresolved external symbol "void __cdecl cv::namedWindow(class std::basic_string,class std::allocator > const &,int)" (?namedWindow@cv@@YAXAEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@H@Z) referenced in function main 1>test.obj : error LNK2019: unresolved external symbol "int __cdecl cv::waitKey(int)" (?waitKey@cv@@YAHH@Z) referenced in function main 1>test.obj : error LNK2019: unresolved external symbol "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) referenced in function main 1>test.obj : error LNK2019: unresolved external symbol "class cv::Mat __cdecl cv::imread(class std::basic_string,class std::allocator > const &,int)" (?imread@cv@@YA?AVMat@1@AEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@H@Z) referenced in function main 1>test.obj : error LNK2019: unresolved external symbol "void __cdecl cv::GaussianBlur(class cv::_InputArray const &,class cv::OutputArray const &,class cv::Size,double,double,int)" (?GaussianBlur@cv@@YAXAEBV_InputArray@1@AEBV_OutputArray@1@V?$Size_@H@1@NNH@Z) referenced in function main 1>test.obj : error LNK2019: unresolved external symbol "void __cdecl cv::Canny(class cv::_InputArray const &,class cv::_OutputArray const &,double,double,int,bool)" (?Canny@cv@@YAXAEBV_InputArray@1@AEBV_OutputArray@1@NNH_N@Z) referenced in function main 1>test.obj : error LNK2019: unresolved external symbol "void __cdecl cv::cvtColor(class cv::_InputArray const &,class cv::_OutputArray const &,int,int)" (?cvtColor@cv@@YAXAEBV_InputArray@1@AEBV_OutputArray@1@HH@Z) referenced in function main 1>C:\Users\cdahms\Documents\Test2\x64\Debug\Test2.exe : fatal error LNK1120: 13 unresolved externals ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

尝试各种选项后,我决定使用此软件包:

After trying various options, I've settled on this package:

这似乎可行,尽管它不是很令人鼓舞,它清楚地将其标记为非官方软件包",并且它已经过时(不过,从OpenCV 3.1.0到3.2.0的更改并不多).我想我会一直使用它,直到发布正确的更新程序包为止.

Which seems to work, although it's not very confidence inspiring that it is clearly labeled "not an official package" and also that it's slightly out of date (not many changes from OpenCV 3.1.0 to 3.2.0 however). I suppose I'll use this until a proper updated package is released.

推荐答案

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

The OpenCV libraries package is OpenCV3.1 rather than OpenCV.Win.ImgProc for your test OpenCV code.

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

Below is my test result, so you just need to install the OpenCV3.1 NuGet package instead of OpenCV.Win.ImgProc for that OpenCV code.

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

Note that: OpenCV3.1 is not an official package.

这篇关于通过带有Visual Studio 2015的NuGet包的OpenCV,如何配置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆