油絵特殊効果の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()

ここに画像の説明を挿入

おすすめ

転載: blog.csdn.net/cyj5201314/article/details/114656931
おすすめ