OpenCV入门(13):图片的马赛克效果

import cv2
import numpy as np

img = cv2.imread("./mm1.jpg",1)
cv2.imshow("src",img)
imgInfo = img.shape
print(imgInfo)
height = imgInfo[0]
width = imgInfo[1]

for m in range(100,300):
    for n in range(100,200):
        # 选取10*10的小矩形块中的一个pixel值替换整个小矩形块,即可达到马赛克效果
        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[m+i,n+j] = (b,g,r)
        
cv2.imshow("dst",img)
cv2.waitKey(0)

你可能感兴趣的:(OpenCV)