#马赛克 import cv2 import numpy as np import matplotlib.pyplot as plt img = cv2.imread('coins.jpg',1) imgInfo = img.shape height = imgInfo[0] width = imgInfo[1] for m in range(200,400): #m,n表示打马赛克区域 for n in range(200,400): # pixel ->10*10 if m%10 == 0 and n%10==0: for i in range(0,10): for j in range(0,10): (b,g,r) = img[m,n] img[i+m,j+n] = (b,g,r) # cv2.imshow('dst',img) # cv2.waitKey(0) #原始图像 img0 = cv2.imread('coins.jpg',1) img_bgr2rgb1 = cv2.cvtColor(img0, cv2.COLOR_BGR2RGB) plt.imshow(img_bgr2rgb1) plt.show() #马赛克图像 img_bgr2rgb0 = cv2.cvtColor(img, cv2.COLOR_BGR2RGB) plt.imshow(img_bgr2rgb0) plt.show()
结果