opencv图像特效之油画特效

#油画特效
# 1 gray 2 分割成x*x的小方块 3 0-255划分成几个等级, 将2步结果映射到这个等级上
import cv2
import numpy as np
img = cv2.imread("E:/code/conputer_visual/data/0.jpg", 1)
imginfo = img.shape
height = imginfo[0]
width = imginfo[1]
cv2.imshow("src", img)

gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
dst = np.zeros((height, width, 3), np.uint8)
for i in range(4, height-4):
    for j in range(4, width-4):
        array1 = np.zeros(8, np.uint8)
        for m in range(-4, 4):
            for n in range(-4, 4):
                p1 = int(gray[i+m, j+n]/32)
                array1[p1] = array1[p1] + 1
        currentMax = np.argmax(array1)
        #简化 均值
        for m in range(-4,4):
            for n in range(-4,4):
                if gray[i+m,j+n] >= (currentMax*32) and gray[i+m,j+n] <= ((currentMax+1)*32):
                    bgr = img[i+m,j+n]
        dst[i,j] = bgr
cv2.imshow("dst", dst)
cv2.waitKey()

opencv图像特效之油画特效_第1张图片

你可能感兴趣的:(opencv,opencv,cv,计算机视觉,边缘检测)