Is there a way to detect if an image is blurry?

后端 未结 12 1940
予麋鹿
予麋鹿 2020-11-22 14:48

I was wondering if there is a way to determine if an image is blurry or not by analyzing the image data.

12条回答
  •  礼貌的吻别
    2020-11-22 15:04

    That's what I do in Opencv to detect focus quality in a region:

    Mat grad;
    int scale = 1;
    int delta = 0;
    int ddepth = CV_8U;
    Mat grad_x, grad_y;
    Mat abs_grad_x, abs_grad_y;
    /// Gradient X
    Sobel(matFromSensor, grad_x, ddepth, 1, 0, 3, scale, delta, BORDER_DEFAULT);
    /// Gradient Y
    Sobel(matFromSensor, grad_y, ddepth, 0, 1, 3, scale, delta, BORDER_DEFAULT);
    convertScaleAbs(grad_x, abs_grad_x);
    convertScaleAbs(grad_y, abs_grad_y);
    addWeighted(abs_grad_x, 0.5, abs_grad_y, 0.5, 0, grad);
    cv::Scalar mu, sigma;
    cv::meanStdDev(grad, /* mean */ mu, /*stdev*/ sigma);
    focusMeasure = mu.val[0] * mu.val[0];
    

提交回复
热议问题