-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdummy.py
executable file
·84 lines (58 loc) · 1.45 KB
/
dummy.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/usr/bin/python3
import io
import time
import json
from aiohttp import web
from PIL import Image
version = "0.0.1"
item_types = ['dummy']
# GET /status
async def status(req):
return web.json_response({
"name": "name of detector",
"type": "detector",
"path": "/",
"version": version,
"output": {
"types": item_types,
},
})
# POST /
async def parser(req):
at = time.time()
data = await req.post()
file = data['frame'].file
imgdata = io.BytesIO(file.read())
img = Image.open(imgdata)
items = json.loads(data["json"])
for item in items:
print(item)
# w, h = img.size
print(img.size)
items = []
# # do something with `img` and store detected objects to the items array
# for obj in DETECT(img):
# items.append({
# 'type': obj.type,
# 'name': obj.name,
# 'bbox': [
# round(obj.x, 3),
# round(obj.y, 3),
# round(obj.w, 3),
# round(obj.h, 3),
# ]
# })
# print(items, time.time() - at)
resp = {
'predicts': items,
'version': version,
'time': time.time() - at,
}
return web.json_response(resp)
app = web.Application()
app.add_routes([
web.get('/status', status),
web.post('/', parser),
])
if __name__ == '__main__':
web.run_app(app, port=64465)