박선진

add save image api

......@@ -2,38 +2,24 @@ from flask import Flask, request
from flask_restplus import Resource, Api, fields
import process
import save_image
app = Flask(__name__, static_url_path='/static')
api = Api(app, version='1.0', title='FlaskLocal', description='FlaskLocal')
ns_node = api.namespace('node', description='node API')
node_response = ns_node.model("test_response",{
"unknown_person": fields.Boolean,
"fire_broken" : fields.Boolean
})
node_request = ns_node.model('test_request', {
'data': fields.String
})
#앱빌더를 통해 새 게시물 & 댓글 알림 수신
@ns_node.route('/process')
class test(Resource):
@ns_node.doc('post')
@ns_node.expect(node_request)
#@ns_node.marshal_with(node_response)
def post(self):
print(api)
print(api.payload)
#res = node.ProcessImage(api.payload)
#return res
@app.route('/process', methods=['POST'])
def post():
#print(request.form)
res = node.ProcessImage(request.form)
return res
@app.route('/save', methods=['POST'])
def save():
#print(request.form)
res = save.Save(request.form)
return res
if __name__ == '__main__':
node = process.Process()
app.run(host='0.0.0.0', port=80, threaded=False)
save = save_image.SaveImage()
app.run(host='0.0.0.0', port=80, threaded=False)
\ No newline at end of file
......
......@@ -30,8 +30,8 @@ class Process:
self.detector.setJsonPath(configuration_json=os.path.join(self.execution_path, "detection_config.json"))
self.detector.loadModel()
def ProcessImage(self, data):
encoded_image = data
def ProcessImage(self, payload):
encoded_image = payload['data']
#base64 to image(uint8) decoding
img64_decode = base64.b64decode(encoded_image)
......
import base64
import numpy as np
from cv2 import cv2
import os
import json
import sys
class SaveImage:
def __init__(self):
image_format = 'jpg'
def Save(self, payload):
known_path = './known_images/'
encoded_image = payload['data']
image_name = payload['name']
#base64 to image(uint8) decoding
img64_decode = base64.b64decode(encoded_image)
im_arr = np.frombuffer(img64_decode, dtype=np.uint8)
decoded_img = cv2.imdecode(im_arr, flags=cv2.IMREAD_COLOR)
path = self.known_path+image_name+'.jpg'
cv2.imwrite(self.known_path, decoded_img)
return True
\ No newline at end of file