win10+vs2019+opencv+opencv_conti
2019-06-17 本文已影响2人
离群土拨鼠
- 电脑:Dell vostro 3480
- 操作系统:win10
- 内存:8GB
- 显卡:英特尔 HD Graphics 620
- CPU: 英特尔 酷睿 i5-8265U
一、安装vs2019
访问网址:https://visualstudio.microsoft.com/zh-hans/vs/,下载vs2019社区版,并按需要进行安装

二、编译opencv及opencv_contrib
访问网址:https://github.com/opencv/,找到opencv 及opencv_contrib 点击蓝色标题,下载源码

将源码解压到同一文件夹下:

新建opencv_build文件夹用于编译

三、下载Cmake-3.15.0
访问网址:https://cmake.org/download/,找到对应的版本下载,这里下载的为win64-x64安装程序

按提示安装cmake,选择添加环境变量,最后点击完成。

打开CMake,找到Where is the soure code 位置。将解压后的opencv目录填入其中

将先前新建opencv_build目录填入Where to build the binaries中

然后点击左侧下方Configure。选择Visual Studio16 2019进行第一次编译

经过一段时间的等待,会发现变红了。不要慌,再点一次Configure

将OPENCV_EXTRA_MODULES_PATH路径填入,opencv_contirb-master/modules,点击Configure,如果遇到红色就再点一边Configure.将BUILD_opencv_world打勾。再点一遍Configure。

可能中间有一些文件无法下载,需要手动下载,如opencv_ffmpeg.dll、face_landmark_model.dat等。也可以网上下载别人下载好的。这里只附上face_landmark_model.dat的下载连接https://raw.githubusercontent.com/opencv/opencv_3rdparty/8afa57abc8229d611c4937165d20e2a2d9fc5a12/face_landmark_model.dat将下载后的face_landmark_model.dat放入下图位置,名称与原来的名称保持一致。并将face_landmark_model.dat复制到F:/opensources/opencv_build/testdata/cv/face//face_landmark_model.dat(没有这个目录就新建一个)

最后点击Generate

在opencv_build文件夹中找到opencv.sln

点击生成- >批量生成

然后可以睡觉了。。。。。(耗时很长)

编译完成后opencv_build文件夹下有install文件夹

四、配置
编译完成后进行环境变量的配置


新建一个控制台应用程序- >打开属性管理器- >添加新的项目属性表

包含目录:
F:\opensources\opencv-build\install\include\opencv2
F:\opensources\opencv-build\install\include

库目录:
F:\opensources\opencv-build\install\x64\vc16\lib

打开链接器- >输入- >附加依赖项,填入opencv_world410.lib

新建c++文件:右键点击源文件- >添加- >新建项

五、测试
- 测试代码:
#include "opencv2/opencv.hpp"
#include"opencv2/xfeatures2d.hpp"
using namespace cv;
using namespace std;
int main() {
Mat img = imread("F:\\opencv_C++\\hello\\3.png", 1);
Ptr<Feature2D> sift = xfeatures2d::SIFT::create();
vector<KeyPoint> keypoints;
Mat descriptors;
sift->detectAndCompute(img, noArray(), keypoints, descriptors);
drawKeypoints(img, keypoints, descriptors, Scalar(0, 255, 255));
imshow("Result", descriptors);
waitKey(0);
return 0;
}
-
测试图片:
3.png
-
测试结果