How to perform Blur Detection using OpenCV in Python

import cv2
import argparse
import glob

Image for post

ap = argparse.ArgumentParser()
ap.add_argument('-i', '--images', required=True,)
ap.add_argument('-t', '--threshold', type=float)
args = vars(ap.parse_args())

To keep the images in the folder in a single array, we write the following code:

images = [cv2.imread(file) for file in glob.glob("{}/*.jpeg".format(args['images']))]

Now it is time to take the pictures in the folder one by one and apply the Laplacian method to find blur.

for image in images:
	gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
	fm = cv2.Laplacian(gray, cv2.CV_64F).var()
	text = "Not Blurry"

	if fm < args["threshold"]:
		text = "Blurry"

	cv2.putText(image, "{}: {:.2f}".format(text, fm), (10, 30),
		cv2.FONT_HERSHEY_SIMPLEX, 0.8, (0, 0, 255), 3)
	cv2.imshow("Image", image)
python -i images -t 100

Author - Blur detection

Muhammed Furkan Gülşen

I have been a web developer for over 5 years. First, I continued as a Frontend developer. Later, I learned Backend and continued to improve myself as a FullStack developer. During this period, I managed projects as a Project Manager in the Facebook Developer Circle community. After doing this job for about 1 year, I received an offer from a company and switched to that company. I have been working in this company for more than 10 months, both as a full-stack developer and as a Data Scientist.While this process was going on (for the last 2 years) I started data science. Later the process continued as machine learning, deep learning, image processing, and finally Computer Vision.

Author: admin

Leave a Reply

Your email address will not be published.