Showing
3 changed files
with
34 additions
and
25 deletions
... | @@ -2,38 +2,24 @@ from flask import Flask, request | ... | @@ -2,38 +2,24 @@ from flask import Flask, request |
2 | from flask_restplus import Resource, Api, fields | 2 | from flask_restplus import Resource, Api, fields |
3 | 3 | ||
4 | import process | 4 | import process |
5 | +import save_image | ||
5 | 6 | ||
6 | app = Flask(__name__, static_url_path='/static') | 7 | app = Flask(__name__, static_url_path='/static') |
7 | api = Api(app, version='1.0', title='FlaskLocal', description='FlaskLocal') | 8 | api = Api(app, version='1.0', title='FlaskLocal', description='FlaskLocal') |
8 | 9 | ||
9 | -ns_node = api.namespace('node', description='node API') | ||
10 | -node_response = ns_node.model("test_response",{ | ||
11 | - "unknown_person": fields.Boolean, | ||
12 | - "fire_broken" : fields.Boolean | ||
13 | -}) | ||
14 | - | ||
15 | -node_request = ns_node.model('test_request', { | ||
16 | - 'data': fields.String | ||
17 | -}) | ||
18 | - | ||
19 | -#앱빌더를 통해 새 게시물 & 댓글 알림 수신 | ||
20 | -@ns_node.route('/process') | ||
21 | -class test(Resource): | ||
22 | - @ns_node.doc('post') | ||
23 | - @ns_node.expect(node_request) | ||
24 | - #@ns_node.marshal_with(node_response) | ||
25 | - def post(self): | ||
26 | - print(api) | ||
27 | - print(api.payload) | ||
28 | - #res = node.ProcessImage(api.payload) | ||
29 | - #return res | ||
30 | - | ||
31 | @app.route('/process', methods=['POST']) | 10 | @app.route('/process', methods=['POST']) |
32 | def post(): | 11 | def post(): |
33 | #print(request.form) | 12 | #print(request.form) |
34 | res = node.ProcessImage(request.form) | 13 | res = node.ProcessImage(request.form) |
35 | return res | 14 | return res |
36 | 15 | ||
16 | +@app.route('/save', methods=['POST']) | ||
17 | +def save(): | ||
18 | + #print(request.form) | ||
19 | + res = save.Save(request.form) | ||
20 | + return res | ||
21 | + | ||
37 | if __name__ == '__main__': | 22 | if __name__ == '__main__': |
38 | node = process.Process() | 23 | node = process.Process() |
39 | - app.run(host='0.0.0.0', port=80, threaded=False) | 24 | + save = save_image.SaveImage() |
25 | + app.run(host='0.0.0.0', port=80, threaded=False) | ||
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
... | @@ -30,8 +30,8 @@ class Process: | ... | @@ -30,8 +30,8 @@ class Process: |
30 | self.detector.setJsonPath(configuration_json=os.path.join(self.execution_path, "detection_config.json")) | 30 | self.detector.setJsonPath(configuration_json=os.path.join(self.execution_path, "detection_config.json")) |
31 | self.detector.loadModel() | 31 | self.detector.loadModel() |
32 | 32 | ||
33 | - def ProcessImage(self, data): | 33 | + def ProcessImage(self, payload): |
34 | - encoded_image = data | 34 | + encoded_image = payload['data'] |
35 | 35 | ||
36 | #base64 to image(uint8) decoding | 36 | #base64 to image(uint8) decoding |
37 | img64_decode = base64.b64decode(encoded_image) | 37 | img64_decode = base64.b64decode(encoded_image) | ... | ... |
detection-API/save_image.py
0 → 100644
1 | +import base64 | ||
2 | +import numpy as np | ||
3 | +from cv2 import cv2 | ||
4 | +import os | ||
5 | +import json | ||
6 | +import sys | ||
7 | + | ||
8 | +class SaveImage: | ||
9 | + def __init__(self): | ||
10 | + image_format = 'jpg' | ||
11 | + | ||
12 | + def Save(self, payload): | ||
13 | + known_path = './known_images/' | ||
14 | + encoded_image = payload['data'] | ||
15 | + image_name = payload['name'] | ||
16 | + | ||
17 | + #base64 to image(uint8) decoding | ||
18 | + img64_decode = base64.b64decode(encoded_image) | ||
19 | + im_arr = np.frombuffer(img64_decode, dtype=np.uint8) | ||
20 | + decoded_img = cv2.imdecode(im_arr, flags=cv2.IMREAD_COLOR) | ||
21 | + path = self.known_path+image_name+'.jpg' | ||
22 | + cv2.imwrite(self.known_path, decoded_img) | ||
23 | + return True | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
-
Please register or login to post a comment