shimat / opencvsharp

OpenCV wrapper for .NET

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Unable to detect if a image is blurred in few cases

SandeepReddyPinniti opened this issue · comments

Summary of your issue

Hi, I have used OpenCvSharp for the first time. I'm using it to find out if an image is blurred or not. Some of the images are blurred but my code is returning that the image is not blurred. Attached image for reference. Please review my code and let me know if I have used OpenCvSharp correctly.

Environment

Windows 10 Machine, Using C#

Example code:

public static bool IsBlurry(string imagePath, double threshold = 100.0)
{
    // Load the image
    var image = Cv2.ImRead(imagePath, ImreadModes.Grayscale);
    
    // Compute the Laplacian of the image
    var laplacian = new Mat();
    Cv2.Laplacian(image, laplacian, MatType.CV_64F);

    // Compute the variance of Laplacian
    Cv2.MeanStdDev(laplacian, out _, out var stddev);

    var varianceValue = stddev.Val0 * stddev.Val0; // Variance = standard deviation squared

    // Check if the image is blurred
    return varianceValue < threshold;

}

Output:

paste your output

What did you intend to be?

Accurately detect if the image is blurred.
download (2)
download
photo-1485288734756-0b31a0a31d95