admin管理员组

文章数量:1530518

一、Visual Studio 2019(VS2019)安装

​ Microsoft Visual Studio(简称VS)是美国微软公司的开发工具包系列产品。VS是一个基本完整的开发工具集,它包括了整个软件生命周期中所需要的大部分工具,如UML工具、代码管控工具、集成开发环境(IDE)等等。所写的目标代码适用于微软支持的所有平台,包括Microsoft Windows、Windows Mobile、Windows CE、.NET Framework、.NET Compact Framework和Microsoft Silverlight 及Windows Phone。
​ Visual Studio是最流行的Windows平台应用程序的集成开发环境。最新版本为 Visual Studio 2019 版本,基于.NET Framework 4.8 。
​ 2018年6月,微软宣布开发新一代集成开发环境(integrated development environment,IDE)Visual Studio 2019。
​ 2019年2月15日,微软敲定了Visual Studio 2019正式版的首发时间,2019年4月2日(北京时间4月3日凌晨1点。
​ Visual Studio 2019已经发布了四个公开预览版,分别是2018年12月的Preview 1、2019年1月的Preview 2。2月13日推出的Preview 3 和3月1日刚推出的Preview 4。

1.下载链接:VS官方网站
2.下载版本,下载Community2019版本的(个人版)

3.VS2019相关配置
如果你只是单纯的想用VS2019写C++代码,选择C++的桌面开发即可‘

4.提醒:位置我们一般情况是选择默认的位置,随后点击安装即可!

5.安装完成进入界面

可能有小伙伴会弹出需要你登录界面,这里我们直接注册一个Microsoft账号就可以了,注册是免费的哟!如果你不登录Microsoft账号的话你只能试用30天,登录了Microsoft账号就可以永久使用啦!That’s because it’s free!

二、安装Boost C++、NumCpp、Eigen 和opencv4.3.0库

Numcpp是依赖另外一个库文件的即Boost C++,因此需要先安装这个库文件。

安装Boost C++

1.下载链接:Boost C++官方网站

2.解压完后,你会看到你的目录下有bootstrap.bat批处理文件,双击执行


运行完成后,会在目录下得到b2.exe文件。

3.再执行b2.exe文件,运行会比较长久。


运行完成后,在stage/lib/目录下会产生很多lib文件。

4.再执行b2.exe install --prefix=D:/Boost

在VS2019中的配置,后面统一进行配置!!!

安装NumCpp

1.下载链接:NUmCPP

2.先创建build文件夹

3.以管理员身份打开cmd

在cmd中分别执行以下命令,第一句定位到build文件下

>> cd /d D:\NumCpp-master\build
>> cmake ..
>> cmake --build . --target install

运行过程中,能够看到安装目录,即C:\Program Files (x86)\NumCpp

安装Eigen

Eigen也是比较常用的库,也安装一下。

1.下载链接:Eigen官网


2.解压后的文件

安装opencv4.3.0

1.下载链接:Releases - OpenCV

2.下载完压缩包名:opencv-4.3.0-vc14_vc15.exe
解压完文件名:opencv

三、在VS2019中,配置Boost C++、NumCpp、Eigen 和opencv4.3.0库环境
Opencv的环境变量与添加dll文件到System32中

【1】找到我的电脑图标(或者是此电脑),右击。选择属性。
【2】选择高级系统设置,找到环境变量。

【3】找到系统变量一栏,双击“path”

【4】点击新建。输入你的安装路径,需要到bin这个文件。

D:\opencv\build\x64\vc15\bin

下面为环境变量的添加。

【5】添加dll文件到System32中。

这个路径的来源如下图,当你一层层点击,直到bin这个文件打开,呈现的一般是类似于下图的样子。这个时候再复制路径到上面的环境变量的添加中。

在路径下找到3个应用程序扩展文件,分别为

opencv_videoio_ffmpeg430_64.dll
opencv_world430.dll
opencv_world430d.dll

将opencv_world430.dll、opencv_videoio_ffmpeg430_64.dll和opencv_world430d.dll复制到下面的目录

C:\Windows\System32

在VS2019中,配置Boost C++、NumCpp、Eigen 和opencv4.3.0库环境

1.新建项目


创建完成。

2.进入属性设置。

进入项目属性页。在右侧解决方案一栏中点击刚才创建好的项目名,然后右击,选择属性。可以得到如下图的界面。

建议选择Release模式和平台x64

3.包含目录,库目录,附加依赖项的配置

配置包含目录下路径

点击新建以下目录

包含目录下添加

D:\opencv\build\include
D:\opencv\build\include\opencv2
D:\boost_1_77_0\boost_1_77_0
D:\eigen-3.4.0\eigen-3.4.0
C:\Program Files (x86)\NumCpp\include

库目录添加:
需要自己安装的目录

D:\opencv\build\x64\vc15\lib
D:\boost_1_77_0\boost_1_77_0\stage\lib

添加附加依赖项
链接器->输入->附加依赖项,点击右侧的下拉箭头进行编辑,添加:

opencv_world430.lib

配置完成!!!

四、测试
// NumCpp测试
#include "NumCpp.hpp"
#include <Eigen/Dense>
#include <iostream>

typedef Eigen::Matrix<int, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor> EigenIntMatrix;
typedef Eigen::Map<EigenIntMatrix> EigenIntMatrixMap;

int main()
{
    // construct some NumCpp arrays
    auto ncA = nc::random::randInt<int>({ 5, 5 }, 0, 10);
    auto ncB = nc::random::randInt<int>({ 5, 5 }, 0, 10);

    std::cout << "ncA:\n" << ncA << std::endl;
    std::cout << "ncB:\n" << ncB << std::endl;

    // map the arrays to Eigen 
    auto eigenA = EigenIntMatrixMap(ncA.data(), ncA.numRows(), ncA.numCols());
    auto eigenB = EigenIntMatrixMap(ncB.data(), ncB.numRows(), ncB.numCols());

    // add the two Eigen matrices
    auto eigenC = eigenA + eigenB;

    // add the two NumCpp arrays for a sanity check
    auto ncC = ncA + ncB;

    // convert the Eigen result back to NumCpp
    int* dataPtr = new int[eigenC.rows() * eigenC.cols()];
    EigenIntMatrixMap(dataPtr, eigenC.rows(), eigenC.cols()) = eigenC;

    constexpr bool takeOwnership = true;
    auto ncCeigen = nc::NdArray<int>(dataPtr, eigenC.rows(), eigenC.cols(), takeOwnership);

    // compare the two outputs
    if (nc::array_equal(ncC, ncCeigen))
    {
        std::cout << "Arrays are equal." << std::endl;
        std::cout << ncC << std::endl;
    }
    else
    {
        std::cout << "Arrays are not equal." << std::endl;
        std::cout << "ncCeigen:\n" << ncCeigen << std::endl;
        std::cout << "ncC:\n" << ncC << std::endl;
    }

    return 0;
}

// opencv测试
#include <iostream>
#include<opencv2/opencv.hpp>
#include <opencv2/highgui/highgui.hpp>//Opencv highgui 模块头文件
#include<opencv2/imgproc/imgproc.hpp>//图像处理头文件
using namespace cv;

int main() {
	//功能二:图像模糊
	Mat srcImage = imread("C:\\Users\\67231\\Pictures\\03.jpg");//需要自己设置路径,注意使用\\

	imshow("均值滤波原始图", srcImage);

	Mat dstImage;
	blur(srcImage, dstImage, Size(7, 7));

	imshow("均值滤波效果图", dstImage);

	waitKey(0);
}


参考网站:
https://blog.csdn/Airaybaiju/article/details/79446864
https://blog.csdn/shizheng_Li/article/details/102467938
https://blog.csdn/weixin_49643423/article/details/107873833
https://blog.csdn/weixin_42398658/article/details/112527065
https://blog.csdn/weixin_49643423/article/details/107873839
https://dpilger26.github.io/NumCpp/doxygen/html/_interface_with_eigen_8cpp-example.html

本文标签: 环境NumCppboostEigen