OpenCV1-VS2022+OpenCV环境配置

OpenCV学习1-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 测试程序:

cpp 复制代码
#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模式下,则会输出大量日志信息,使用以下代码可以关闭日志的输出:

cpp 复制代码
// 包含头文件
#include <opencv2/core/utils/logger.hpp>

// main函数中
cv::utils::logging::setLogLevel(utils::logging::LOG_LEVEL_SILENT);
cpp 复制代码
#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;
}
相关推荐
zzzsde1 分钟前
【C++】stack和queue:使用&&OJ题&&模拟实现
开发语言·c++
m0_7482336413 分钟前
C++与Python:内存管理与指针的对比
java·c++·python
孤廖14 分钟前
面试官问 Linux 编译调试?gcc 编译流程 + gdb 断点调试 + git 版本控制,连 Makefile 都标好了
linux·服务器·c++·人工智能·git·算法·github
终焉代码21 分钟前
【Linux】进程初阶(1)——基本进程理解
linux·运维·服务器·c++·学习·1024程序员节
我想吃余21 分钟前
Linux进程间通信:管道与System V IPC的全解析
linux·服务器·c++
紫荆鱼22 分钟前
设计模式-备忘录模式(Memento)
c++·后端·设计模式·备忘录模式
深度学习lover30 分钟前
<数据集>yolo煤矿安全帽识别数据集<目标检测>
人工智能·python·深度学习·yolo·目标检测·计算机视觉·煤矿安全帽识别
Wind哥32 分钟前
VS Code搭建C/C++开发调试环境-Windows
c语言·开发语言·c++·visual studio code
B站_计算机毕业设计之家1 小时前
计算机视觉:python车牌识别检测系统 YOLOv8 深度学习pytorch技术 LPRNet车牌识别算法 CCPD2020数据集 ✅
大数据·python·深度学习·机器学习·计算机视觉·数据分析·车牌识别
Skrrapper1 小时前
【C++】C++ 中的 map
开发语言·c++