Read the image posted by flask so that it can be handled by opencv

Reads the posted image data in the StrageFile state and converts it to the np array format. The converted one is read as a color image by opencv, and it becomes a format that can be handled by opencv. In my example I use flask, but I think other frameworks can probably use the same method.

@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)

Reference: https://gist.github.com/kylehounslow/767fb72fde2ebdd010a0bf4242371594

Recommended Posts

Read the image posted by flask so that it can be handled by opencv
The story that it turns blue when the data read by Pillow is converted so that it can be handled by OpenCV
List the classes that can be referenced by ObjCClass
I tried to expand the database so that it can be used with PES analysis software
Hide the warning that zsh can be used by default on Mac
Tensorflow, it seems that even the eigenvalues of the matrix can be automatically differentiated
Moved Raspberry Pi remotely so that it can be LED attached with Python
The SHA-512 encryption of the password has been scripted so that it can be automated without worrying about the execution environment.
The avi file output by OpenCV cannot be played
ANTs image registration that can be used in 5 minutes
POST the image with json and receive it with flask
Install Mecab and CaboCha on ubuntu16.04LTS so that it can be used from python3 series
I made a function to crop the image of python openCV, so please use it.
Read the OpenCV documentation
It seems that Skeleton Tracking can be done with RealSense
How to switch the configuration file to be read by Python
Goroutine that can be used in the field (errgroup.Group edition)
Display image data handled by OpenCV / numpy on Qt Widget
Implement a thread that can be paused by exploiting yield
I investigated the pretreatment that can be done with PyCaret
[Flask] I tried to summarize the "docker-compose configuration" that can be created quickly for web applications
The mystery of the number that can be seen just by arranging 1s-The number of repunits and mysterious properties-
[Django] A brief summary of the log output function so that even beginners can understand it.
Introduced anyenv and pasted a symlink so that existing pyenv, rbenv, jenv can also be read
・ <Slack> Write a function to notify Slack so that it can be quoted at any time (Python)