图像像素类型转换与归一化
#include<iostream>
#include<opencv2/opencv.hpp>
using namespace std;
using namespace cv;
void norm_demo(cv::Mat& image)
{
Mat dst;
cout <<"原类型:" << image.type() << endl;
image.convertTo(image, CV_32F);
cout<<"转换后类型:" << dst.type() << endl;
normalize(image, dst, 1.0, 0, NORM_MINMAX);
cout <<"归一化后:" << dst.type() << endl;
imshow("图像像素归一化", dst);
}
int main()
{
string path = "C:\Users\四明\Pictures\QQ图片20200608155343.jpg";
Mat img = imread(path,IMREAD_ANYCOLOR);
if (img.empty())
{
cout << "无法加载图片" << endl;
return -1;
}
namedWindow("image", WINDOW_FREERATIO);
imshow("image", img);
norm_demo(img);
waitKey(0);
destroyAllWindows();
return 0;
}