安装VS2017
- 在微软官网https://www.microsoft.com,下载Visual Studio 2017安装包
- 用管理员权限运行vs2017 enterprise安装包,安装过程会持续1~2个小时。
- 注册激活:
- Enterprise: NJVYC-BMHX2-G77MM-4XJMR-6Q8QF
- Professional:
KBJFW-NXHK6-W4WJM-CRMQB-G3CDH - 测试安装结果:启动VS2017,新建工程,并编译运行。
安装OpenCV3.4
- 在github官方仓库https://github.com/opencv/opencv/releases,下载OpenCV3.4.2
- 安装(解压)到C:\
- 配置OpenCV环境变量:
- 右键Computer -> Properties -> Advanced system settings -> Environment variables
- System variables -> New -> 输入OPENCV和目录C:\opencv\build
- System variables -> Path -> 添加%OPENCV%\x64\vc15\bin;
配置VS2017工程+案例测试
- 新建工程取名test
- 配置OpenCV库,View -> Other Window -> Property Manager,选中Debug|x64 -> Microsoft.Cpp.x64.user -> Properties
- VC++ Directories -> Include Directories -> 添加C:\opencv\build\include
- VC++ Directories -> Library Directories -> 添加C:\opencv\build\x64\vc15\lib
- Linker -> Input -> Additional Dependencies -> 添加opencv_world342d.lib
- 编辑代码
#include<iostream> #include <opencv2/opencv.hpp> using namespace cv; int main() { Mat img = imread("test_image.jpg"); // 读入一张图片,图片与test.cpp同一目录 namedWindow("test_image", cv::WINDOW_NORMAL); // 创建一个名为 "test_image" 的窗口 imshow("test_image", img); // 在窗口中显示 waitKey(); return 0; }
- 编译运行,提示an error has occurred in the script on this page expected identifier string or number,解决办法:
- Debug -> Debugging -> General -> 取消Enable Diagnostic Tools while debugging -> OK保存
- 重启VS2017,已解决
原文地址:https://www.cnblogs.com/xbit/p/9328066.html
时间: 2024-10-10 05:01:10