-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnoos.py
97 lines (84 loc) · 2.86 KB
/
noos.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
85
86
87
88
89
90
91
92
93
94
95
#!/usr/bin/env python3
import requests
import json
import sys
class noos_class:
def __init__(self, user, psw):
self.header = {
'User-Token': user,
'Accept-Token': psw
}
def send_post(self, filename, url, json_data = None):
# The form to submit
if json_data is not None:
print(json.dumps(json_data))
files = {
'json': (None, json.dumps(json_data), 'application/json'),
'filename': (filename, open(filename, 'rb'))
}
else:
files = {
'filename': (filename, open(filename, 'rb'))
}
try:
response = requests.post(url, headers = self.header, files = files)
except requests.exceptions.RequestException as e: #All request errors
print('\033[91m', e, '\033[0m')
return
return response.json()
#Object recognition
def object_recognition(self, filename):
json = self.send_post(filename, 'https://demo.noos.cloud:9001/object_recognition')
if json is None:
return
if json['error'] == '':
result = self.obj_result(json)
if result == '':
return 'Object not found'
else:
return result
else:
return json['error']
def obj_result(self, json):
max_value = 0
result = ''
for i, obj in enumerate(json['result']):
if (obj['probability'] > max_value):
max_value = obj['probability']
result = obj['label']
return result
#ORB
def keypoints_result(self, json):
keypoints = []
for i, keyp in enumerate(json['keypoints']):
dict = {'x' : keyp['x'], 'y' : keyp['y']}
keypoints.append(dict)
return keypoints
def orb_keypoints(self, filename, threshold):
json = self.send_post(filename,
'https://demo.noos.cloud:9001/orb_query',
{"model": filename, "theta": threshold})
if json is None:
return
if json['error'] == '':
result = self.keypoints_result(json)
if result == '':
print ('No keypoints')
return
else:
return result
else:
print(json['error'])
return
def add_orb_model(self, filename):
json = self.send_post(filename,
'https://demo.noos.cloud:9001/orb_add_model',
{"name": filename})
if json is None:
return 'No reply'
if json['error'] == '':
if json['result'] == False:
return 'Model has not been saved'
else:
return json['error']
return json['result']