Get the App
SLTechnology News&Howtos  ›  Development  › 

How to detect the effect of blurred image using opencv python

Shulou Source: shulou.com Published: 2022-06-01 06:37:55 10月01日 Update

Xiaobian to share with you how to use opencv python fuzzy image detection effect, I believe most people still do not know how, so share this article for everyone's reference, I hope you have a lot of harvest after reading this article, let's go to understand it together!

In this paper, Laplacian operator is used to calculate the blur degree of image. The image less than threshold is considered as blurred, and thus moved to the folder dedicated to storing blurred images. This article uses only the cv2 and shutil libraries, which you need to install if you want to use the script directly. The complete code is shown below.

import osimport cv2import shutilimport sys #blur image detection function, threshold default is 0.07def blurImagesDetection(folder_path, thres=0.07): #Create a new folder to store blurred images blurImageDirPath = os.getcwd() + "/blurImages" if not os.path.exists(blurImageDirPath): os.mkdir(blurImageDirPath) #Get a list of image names in the image folder imageNameList = os.listdir(folder_path) for imageName in imageNameList: #Get the image path imagePath = os.path.join(folder_path, imageName) #Read image as grayscale img = cv2.imread(imagePath, 0) #Reduce image size and speed up processing tiny_img = cv2.resize(img, (400, 300), fx=0, fy=0) #Get image size width, height = tiny_img.shape #Calculate image blur blurness = cv2.Laplacian(tiny_img, cv2.CV_64F).var() / (width * height) #If the blur level of the image is less than the threshold, move it to the folder where the blurred image is stored if blurness

< thres: print(imageName + " bulrness:%f 模糊" % (blurness)) blurImagePath = os.path.join(blurImageDirPath, imageName) shutil.move(imagePath, blurImagePath) else: print(imageName + " blurness:%f 不模糊" % (blurness))if __name__ == '__main__': # 指定要处理的文件夹路径,sys.argv[1]为第一个参数 folder_path = os.getcwd()+'/'+sys.argv[1] # 调用函数 blurImagesDetection(folder_path) 实际运行效果如图所示 所检测到的模糊影像如图所示

The above is "how to use opencv python blur image detection effect" all the content of this article, thank you for reading! I believe that everyone has a certain understanding, hope to share the content to help everyone, if you still want to learn more knowledge, welcome to pay attention to the industry information channel!

Tags: Image file folder detection effect degree article threshold content function path such as figure processing move not so two code parameter most actual Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Huawei Redmi Linux MariaDB vpn