Visual Studio 配置OpenCV C++版

OpenCV+Visual Studio 2022的C++学习路线

一、VS配置

1. OpenCV下载

2. 安装

在这里插入图片描述

  1. 我解压到了D盘,你们随意
  2. 添加环境变量:在这里插入图片描述

二、创建项目

  1. 新建c++控制台项目在这里插入图片描述

  2. 创建项目在这里插入图片描述

  3. 配置项目包目录在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述

  4. 同理,自己配置一下库目录在这里插入图片描述

  5. 配置链接器,直接输入即可(opencv_world412d.lib在这里插入图片描述

运行

#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc.hpp>
#include <iostream>

using namespace cv;
using namespace std;

int main()
{
    Mat image = Mat::zeros(300,300, CV_8UC3);
    circle(image, Point(150, 150), 100, Scalar(0, 255, 0), -100);
    circle(image, Point(150, 150), 50, Scalar(0, 0, 255), -100);
    imshow("circle", image);
    waitKey(0);
    return 0;
}

运行效果
在这里插入图片描述

  • 1
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
Visual Studio配置 OpenCV 可以分为以下几个步骤: 1. 下载安装 OpenCV 库 首先需要从 OpenCV 官网下载适用于你的操作系统的 OpenCV 库,下载后进行安装。 2. 新建一个空的 Visual Studio 项目 在 Visual Studio 中,选择菜单 File -> New -> Project,然后选择 Visual C++ -> Empty Project,命名为 OpenCVProject。 3. 配置项目属性 在 Solution Explorer 中右键点击项目,选择 Properties。在左侧选择 Configuration Properties -> VC++ Directories,然后在右侧的 Include Directories 中加入 OpenCV 的 include 目录,如:`C:\opencv\build\include`。 接着,在左侧选择 Configuration Properties -> Linker -> General,然后在右侧的 Additional Library Directories 中加入 OpenCV 的 lib 目录,如:`C:\opencv\build\x64\vc15\lib`。 然后,在左侧选择 Configuration Properties -> Linker -> Input,然后在右侧的 Additional Dependencies 中加入需要连接的 OpenCV 库名字,如:`opencv_world420.lib`。 4. 编写代码 在项目中添加一个 C++ 源文件,如 main.cpp,然后在其中添加 OpenCV 的头文件和代码,例如: ```cpp #include <opencv2/opencv.hpp> using namespace cv; int main() { // 读取图像 Mat img = imread("image.jpg", IMREAD_COLOR); // 显示图像 namedWindow("Display window", WINDOW_AUTOSIZE); imshow("Display window", img); waitKey(0); return 0; } ``` 5. 编译和运行 在 Visual Studio 中,选择菜单 Build -> Build Solution 编译整个项目,然后选择菜单 Debug -> Start Without Debugging 运行程序。如果一切正常,就应该可以看到加载的图像窗口弹出。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值