opencv 图片清晰度检测

opencv 图片清晰度判断代码

读取D盘里面的两张图片,进行清晰度的判别。
阈值可以自行修改

#include 
#include 

using namespace std;
using namespace cv;

int main()
{
	Mat imageSource = imread("D:/1.jpg");
	Mat imageGrey;

	cvtColor(imageSource, imageGrey, CV_RGB2GRAY);
	Mat imageSobel;
	Sobel(imageGrey, imageSobel, CV_16U, 1, 1);

	//图像的平均灰度
	double meanValue = 0.0;
	meanValue = mean(imageSobel)[0];

	//double to string
	stringstream meanValueStream;
	string meanValueString;
	meanValueStream << meanValue;
	meanValueStream >> meanValueString;
	meanValueString = "Articulation(Sobel Method): " + meanValueString;
	putText(imageSource, meanValueString, Point(128, 128), CV_FONT_HERSHEY_COMPLEX, 4, Scalar(0, 255, 0), 3);
	namedWindow("Articulation", WINDOW_FREERATIO);
	imshow("Articulation", imageSource);




	Mat iimageSource = imread("D:/2.jpg");
	Mat iimageGrey;

	cvtColor(iimageSource, iimageGrey, CV_RGB2GRAY);
	Mat iimageSobel;
	Sobel(iimageGrey, iimageSobel, CV_16U, 1, 1);

	//图像的平均灰度
	double iimeanValue = 0.0;
	iimeanValue = mean(iimageSobel)[0];

	//double to string
	stringstream iimeanValueStream;
	string iimeanValueString;
	iimeanValueStream << iimeanValue;
	iimeanValueStream >> iimeanValueString;
	iimeanValueString = "iArticulation(Sobel Method): " + iimeanValueString;
	putText(iimageSource, iimeanValueString, Point(128, 128), CV_FONT_HERSHEY_COMPLEX, 4, Scalar(0, 255, 0), 3);
	//照片/添加的文字/左上角坐标/字体/字体大小/颜色/字体粗细
	namedWindow("iArticulation", WINDOW_FREERATIO);
	imshow("iArticulation", iimageSource);


	if (meanValue - 3> iimeanValue)
		printf("超出阈值");
	else
		printf("未超出阈值");
	waitKey();
}

运行结果

opencv 图片清晰度检测_第1张图片
opencv 图片清晰度检测_第2张图片
下面是我做的系统展示平台,有需要的可以下载
https://download.csdn.net/download/qq_46626270/18576814
opencv 图片清晰度检测_第3张图片

你可能感兴趣的:(经验分享)