利用UI界面进行安装

1.创建新项目,利用鼠标右键单击项目,并选择Nuget安装包管理器,具体如下所示:OpenCV入门---VS2015安装OpenCV(Nuget安装)

2.利用Nuget安装Opencv:注意,目前只有这个版本支持VS2015,也就是平台工具集可以为vs140,其他的都会报错

OpenCV入门---VS2015安装OpenCV(Nuget安装)

3.测试代码

#include <opencv2/core.hpp>
#include <opencv2/imgcodecs.hpp>
#include <opencv2/highgui.hpp>
#include <iostream>
using namespace cv;
using namespace std;
int main( int argc, char** argv )
{
    if( argc != 2)
    {
     cout <<" Usage: display_image ImageToLoadAndDisplay" << endl;
     return -1;
    }
    Mat image;
    image = imread(argv[1], IMREAD_COLOR); // Read the file
    if( image.empty() ) // Check for invalid input
    {
        cout << "Could not open or find the image" << std::endl ;
        return -1;
    }
    namedWindow( "Display window", WINDOW_AUTOSIZE ); // Create a window for display.
    imshow( "Display window", image ); // Show our image inside it.
    waitKey(0); // Wait for a keystroke in the window
    return 0;
}

利用命令行进行安装

1.打开Power shell虚拟机

OpenCV入门---VS2015安装OpenCV(Nuget安装)

2.安装OpenCV

OpenCV入门---VS2015安装OpenCV(Nuget安装)

OpenCV入门---VS2015安装OpenCV(Nuget安装)

 

NuGet安装移除包均非常方便,对常见的指令可输入OpenCV入门---VS2015安装OpenCV(Nuget安装)

3.测试代码

#include <opencv2/core.hpp>
#include <opencv2/imgcodecs.hpp>
#include <opencv2/highgui.hpp>
#include <iostream>
using namespace cv;
using namespace std;
int main( int argc, char** argv )
{
    if( argc != 2)
    {
     cout <<" Usage: display_image ImageToLoadAndDisplay" << endl;
     return -1;
    }
    Mat image;
    image = imread(argv[1], IMREAD_COLOR); // Read the file
    if( image.empty() ) // Check for invalid input
    {
        cout << "Could not open or find the image" << std::endl ;
        return -1;
    }
    namedWindow( "Display window", WINDOW_AUTOSIZE ); // Create a window for display.
    imshow( "Display window", image ); // Show our image inside it.
    waitKey(0); // Wait for a keystroke in the window
    return 0;
}

实验效果

OpenCV入门---VS2015安装OpenCV(Nuget安装)

 

相关文章: