<p>I may be late to answer this one, but here is one potential approach.
The blur_detector library in pypi can be used to identify regions in an image which are sharp vs blurry. Here is the paper on which the library is created: <a href="https://arxiv.org/pdf/1703.07478.pdf" rel="noreferrer">https://arxiv.org/pdf/1703.07478.pdf</a></p>
<p>The way this library operates is that it looks at every pixel in the image at multiple scales and performs the discrete cosine transform at each scale. These DCT coefficients are then filtered such that we only use the <code>high frequency</code> coefficients. All the <code>high frequency</code> DCT coefficients at multiple scales are then fused together and sorted to form the <code>multiscale-fused and sorted high-frequency transform coefficients</code>
A subset of these sorted coefficients is selected. This is a tunable parameter and user can experiment with it based on the application. The output of the selected DCT coefficients is then sent through a max pooling to retain the maximum activation at multiple scales. This makes the algorithm quite robust to detect blurry areas in an image.</p>
<p>Here are the results that I see on the images that you have provided in the question:
<a href="https://i.stack.imgur.com/L0N25.png" rel="noreferrer"><img src="https://i.stack.imgur.com/L0N25.png" alt="enter image description here" /></a></p>
<p>Note: I have used a face detector from the default cascade_detectors in opencv to select a region of interest. the output of these two approaches (spatial blur detection + face detection) can be used to get the sharpness map in the image.</p>
<p>Here we can see that in the sharp images, the intensity of the pixels in the eyes region is very high, whereas for the blurry image, it is low.</p>
<p>You can threshold this to identify which images are sharp and which images are blurry.</p>
<p>Here is the code snippet which generated the above results:</p>
<pre><code>pip install blur_detector
</code></pre>
<hr />
<pre><code>import blur_detector
import cv2

if __name__ == '__main__':
    face_cascade = cv2.CascadeClassifier('cv2/data/haarcascade_frontalface_default.xml')

    img = cv2.imread('1.png', 0)
    blur_map1 = blur_detector.detectBlur(img, downsampling_factor=1, num_scales=3, scale_start=1)
    faces = face_cascade.detectMultiScale(img, 1.1, 4)
    for (x, y, w, h) in faces:
        cv2.rectangle(blur_map1, (x, y), (x + w, y + h), (255, 0, 0), 2)

    img = cv2.imread('2.png', 0)
    blur_map2 = blur_detector.detectBlur(img, downsampling_factor=1, num_scales=3, scale_start=1)
    faces = face_cascade.detectMultiScale(img, 1.1, 4)
    for (x, y, w, h) in faces:
        cv2.rectangle(blur_map2, (x, y), (x + w, y + h), (255, 0, 0), 2)

    img = cv2.imread('3.png', 0)
    blur_map3 = blur_detector.detectBlur(img, downsampling_factor=1, num_scales=3, scale_start=1)
    faces = face_cascade.detectMultiScale(img, 1.1, 4)
    for (x, y, w, h) in faces:
        cv2.rectangle(blur_map3, (x, y), (x + w, y + h), (255, 0, 0), 2)

    cv2.imshow('a', blur_map1)
    cv2.imshow('b', blur_map2)
    cv2.imshow('c', blur_map3)
    cv2.waitKey(0)
</code></pre>
<p>To understand the details about the algorithm regarding the blur detector, please take a look at this github page: <a href="https://github.com/Utkarsh-Deshmukh/Spatially-Varying-Blur-Detection-python" rel="noreferrer">https://github.com/Utkarsh-Deshmukh/Spatially-Varying-Blur-Detection-python</a></p>
Blur Detection of image using OpenCV
<p>I am working on the blur detection of images. I have used the <strong>variance of the Laplacian method</strong>  in OpenCV.</p>

<pre><code>img = cv2.imread(imgPath)
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
value = cv2.Laplacian(gray, cv2.CV_64F).var()
</code></pre>

<p>The function failed in some cases like pixelated blurriness. It shows a higher value for those blur images than the actual clear images. Is there any better approach that detects Pixelated as well as motion blurriness?</p>

<p>Sample images:</p>

<p>This image is much clearer but showing value of <strong>266.79</strong></p>

<p><a href="https://i.stack.imgur.com/5yKqT.png" rel="noreferrer"><img src="https://i.stack.imgur.com/5yKqT.png" alt="enter image description here"></a></p>

<p>Where as this image showing the value of  <strong>446.51</strong> .</p>

<p><a href="https://i.stack.imgur.com/oJ5NB.png" rel="noreferrer"><img src="https://i.stack.imgur.com/oJ5NB.png" alt="enter image description here"></a></p>

<p>Also this image seems to be much clearer but showing value only <strong>38.96</strong></p>

<p><a href="https://i.stack.imgur.com/zSV4S.png" rel="noreferrer"><img src="https://i.stack.imgur.com/zSV4S.png" alt="enter image description here"></a></p>

<p>I need to classify 1st and 3rd one as not blur whereas the second one as a blur.</p>