visual studio 2019 opencv配置

本文介绍了如何在Windows环境下配置OpenCV以供Microsoft Visual Studio 2019使用。配置分为全局(适用于所有项目)和局部(仅限当前项目)两种方式,关键在于设置编译器的包含目录和链接器的库目录。文章详细展示了局部配置的步骤,包括创建新的属性表以便复用,并提供了测试代码以验证配置是否成功。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

前提是installatioin in windows

stepone:

打开opencv官网—
tutorials--------
Introduction to Opencv-----
How to build application with opencv inside the “Microsoft visual Studio”
设置的方法总共有两种
1.globally (so all your projects will get this information)
2.locally(so only for the current project)

The key point has two layers:

  1. the compiler: to tell the compiler how the OpenCV library looks. You do this by showing the header files.
  2. the linker: to tell the linker from where to get the functions and implements of all used functions and data structrues to the executable file.

对于解决方案中每个项目的每种build mode(debug and Release)都可以单独设置。
放在括号中的任何以美元符号开头的内容都将在运行时替换为当前环境变量值

steotwo :下面的方式是locally

这是举一个例子新建一个win32 console application
在这里插入图片描述
在这里插入图片描述
窗口右边就会出现下图:
在这里插入图片描述
选中你想要的的build mode ,对齐属性进行设置,如下图,我选择debug x64
在这里插入图片描述
1.
在这里插入图片描述
2.the linker
在这里插入图片描述
3. The you need to specify the libraries in which the linker should look into.
在这里添加你想要的模块,对于以前的opencv是分开的,你自己选择想要那个module,就引入哪一个就好,opencv_(The Name of the module)(The version Number of the library you use)d.lib,但是对于现在的版本,都整合到同一个lib中了,所以
The letter d at the end just indictates that these are the libraries required for debug.
so for the Release build mode , make sure to omit d letters from the library name and to save the property sheets with the save icon abover them.
在这里插入图片描述

上面的这些设置可以新建一个属性表,操作上面的步骤,用于以后重复使用。

在这里插入图片描述

stepthree: forglobally(如果用了locally这一步就不用管了)

请参考官网

stepfour: 测试:

在这里插入图片描述
粘贴下面的代码:

#include <opencv2/core.hpp>
#include <opencv2/imgcodecs.hpp>
#include <opencv2/highgui.hpp>
#include <iostream>
using namespace cv;
using namespace std;
int main(int argc, char** argv)
{
    if (argc != 2)
    {
        cout << " Usage: " << argv[0] << " ImageToLoadAndDisplay" << endl;
        return -1;
    }
    Mat image;
    image = imread(argv[1], IMREAD_COLOR); // Read the file
    if (image.empty()) // Check for invalid input
    {
        cout << "Could not open or find the image" << std::endl;
        return -1;
    }
    namedWindow("Display window", WINDOW_AUTOSIZE); // Create a window for display.
    imshow("Display window", image); // Show our image inside it.
    waitKey(0); // Wait for a keystroke in the window
    return 0;
}

在这里插入图片描述
右击目标项目,点击生成
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值