LoginSignup
5
5

More than 3 years have passed since last update.

flaskでpostされた画像をopencvで扱えるように読み込む

Last updated at Posted at 2017-08-11

postされたStrageFile状態の画像データを読み込んで、npのarrayの形式に変換します。
変換されたものをopencvでカラー画像として読み込んで、opencvで扱える形式になります。
僕の例だとflaskを使っていますが、おそらく他のフレームワークでも同様の方法が使えると思います。

@app.route('/upload', methods=['POST'])
def upload():
    if request.files['file'].filename != u'':
        file_data = request.files['file'].read()
        nparr = np.fromstring(file_data, np.uint8)
        img = cv2.imdecode(nparr, cv2.IMREAD_COLOR)

参考:https://gist.github.com/kylehounslow/767fb72fde2ebdd010a0bf4242371594

5
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
5