OpenCV——图像显示与写入

1、图像显示与写入的代码如下:

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

using namespace cv;
using namespace std;
//opencv中图像显示与写入
int main()
{
	Mat myMat = imread("小狗1.jpg", -1);

	if (myMat.empty()) {
		throw runtime_error("The image is empty");  // If the image is empty, throw error.
		return -1;
	}
	namedWindow("显示图像", WINDOW_AUTOSIZE);
	imshow("显示图像", myMat);
	imwrite("小狗2.jpg", myMat);
	waitKey(0);
	destroyAllWindows();
}

2、最终效果如下:


3、程序目录下写入了一张名称为“小狗2”的图片。


猜你喜欢

转载自blog.csdn.net/ywxk1314/article/details/80054659