|
@@ -35,10 +35,52 @@ int doDetection(cv::Mat cvImage) {
|
|
|
cv::Laplacian(grayCVImage, laplacianImage, CV_64F);
|
|
|
cv::Scalar mu, sigma;
|
|
|
cv::meanStdDev(laplacianImage, mu, sigma);
|
|
|
+ int blur_value = sigma.val[0] * sigma.val[0];
|
|
|
+ blur_value = blur_value < 100 ? image_color_ratio(grayCVImage) : blur_value;
|
|
|
cvImage.release();
|
|
|
grayCVImage.release();
|
|
|
- return sigma.val[0] * sigma.val[0];
|
|
|
+ return blur_value;
|
|
|
}
|
|
|
}
|
|
|
return -1;
|
|
|
}
|
|
|
+
|
|
|
+//定义比较的函数
|
|
|
+static bool cmp_value(const std::pair<long, long> left, const std::pair<long, long> right) {
|
|
|
+ return left.second < right.second;
|
|
|
+}
|
|
|
+
|
|
|
+int image_color_ratio(cv::Mat image) {
|
|
|
+ int num = 0;//记录颜色的像素点
|
|
|
+ std::map<long, long> colors;
|
|
|
+ for (int i = 0; i < image.rows; ++i) {
|
|
|
+ for (int j = 0; j < image.cols; ++j) {
|
|
|
+ int gray_data = image.at<uchar>(i, j);
|
|
|
+ if (colors.count(gray_data) == 0) {
|
|
|
+ colors[gray_data] = 1;
|
|
|
+ } else {
|
|
|
+ long a = ++colors[gray_data];
|
|
|
+ colors[gray_data] = a;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (!colors.empty()) {
|
|
|
+ auto maxCount = 0L;
|
|
|
+ if (colors.size() > 1) {
|
|
|
+ maxCount = max_element(colors.begin(), colors.end(), cmp_value)->second;
|
|
|
+ } else {
|
|
|
+ std::map<long, long>::iterator iter;
|
|
|
+ iter = colors.begin();
|
|
|
+ while (iter != colors.end()) {
|
|
|
+ maxCount = iter->second;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ float i = maxCount * 1.0f / (image.rows * image.cols);
|
|
|
+ if (i >= DEFAULT_PIX_THRESHOLD) {
|
|
|
+ num = DEFAULT_BLUR_THRESHOLD + 1;
|
|
|
+ };
|
|
|
+ }
|
|
|
+ return num;
|
|
|
+}
|