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;
}

把这两个代码在VS中运行一遍,你会发现,Mat是一个矩阵,数字都是像素值。

PS.代码中图片位置要更改成你们自己的路径,运行完是不是豁然开朗,hhh

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值