示例#1
0
def api_upload_image():
    database = flask.request.values.get('database')
    episode_id = flask.request.values.get('id')
    suffix = flask.request.values.get('suffix', default='v')
    filepath = Loader.get_image_path(database, episode_id, suffix)
    filepath.parent.mkdir(exist_ok=True, parents=True)

    image_data = flask.request.data
    if flask.request.files:
        image_data = flask.request.files['file'].read()

    image_buffer = np.fromstring(image_data, np.uint8)
    image = cv2.imdecode(image_buffer, cv2.IMREAD_UNCHANGED)
    cv2.imwrite(str(filepath), image)
    return flask.jsonify(success=True)
示例#2
0
def api_upload_image():
    collection = flask.request.values.get('collection')
    episode_id = flask.request.values.get('episode_id')
    action_id = flask.request.values.get('action_id', type=int)
    suffix = flask.request.values.get('suffix')
    filepath = Loader.get_image_path(collection,
                                     episode_id,
                                     action_id,
                                     suffix,
                                     image_format='png')
    filepath.parent.mkdir(exist_ok=True, parents=True)

    image_data = flask.request.data
    if flask.request.files:
        image_data = flask.request.files['file'].read()

    image_buffer = np.fromstring(image_data, np.uint8)
    image = cv2.imdecode(image_buffer, cv2.IMREAD_UNCHANGED)
    cv2.imwrite(str(filepath), image)
    return flask.jsonify(success=True)