opencv 进行图像的花屏检测(模糊检测)
参考:
https://www.pyimagesearch.com/2015/09/07/blur-detection-with-opencv/
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++实现如下:
bool isImageBlurry(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; double m = 0, sd = 0; int threshold = 1000; cv::meanStdDev(dst, tmp_m, tmp_sd); m = tmp_m.at<double>(0,0); sd = tmp_sd.at<double>(0,0); std::cout << "StdDev: " << sd * sd << std::endl; return ((sd * sd) <= threshold); }