直接上代碼,list_jian.txt為待檢測圖像路徑列表
import cv2
import numpy as np
import os
for path in open("list_jian.txt"):
path = path.replace('\n', '') #去除換行符號
img = cv2.imread(path, 1)
width,height = img.shape[:2][::-1]
img_resize = cv2.resize(img,(int(width*1.0),int(height*1.0)),interpolation=cv2.INTER_CUBIC)
img_gray = cv2.cvtColor(img_resize,cv2.COLOR_RGB2GRAY)
imageVar = cv2.Laplacian(img_gray, cv2.CV_64F).var() #圖像模糊度
print('>>>',path)
print(">>>",int(imageVar))
