OPENCV(Python) 一個簡單方法識別毛玻璃、高斯模糊
OPENCV(Python) 一個簡單方法識別毛玻璃、高斯模糊
資料來源: https://mp.weixin.qq.com/s/YXInwmU4TwZmSbJp5VEFWA
GITHUB: https://github.com/jash-git/Jash-good-idea-20210318-001/tree/master/OPENCV%20%E4%B8%80%E5%80%8B%E7%B0%A1%E5%96%AE%E6%96%B9%E6%B3%95%E8%AD%98%E5%88%A5%E6%AF%9B%E7%8E%BB%E7%92%83%E3%80%81%E9%AB%98%E6%96%AF%E6%A8%A1%E7%B3%8A
Code
#coding:utf-8 import cv2 import numpy as np import random img = cv2.imread('test.jpg',1) shape = img.shape h = shape[0] w = shape[1] dst = np.zeros((h,w,3),np.uint8) mm = 8 for m in range(h-mm): for n in range(w-mm): index = int(random.random()*8) (b,g,r) = img[m+index,n+index] dst[m,n] = (b,g,r) cv2.imwrite("result.jpg", dst)
import cv2 def variance_of_laplacian(image): return cv2.Laplacian(image, cv2.CV_64F).var() imagePath = “test.jpg” image = cv2.imread(imagePath) gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) fm = variance_of_laplacian(gray) if fm < 100: print("Blurry")