Skip to content

Commit

Permalink
Can get cropped images from back
Browse files Browse the repository at this point in the history
  • Loading branch information
iPhaeton committed Jan 2, 2019
1 parent 7beaf9a commit 870155e
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 3 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@ home/modules/mask_rcnn_inception_v2_coco_2018_01_28/
home/modules/mask_rcnn_resnet50_atrous_coco_2018_01_28/
.floydexpt
input/
home/.png
home/images/
41 changes: 38 additions & 3 deletions home/app.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,53 @@
from flask import Flask, jsonify, request
from flask import Flask, jsonify, request, send_file
from modules.detector import Detector
from keras.preprocessing.image import ImageDataGenerator, img_to_array, load_img, array_to_img, save_img
from werkzeug.utils import secure_filename
import os

app = Flask(__name__)

detector = None

def load_detector():
global detector
if detector == None:
detector = Detector('yolo')
return detector

# The request method is POST (this method enables your to send arbitrary data to the endpoint in the request body, including images, JSON, encoded-data, etc.)
@app.route('/', methods=["POST"])
def evaluate():
input_image = request.files.get('image')
print('333')
detector = load_detector()

return "success"
filename = secure_filename('recognizing_image.jpg')
image_dir = './images'
input_filepath = os.path.join(image_dir, filename)
output_filepath = os.path.join(image_dir, 'recognized_image.jpg')

if os.path.exists(image_dir) == False:
os.mkdir(image_dir)

input_image.save(input_filepath)

car_image = detector.crop_image(
source_image=input_filepath,
input_type='file',
params={
'detect_largest_box': True,
'smallest_detected_area': 0.2,
}
)

save_img(output_filepath, car_image)

car_image_array = img_to_array(car_image)

return send_file(output_filepath, mimetype='image/jpg')

# The following is for running command `python app.py` in local development, not required for serving on FloydHub.
if __name__ == "__main__":
print('* Loading detection model...')
load_detector()
print("* Starting web server... please wait until server has fully started")
app.run(host='0.0.0.0', threaded=False)

0 comments on commit 870155e

Please sign in to comment.