python opencv对一组照片进行清晰度打分

import cv2		# 导入cv2
import os
import sys
# 给图片清晰度打分


def getImageVar(imgPath):
    image = cv2.imread(imgPath)
    img2gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
    imageVar = int(cv2.Laplacian(img2gray, cv2.CV_64F).var())
    return imageVar

# imgPath='1.jpg'	#本地路径下的一张图片
# print(getImageVar(imgPath))


for root, dirs, files in os.walk(r'/Users/anker/Desktop/test/test-jp'):
    for file in files:
        imgPath = os.path.join(root, file)
        print(getImageVar(imgPath), '  ', imgPath)

结果返回一个数值,数值越大,清晰度越高。

你可能感兴趣的:(python,opencv,清晰度)