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