opencv Mat CV_32FC1格式数据以灰度图形式显示出来

#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include 
#include 
 
using namespace std;
using namespace cv;

//用二维数组初始化opencv Mat 
void InitMat(Mat& m,float(*p)[255])
{
 for(int i=0;i(i,j)=*(*(p+i)+j);
}
 
int main()
{
	float a[255][255] = {0};
	for(int i = 0; i < 255; i++)
	{
		//0cout << "第 " << i << "行  " << endl;
		for(int j = 0; j < 255; j++)
		{
			a[i][j] = j+255;
			//cout << a[i][j];
		}
		//cout << endl;
	}
	//Mat temp(255, 255, CV_8UC1, a);
	Mat temp(255,255,CV_32FC1);
	InitMat(temp,a);
	Mat B;
//获取Mat temp中元素的最大值与最小值
	double minv = 0.0, maxv = 0.0;
	double* minp = &minv;
	double* maxp = &maxv;
	minMaxIdx(temp,minp,maxp);

	cout << "Mat minv = " << minv << endl;
	cout << "Mat maxv = " << maxv << endl;
	temp.convertTo(B, CV_8U, 255.0/(maxv-minv));//映射到0-255
	imshow("a", B);
	cout << "temp" << temp << endl;
	waitKey();
	return 0;
}

 

你可能感兴趣的:(C++,Opencv)