Display pictures and save pictures - OpenCV

Preface 

Study notes, learn OpenCV, from simple to deep.

Background introduction

OpenCV is a cross-platform computer vision and machine learning software library released under the Apache2.0 license (open source) and can run on Linux , Windows , Android and Mac OS operating systems. [1]   It is lightweight and efficient - it consists of a series of C functions and a small number  of C++  classes. It also provides interfaces in Python, Ruby, MATLAB and other languages, and implements many common algorithms in image processing and computer vision.

Installation and environment configuration

Reference blog VisualStudio2019 configuration OpenCV4.1.0_Rustone's blog-CSDN blog

Code and description

#include<iostream>
#include<opencv2/opencv.hpp>
using namespace std;
using namespace cv;

int  main()
{
	//创建窗口 重置窗口大小
	namedWindow("WindowName", WINDOW_NORMAL);
	resizeWindow("WindowName", 500, 312);
	//imshow("WindowName", 0);  //显示窗口 空白

	//读取图片 ,可将此图片显示到上面窗口里
	Mat srcImg = imread("C:/Users/yxp/Desktop/747196.png");
	if (srcImg.empty()) {
		cout << "could not load image..." << endl;
		return -1;
	}
	imshow("WindowName", srcImg);


	//保存图片
	imwrite("./out.png", srcImg);

	//显示灰度图片
	Mat Gray;
	cvtColor(srcImg, Gray, ColorConversionCodes::COLOR_BGR2GRAY);
	namedWindow("Gray", WINDOW_NORMAL);
	resizeWindow("Gray", 500, 312);
	imshow("Gray", Gray);

	//键盘 q键 销毁界面
	int key=waitKey(0);
	if(key=='q')
		destroyAllWindows();

	return 0;
}

renderings

 

Conclusion

Today is a day to say Hi to OpenCV!

Guess you like

Origin blog.csdn.net/xiaopei_yan/article/details/129442366