import cv2 # 马赛克效果 img = cv2.imread(filename='../anqila21.jpg',flags=1) imginfo = img.shape height = imginfo[0] width = imginfo[1] flag = 2 # 系数,系数越小,马赛克的效果越不明显 for m in range(26,height): for n in range(140,880): if m%flag==0 and n%flag==0: for i in range(0,flag): for j in range(0,flag): (b,g,r) = img[m,n] img[i+m,j+n] = (b,g,r) cv2.imshow('dst',img) cv2.waitkey(0)
2. 毛玻璃效果
import cv2 import numpy as np import random # 毛玻璃效果 img = cv2.imread(filename='../anqila21.jpg',flags=1) imginfo = img.shape height = imginfo[0] width = imginfo[1] dst = np.zeros((height,width,3),np.uint8) for i in range(height-8): for j in range(width-8): index = int(random.random()*8) # 生成0-8之间的随机数(不包括8) dst[i, j] = img[i+index,j+index] cv2.imshow('dst',dst) cv2.waitkey(0)