Python OpenCV实例:马赛克效果

 

#coding:utf-8

'''
马赛克效果
'''
import cv2
import numpy as np

point_start = {'x':0,'y':0}
point_end = {'x':0,'y':0}
rows = 0
cols = 0

selected = False

def mosaic(selected_image,nsize=9):
    rows,cols,_ = selected_image.shape
    dist = selected_image.copy()
    # 划分小方块,每个小方块填充随机颜色
    for y in range(0,rows,nsize):
        for x in range(0,cols,nsize):
            dist[y:y+nsize,x:x+nsize] = (np.random.randint(0,255),np.random.randint(0,255),np.random.randint(0,255))
    return dist

def mouse_handler(event,x,y,flag,params):
    global point_lft,point_rgt,selected
    
    if event == cv2.EVENT_LBUTTONDOWN:
        print('button down')
        point_start['x'] = x
        point_start['y'] = y

    if event == cv2.EVENT_LBUTTONUP:
        print('button up')
        point_end['x'] = x
        point_end['y'] = y
        selected = True
    
src = cv2.imread('datas/images/f2.jpg')
rows,cols,_ = src.shape
src_cpy = src.copy()
cv2.nam

你可能感兴趣的:(图像处理)