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 			//隨機最大值 數組 不包含
)	

在這裏插入圖片描述

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