OpenCV via NuGet packages with Visual Studio 2015, how to configure?

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

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.

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

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

在这里输入图像描述

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)

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

Start Visual Studio 2015, make an Empty Project:

在这里输入图像描述

Bring up the NuGet package manager:

在这里输入图像描述

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

在这里输入图像描述

在这里输入图像描述

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

在这里输入图像描述

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

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:

在这里输入图像描述

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

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 ---------------

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:

在这里输入图像描述

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>------ 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::M at 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 LNK2 019: 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:UserscdahmsDocumentsTest2x64DebugTest2.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:

在这里输入图像描述

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.


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

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.

在这里输入图像描述

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

链接地址: http://www.djcxy.com/p/95158.html

上一篇: JavaFX旋转矩形关于中心?

下一篇: OpenCV通过NuGet包与Visual Studio 2015,如何配置?