一、获取图像宽、高、通道数
代码如下:
int w = src.cols;
int h = src.rows;
int ch = src.channels();
std::cout << "width" << w <<std::endl<< "height" << h << std::endl << "channel" << ch << std::endl;
二、获取图像均值与方差
mean(输入)获取图像均值,类型为Scalar,三通道与单通道均可获取
meanStdDev(输入,均值,方差)获取图像均值与方差,三通道与单通道均可获取
代码如下:
Scalar s=mean(src);//获取图像均值
cout.setf(ios::fixed);
std::cout << "mean_b:" << setprecision(2) << s[0] << std::endl;
std::cout << "mean_g:" << setprecision(2) << s[1] << std::endl;
std::cout << "mean_r:" << setprecision(2) << s[2] << std::endl;
Mat mm ,mstd;
meanStdDev(src, mm, mstd);//获取图像方差
int rows = mstd.rows;
std::cout << &#