码迷,mamicode.com
首页 > 其他好文 > 详细

使用numpy 和 PIL 手绘效果

时间:2020-05-06 20:08:31      阅读:87      评论:0      收藏:0      [点我收藏+]

标签:play   ring   string   tle   byte   lenovo   syn   decode   die   

其中出现了一个错误:

SyntaxError: (unicode error) ‘unicodeescape‘ codec can‘t decode bytes 

技术图片

 

 解决办法:

在路径前加 ‘r’

原因:在Python中 \ 是转义符,\u表示其后是UNICODE编码,因此\User在这里会报错,在字符串前面加个 r(rawstring  原生字符串),可以避免python与正则表达式语法的冲突!

参考:https://blog.csdn.net/qq_28286027/article/details/92759470

技术图片
 1 from PIL import Image
 2 import numpy as np
 3 el=np.pi/2.2
 4 az=np.pi/4
 5 depth=10
 6 im=np.array(Image.open(rC:\Users\lenovo\Desktop\壁纸呗\梦源系列 片尾03.png).convert(L))
 7 a=np.asarray(im).astype(float)
 8 grad = np.gradient(a)
 9 grad_x,grad_y = grad
10 grad_x = grad_x*depth/100
11 grad_y = grad_y*depth/100
12 dx=np.cos(el)*np.cos(az)
13 dy=np.cos(el)*np.sin(az)
14 dz=np.sin(el)
15 A=np.sqrt(grad_x**2+grad_y**2+1.0)
16 uni_x=grad_x/A
17 uni_y=grad_y/A
18 uni_z=1.0/A
19 a2=255*(dx*uni_x+dy*uni_y+dz*uni_z)
20 a2=a2.clip(0,255)
21 im2=Image.fromarray(a2.astype(uint8))
22 im2.save(rC:\Users\lenovo\Desktop\壁纸呗\hand drawn of mengyuan03.png)
View Code

技术图片技术图片

 

使用numpy 和 PIL 手绘效果

标签:play   ring   string   tle   byte   lenovo   syn   decode   die   

原文地址:https://www.cnblogs.com/modiqiang/p/12838176.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!