自学内容网 自学内容网

OpenCV马赛克

#马赛克
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()

结果


原文地址:https://blog.csdn.net/A_Lv123/article/details/142717160

免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!