Opencv C++ 图片随机赋值 显示矩阵

Opencv C++ 图片随机赋值 显示矩阵

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

using namespace cv;
using namespace std;

int main()
{
	//1.创建图片
	Mat imgRandu = Mat(200, 200, CV_8UC3);
	
	//2.图片随机赋值 0-255
	randu(imgRandu, Scalar::all(0), Scalar::all(255));

	//3.显示随机图片
	imshow("imgRandu", imgRandu);

	//4.创建矩阵显示用数组
	Mat r = Mat(10, 3, CV_8UC3);
	randu(r, Scalar::all(0), Scalar::all(255));

	//5.不同格式输出
	cout << "R 矩阵输出(默认格式)= " << endl << r <<endl;

	cout << "R 矩阵输出(Python)= " << endl <<format(r, Formatter::FMT_PYTHON)<< endl;

	cout << "R 矩阵输出(Numpy)= " << endl << format(r, Formatter::FMT_NUMPY) << endl;

	waitKey(0);
	destroyAllWindows();
}

在这里插入图片描述

函数说明

void cv::randu	(	
InputOutputArray 	dst,	//输入输出图片
InputArray 	low,			//随机最小值 数组 包含
InputArray 	high 			//随机最大值 数组 不包含
)	

在这里插入图片描述

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章