看板 Python 關於我們 聯絡資訊
大家好, 小妹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://www.ptt.cc/bbs/Python/M.1549788622.A.8C2.html
s860134: 查文件就有了 https://goo.gl/FqfiPn 02/10 17:13
s860134: Each value in files is a Werkzeug FileStorage object 02/10 17:14
s860134: 點進去 ...so it’s possible to do storage.read() 02/10 17:14
water415: 我改成upload_file.read()把檔案拿出來之後還是沒辦法 02/10 17:51
water415: 這是不是代表我必須要將他轉換成可以做imread的格式? 02/10 17:52
Raymond0710: 放到ByteIO 用PIL.Image.read 02/11 02:13