图片变油画

import cv2

import numpy

img = cv2.imread('E:\wangzc\code\.math\s.png')

height = img.shape[0]

width = img.shape[1]

print(height)

gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)

det = numpy.zeros((height,width,3),numpy.uint8)

for i in range(4,height-4):

    print(i)

    for j in range(4,width-4):

        array1 = numpy.zeros(8,numpy.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

                curentmax = array1[0]

                l = 0

                for k in range(0,8):

                    if curentmax

                        curentmax = array1[k]

                        l = k

        for m in range(-4,4):

            for n in range(-4,4):

                if gray[i+m,j+n] >= (l*32) and gray[i+m,j+n]<=((l+1)*32):

                    b,g,r = img[i+m,j+n]

        det[i,j] = (b,g,r)

cv2.imshow("set",det)

cv2.waitKey(0)

你可能感兴趣的:(python,python,numpy,opencv)