opencv中Mat究竟是什么?

opencv中Mat究竟是什么?

首先看opencv是怎么显示一张图的 :

//#include "stdafx.h"

#include <opencv2/opencv.hpp>

#include <iostream>
#include <string>

using namespace cv;
using namespace std;

int main(int argc, char** argv)
{
	// Read the image file
	Mat image1 = imread("hero.jpg");//注意,图片需要在绝对路径

	if (image1.empty()) // Check for failure
	{
		cout << "Could not open or find the image" << endl;
		system("pause"); //wait for any key press
		return -1;
	}
	//Mat image1 (10,30,CV_8UC3,Scalar(155,175,131));//画一个高10 宽30的窗口,8*3bit的3通道图像,Scalar是定义颜色的函数;

	//cout << "image1 = " << endl << " " << image1 << endl << endl;//同时输出Mat所代表的矩阵
	String windowName1 = "My HelloWorld Window"; //Name of the window
	
	namedWindow(windowName1); // Create a window

	imshow(windowName1, image1); // Show our image inside the created window.

	waitKey(0); // Wait for any keystroke in the window

	destroyWindow(windowName1); //destroy the created window

	return 0;
}

以下是重点,代码就改了一点点:

//#include "stdafx.h"

#include <opencv2/opencv.hpp>

#include <iostream>
#include <string>

using namespace cv;
using namespace std;

int main(int argc, char** argv)
{
	// Read the image file
	//Mat image1 = imread("hero.jpg");//注意,图片需要在绝对路径

	//if (image1.empty()) // Check for failure
	//{
	//	cout << "Could not open or find the image" << endl;
	//	system("pause"); //wait for any key press
	//	return -1;
	//}
	Mat image1 (10,30,CV_8UC3,Scalar(155,175,131));//画一个高10 宽30的窗口,8*3bit的3通道图像,Scalar是定义颜色的函数;

	cout << "image1 = " << endl << " " << image1 << endl << endl;//同时输出Mat所代表的矩阵
	String windowName1 = "My HelloWorld Window"; //Name of the window
	
	namedWindow(windowName1); // Create a window

	imshow(windowName1, image1); // Show our image inside the created window.

	waitKey(0); // Wait for any keystroke in the window

	destroyWindow(windowName1); //destroy the created window

	return 0;
}

是不是豁然开朗,hh

上一篇:opencv学习04图像的平移


下一篇:Python实训day7