Exemple #1
0
def api_sketch2model():
    """Main API: Takes an image, runs sketch2model image processing and
    returns model as a png image"""

    try:
        ## Add more validation here
        sketch = request.files['sketch']
    except Exception as e:
        app.logger.error('API Sketch Error: %s', e)
        result = {
            'ok': False,
            'error': 'sketch not found or could not be opened'
        }
        return jsonify(result)

    try:
        model = sketch2model(sketch)
        response = make_response(model.getvalue())
        response.mimetype = 'image/png'

    except Exception as e:
        app.logger.error('API Sketch2Model Error: %s', e)
        result = {
            'ok': False,
            'error': 'sketch2model image processing failed'
        }
        return jsonify(result)

    return(response)
Exemple #2
0
def model_sketch(filename, bucket, upload_folder, model_folder):
    """Pulls sketch image from S3, runs sketch2model image processing
    on the image and then uploads result to S3."""
    s3 = resource('s3')
    
    s3_upload = s3.Object(bucket, upload_folder + '/' + filename)    
    sketch = s3_upload.get()['Body']

    s3_model = s3.Object(bucket, model_folder + '/' + filename)
    model_object = sketch2model(sketch)
    s3_model.put(Body=model_object, ContentType='image/jpeg') 
    model_object.close()