https://www.cnblogs.com/arkenstone/p/7900978.html
先对图像用拉普拉斯算子进行滤波,然后求取得到的结果图像的方差,如果方差小于一定值则图片视为模糊。利用python很好实现:
img2gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)# 将图片压缩为单通道的灰度图
score = cv2.Laplacian(img2gray, cv2.CV_64F).var()
C++实现如下:
boolisImageBlurry(cv::Mat& img)
{
cv::Mat matImageGray;
// converting image's color space (RGB) to grayscale cv::cvtColor(img, matImageGray, CV_BGR2GRAY);
cv::Mat dst, abs_dst;
cv::Laplacian(matImageGray, dst, CV_16S, 3);
cv::convertScaleAbs( dst, abs_dst );
cv::Mat tmp_m, tmp_sd;
doublem =0, sd =0;
intthreshold =1000;
cv::meanStdDev(dst, tmp_m, tmp_sd);
m = tmp_m.at(0,0);
sd = tmp_sd.at(0,0);
std::cout <<"StdDev: "<< sd * sd << std::endl;
return((sd * sd) <= threshold);
}