opencv 3.4.0+opencv_contrib+CMake+VS 2017+Win10

opencv 3.4.0+opencv_contrib+CMake+VS 2013+Win10

文章目录

  • opencv 3.4.0+opencv_contrib+CMake+VS 2013+Win10
    • 1.下载
    • 2.编译
    • 3.配置
    • 4.测试
    • 5.参考

1.下载

opencv 3.4.0:https://sourceforge.net/projects/opencvlibrary/files/opencv-win/3.4.0/opencv-3.4.0-vc14_vc15.exe/download

opencv_contrib 3.4.0:https://github.com/opencv/opencv_contrib/tree/3.4.0

CMake(.msi安装包):https://cmake.org/download/

opencv3.4以上应该必须用VS2015以上才行,本人用2013频频报错,用2017没问题

2.编译

①opencv 3.4.0解压在无中文路径下

②opencv_contrib解压在opencv/sources/modules下
opencv 3.4.0+opencv_contrib+CMake+VS 2017+Win10_第1张图片
③安装CMake,安装过程把添加Path到环境变量勾上

④运行CMake自行build opencv,注意CMake的路径和资源管理器的路径格式(斜杠)不同
opencv 3.4.0+opencv_contrib+CMake+VS 2017+Win10_第2张图片
⑤点击Configure,根据VS版本和系统位数进行选择
opencv 3.4.0+opencv_contrib+CMake+VS 2017+Win10_第3张图片

这一步配置过程可能出现很多问题,其中会访问外网下载几个文件,网速慢或没VPN的话则会报错,不要担心。

解决办法如下:
根据报错提示在资源管理器搜索那文件→百度下载该文件→改成搜索到的文件同名覆盖→重新Configure

第一次Configure呈红色,再Configure一次变成白色就好

opencv 3.4.0+opencv_contrib+CMake+VS 2017+Win10_第4张图片

⑥配置OPENCV_EXTRA_MODULES_PATH成opencv_contrib的modules文件夹后点Generate
opencv 3.4.0+opencv_contrib+CMake+VS 2017+Win10_第5张图片

⑦点Open Project或打开newbuild中的OpenCV.sln
opencv 3.4.0+opencv_contrib+CMake+VS 2017+Win10_第6张图片

opencv 3.4.0+opencv_contrib+CMake+VS 2017+Win10_第7张图片

⑧右键解决方案→重新生成解决方案

opencv 3.4.0+opencv_contrib+CMake+VS 2017+Win10_第8张图片

⑦右键INSTALL→仅用于项目→仅生成INSTALL
opencv 3.4.0+opencv_contrib+CMake+VS 2017+Win10_第9张图片

3.配置

①新建空项目
opencv 3.4.0+opencv_contrib+CMake+VS 2017+Win10_第10张图片

②打开属性管理器
opencv 3.4.0+opencv_contrib+CMake+VS 2017+Win10_第11张图片

③右键Debug | x64→Microsoft.Cpp.x64.user→属性
opencv 3.4.0+opencv_contrib+CMake+VS 2017+Win10_第12张图片

④可执行目录

\newbuild\install\x64\vc15\bin

opencv 3.4.0+opencv_contrib+CMake+VS 2017+Win10_第13张图片

⑤包含目录

\newbuild\install\include
\newbuild\install\include\opencv
\newbuild\install\include\opencv2

opencv 3.4.0+opencv_contrib+CMake+VS 2017+Win10_第14张图片

⑥库目录

\newbuild\install\x64\vc15\lib

opencv 3.4.0+opencv_contrib+CMake+VS 2017+Win10_第15张图片

⑦附加依赖项

opencv_aruco340d.lib
opencv_bgsegm340d.lib
opencv_bioinspired340d.lib
opencv_calib3d340d.lib
opencv_ccalib340d.lib
opencv_core340d.lib
opencv_datasets340d.lib
opencv_dnn340d.lib
opencv_dpm340d.lib
opencv_face340d.lib
opencv_features2d340d.lib
opencv_flann340d.lib
opencv_fuzzy340d.lib
opencv_highgui340d.lib
opencv_img_hash340d.lib
opencv_imgcodecs340d.lib
opencv_imgproc340d.lib
opencv_line_descriptor340d.lib
opencv_ml340d.lib
opencv_objdetect340d.lib
opencv_optflow340d.lib
opencv_phase_unwrapping340d.lib
opencv_photo340d.lib
opencv_plot340d.lib
opencv_reg340d.lib
opencv_rgbd340d.lib
opencv_saliency340d.lib
opencv_shape340d.lib
opencv_stereo340d.lib
opencv_stitching340d.lib
opencv_structured_light340d.lib
opencv_superres340d.lib
opencv_surface_matching340d.lib
opencv_text340d.lib
opencv_tracking340d.lib
opencv_video340d.lib
opencv_videoio340d.lib
opencv_videostab340d.lib
opencv_xfeatures2d340d.lib
opencv_ximgproc340d.lib
opencv_xobjdetect340d.lib
opencv_xphoto340d.lib

opencv 3.4.0+opencv_contrib+CMake+VS 2017+Win10_第16张图片

⑧环境变量

\newbuild\install\x64\vc15\bin

opencv 3.4.0+opencv_contrib+CMake+VS 2017+Win10_第17张图片

PS:运行项目时要将Debug解决方案平台调为x64(没有的话就在配置管理器中新建)
opencv 3.4.0+opencv_contrib+CMake+VS 2017+Win10_第18张图片

4.测试

#include 
#include 
#include "opencv2/xfeatures2d.hpp"
#include "opencv2/highgui.hpp"

using namespace cv;
using namespace cv::xfeatures2d;
using namespace std;

int main()
{
	Mat img = imread("JUST SMASH.jpg");
	Mat gray = imread("JUST SMASH.jpg", IMREAD_GRAYSCALE);
	if (img.empty())
	{
		printf("could not load image...\n");
		return -1;
	}
	namedWindow("原图", CV_WINDOW_AUTOSIZE);
	imshow("原图", img);

	int minHessian = 400;
	Ptr detector = SURF::create(minHessian);
	vector keypoints;
	detector->detect(gray, keypoints);

	Mat img_keypoints;
	drawKeypoints(gray, keypoints, img_keypoints, Scalar::all(-1), DrawMatchesFlags::DEFAULT);
	namedWindow("效果", CV_WINDOW_AUTOSIZE);
	imshow("效果", img_keypoints);

	waitKey(0);
	return 0;
}

opencv 3.4.0+opencv_contrib+CMake+VS 2017+Win10_第19张图片

5.参考

1.OpenCV学习笔记(六)——配置扩展模块 - 行歌 - CSDN博客 https://blog.csdn.net/weixin_41695564/article/details/79925379#commentBox

2.OpenCV contrib 3.2.0扩展模块添加与编译(VS2017+OpenCV3.2.0)详解与排坑 - weixin_37800680的博客 - CSDN博客 https://blog.csdn.net/weixin_37800680/article/details/72566294

你可能感兴趣的:(C++)