作者water415 (蔡佩)
看板Python
标题[问题] 如何将透过post收到的影像直接做处理
时间Sun Feb 10 16:50:19 2019
大家好, 小妹python新手
目前遇到一些问题不知道该从何下手
希望各位大大可以不吝啬提供一些方向
或是提供一些搜寻关键字等等
因为现在真的没什麽头绪
--------------------------------------
目前有一个简易的flask server程式
就只是单纯可以接收影像并把他储存起来
内容如下
@app.route('/postImage', methods=['POST'])
def postImage():
if request.method == 'POST':
upload_file = request.files['file']
old_file_name = upload_file.filename
if upload_file:
file_path = os.path.join('./image/', old_file_name)
upload_file.save(file_path)
print('file saved to %s' % file_path)
result = imagePreProcess(file_path)
return result
else:
return 'error'
else:
return 'error'
现在想要先经过一些简单的影像处理後再储存
但目前能做到的前处理的function大概像这样
def imagePreProcess(path):
img = plt.imread(str(path))
...
...
...
需要先把影像存起来再读出来做二次处理
不知道有没有方法可以省略先把影像储存起来这个步骤
就是直接把post过来的影像upload_file直接放进imagePreProcess处理呢?
(目前使用的影像档案是PNG类型)
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 36.227.181.167
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/Python/M.1549788622.A.8C2.html
2F:→ s860134: Each value in files is a Werkzeug FileStorage object 02/10 17:14
3F:→ s860134: 点进去 ...so it’s possible to do storage.read() 02/10 17:14
4F:→ water415: 我改成upload_file.read()把档案拿出来之後还是没办法 02/10 17:51
5F:→ water415: 这是不是代表我必须要将他转换成可以做imread的格式? 02/10 17:52
6F:推 Raymond0710: 放到ByteIO 用PIL.Image.read 02/11 02:13