title: Detect motion blur of a cropped face with python i.e. opencv
body: <p>I'm detecting faces with haarcascade and tracking them with a webcam using OpenCV. I need to save each face that is tracked. But the problem is when people are moving. In which case the face becomes blurry.</p>
  
  <p>I've tried to mitigate this problem with opencv's dnn face detector and Laplacian with the following code:</p>
  
  <pre><code>blob = cv2.dnn.blobFromImage(cropped_face, 1.0, (300, 300), (104.0, 177.0, 123.0))
  net.setInput(blob)
  detections = net.forward()
  confidence = detections[0, 0, 0, 2]
  blur = cv2.Laplacian(cropped_face, cv2.CV_64F).var()
  if confidence &gt;= confidence_threshold and blur &gt;= blur_threshold:
      cv2.imwrite('less_blurry_image', cropped_face)
  </code></pre>
  
  <p>Here I tried to limit saving a face if it is not blurry due to motion by <code>setting blur_threshold</code> to 500 and <code>confidence_threshold</code> to 0.98 (i.e. 98%).</p>
  
  <p>But the problem is if I change the camera I have to change the thresholds again manually. And in most of the cases setting a threshold omits most of the faces.</p>
  
  <p>Plus, it is difficult to detect since the background is always clear compared to the blurred face.</p>
  
  <p>So my question is how can I detect this motion blur on a face. I know I can train an ML model for motion blur detection of a face. But that would require heavy processing resources for a small task.</p>
  
  <p>Moreover, I will be needing a huge amount of annotated data for training if I go that route. Which is not easy for a student like me.</p>
  
  <p>Hence, I am trying to detect this with OpenCV which will be a lot less resource intensive compared to using an ML model for detection.</p>
  
  <p>Is there any less resource intensive solution for this? </p>