Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to detect the effect of blurred image using opencv python

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

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!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report