opencv 進行圖像的花屏檢測(模糊檢測)

參考:html

https://www.pyimagesearch.com/2015/09/07/blur-detection-with-opencv/python

https://www.cnblogs.com/arkenstone/p/7900978.htmlspa

先對圖像用拉普拉斯算子進行濾波,而後求取獲得的結果圖像的方差,若是方差小於必定值則圖片視爲模糊。利用python很好實現:code

img2gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)  # 將圖片壓縮爲單通道的灰度圖
score = cv2.Laplacian(img2gray, cv2.CV_64F).var()

C++實現以下:htm

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); }
相關文章
相關標籤/搜索