[問題] 如何將透過post收到的影像直接做處理

看板Python作者 (蔡佩)時間6年前 (2019/02/10 16:50), 編輯推噓1(105)
留言6則, 3人參與, 6年前最新討論串1/1
大家好, 小妹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

02/10 17:13, 6年前 , 1F
查文件就有了 https://goo.gl/FqfiPn
02/10 17:13, 1F

02/10 17:14, 6年前 , 2F
Each value in files is a Werkzeug FileStorage object
02/10 17:14, 2F

02/10 17:14, 6年前 , 3F
點進去 ...so it’s possible to do storage.read()
02/10 17:14, 3F

02/10 17:51, 6年前 , 4F
我改成upload_file.read()把檔案拿出來之後還是沒辦法
02/10 17:51, 4F

02/10 17:52, 6年前 , 5F
這是不是代表我必須要將他轉換成可以做imread的格式?
02/10 17:52, 5F

02/11 02:13, 6年前 , 6F
放到ByteIO 用PIL.Image.read
02/11 02:13, 6F
文章代碼(AID): #1SN-NEZ2 (Python)
文章代碼(AID): #1SN-NEZ2 (Python)