OpenCV读取pgm文件并显示


#include 
#include 

using namespace std;
using namespace cv;

void main()
{
	Mat img = imread("C:\\Users\\Win10\\Downloads\\rasterImg.pgm", 0); 

	if (empty(img))
	{
		cout<<"NULL";
		return;
	}

	normalize(img, img, 0, 255, NORM_MINMAX);
	imshow("Image window",img);
	waitKey(0);
}

第2种方法:

#include 
#include 

using namespace std;
using namespace cv;

void main()
{
	Mat img = imread("C:\\Users\\Win10\\Downloads\\rasterImg.pgm", IMREAD_UNCHANGED);

	if (empty(img))
	{
		cout<<"NULL";
		return;
	}

	normalize(img, img, 0, 255, NORM_MINMAX);
	img.convertTo(img, CV_8U);
	imshow("Image window",img);
	waitKey(0);
}

不进行标准化:

#include 
#include 

using namespace std;
using namespace cv;

void main()
{
	Mat img = imread("C:\\Users\\Win10\\Downloads\\rasterImg.pgm", IMREAD_UNCHANGED);

	if (empty(img))
	{
		cout<<"NULL";
		return;
	}

	img.convertTo(img, CV_8U);
	imshow("Image window",img);
	waitKey(0);
}

 

你可能感兴趣的:(opencv)