OpenCV1-VS2022+OpenCV环境配置


1.VS、Image Watch、FastStone Image Viewer、OpenCV

1.安装VS2022

2.安装看图拓展:Image Watch for Visual Studio 2022

3.安装图像对比软件 FastStone Image Viewer

4.OpenCV官网下载:opencv.org/release

2.VS2022配置OpenCV环境

配置:

1.添加环境变量D:\ThirdLib\opencv\build\x64\vc16\bin

2.添加包含目录:

D:\ThirdLib\opencv\build\include\opencv2

D:\ThirdLib\opencv\build\include\

3.添加库目录:

D:\ThirdLib\opencv\build\x64\vc16\lib

4.添加附加依赖项:库目录下的文件

如果是Release版本:opencv_world480.lib

如果是Debug版本:opencv_world480d.lib

get-started 测试程序:

#include <opencv2/core.hpp>
#include <opencv2/highgui.hpp>

using namespace cv;

int main()
{
	std::string image_path = "path/to/image";
	Mat img = imread(image_path, IMREAD_COLOR);

	imshow("Display window", img);
	int k = waitKey(0); // Wait for a keystroke in the window
	return 0;
}

3.Debug模式下日志的关闭

如果实在Debug模式下,则会输出大量日志信息,使用以下代码可以关闭日志的输出:

// 包含头文件
#include <opencv2/core/utils/logger.hpp>

// main函数中
cv::utils::logging::setLogLevel(utils::logging::LOG_LEVEL_SILENT);
#include <opencv2/core.hpp>
#include <opencv2/highgui.hpp>
#include <opencv2/core/utils/logger.hpp>

using namespace cv;
using namespace std;

int main()
{
	cout << "OpenCV Version: " << CV_VERSION << endl;
	utils::logging::setLogLevel(utils::logging::LOG_LEVEL_SILENT);

	// jpg图片
	string image_path = "morty.jpg";
	Mat img_jpg = imread(image_path, IMREAD_UNCHANGED);
	if (img_jpg.empty())
	{
		cout << "Input image is null!" << endl;
		return 0;
	}
	imshow(image_path, img_jpg);
	cout << "Channel nmuber: " << img_jpg.channels() << endl;
	cout << "Size: " << img_jpg.size << endl;

	// png图片
	image_path = "skinner.png";
	Mat img_png = imread(image_path, IMREAD_UNCHANGED);
	if (img_png.empty())
	{
		cout << "Input image is null!" << endl;
		return 0;
	}
	imshow(image_path, img_png);
	cout << "Channel nmuber: " << img_png.channels() << endl;
	cout << "Size: " << img_png.size() << endl;

	int k = waitKey(0); // Wait for a keystroke in the window
	return 0;
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
为了在 Visual Studio 2022配置 OpenCV 环境,你可以按照以下步骤进行操作: 1. 下载 OpenCV 库文件: - 访问 OpenCV 官方网站(https://opencv.org/releases/)下载最新版本的 OpenCV 库文件。 - 根据你的操作系统选择适当的版本,下载并解压缩到一个目录中。 2. 创建 Visual Studio 项目: - 打开 Visual Studio 2022,创建一个新的空白项目或打开现有项目。 3. 配置项目属性: - 右键单击项目名称,选择“属性”选项。 - 在属性窗口中,选择“VC++目录”选项卡。 - 在“包含目录”字段中,添加包含 OpenCV 头文件的路径,例如:`<OpenCV_Directory>\include`。 - 在“库目录”字段中,添加包含 OpenCV 库文件的路径,例如:`<OpenCV_Directory>\lib`。 - 在“链接器->输入->附加依赖项”字段中,添加以下库文件: `opencv_world<version>.lib`(例如:opencv_world452.lib) - 点击“应用”和“确定”保存更改。 4. 配置运行时环境: - 将 OpenCV 的 DLL 文件复制到你的项目的输出目录(通常是 Debug 或 Release 文件夹)。 - 在运行时,确保将这些 DLL 文件放置在可执行文件所在的目录中。 5. 测试配置: - 在你的代码中包含 OpenCV 头文件,例如:`#include <opencv2/opencv.hpp>`。 - 编写一些测试代码来验证你的配置是否成功。 这些步骤应该能帮助你在 Visual Studio 2022配置 OpenCV 环境。如果你遇到任何问题,请确保按照以上步骤进行操作,并在需要时参考 OpenCV 官方文档或社区支持。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

shlyyy

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值