imutils is Python basic image processing functional package to do image translation, rotation, resizing, skeletonization, or blur amount detection. imutils also check to find functions if you already have NumPy, SciPy, Matplotlib, and OpenCV installed.
In this article, we will check the image blur amount. This is used to verify image quality.
We will use PIP to install the package.
The next step is to install OpenCV package that will process the image. Run the below command to install it.
pip3 install opencv-python
We will also need Numpy package to work with array data. Install Numpy with following command.
pip3 install numpy
Now install imutils with below command:
pip3 install imutils
Now we have installed all packages that we required. Create file blur_detection.py and add the below code.
from imutils import paths import argparse import cv2 import sys def variance_of_laplacian(image): return cv2.Laplacian(image, cv2.CV_64F).var() # image path imagePath = sys.argv['image'] image = cv2.imread(imagePath) gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) fm = variance_of_laplacian(gray) text = "Not Blur" # check image quality if fm < 100: text = "Blur image" print text
variance_of_laplacian() function takes one argument of image and returns 3X3 laplacian variance. We will pass imagePath with argument. The default blur threshold value we set is 100. You can set it according to image you want to test. If the value will be lower than 100, we will print image as Blur.
Now run Python file in Terminal using python command
python blur_detection.py --image test.jpg
This will print variable text whether the image is blur or not. Thank you giving time to read the article.
Laravel Create and Delete DirectoryManaging files in web application is one...
How to Submit a Form Using jQueryUse the jQuery submit() Method You ca...
How to show and hide div elements based on the click of checkboxes in jQueryUse the jQuery toggle() method The fo...
Laravel Telescope Installation and Configuration TutorialLaravel provide some official packages w...
Block and Inline elementsEvery element in HTML has display level....