Toggle navigation
Toggle navigation
This project
Loading...
Sign in
박선진
/
video-emergency-detection
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
3
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
박선진
2020-06-25 10:48:02 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
9af713996270b6303a3be10918a97e366d0db0d9
9af71399
1 parent
51e9cc01
add save image api
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
34 additions
and
25 deletions
detection-API/index.py
detection-API/process.py
detection-API/save_image.py
detection-API/index.py
View file @
9af7139
...
...
@@ -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
...
...
detection-API/process.py
View file @
9af7139
...
...
@@ -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
)
...
...
detection-API/save_image.py
0 → 100644
View file @
9af7139
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
Please
register
or
login
to post a comment