|
|
@ -13,6 +13,7 @@ def main():
|
|
|
|
|
|
|
|
|
|
|
|
@app.route("/analyze", methods=["POST"])
|
|
|
|
@app.route("/analyze", methods=["POST"])
|
|
|
|
def analyze():
|
|
|
|
def analyze():
|
|
|
|
|
|
|
|
# Первоначальные проверки.
|
|
|
|
if 'image' not in request.files or request.files['image'].filename == '':
|
|
|
|
if 'image' not in request.files or request.files['image'].filename == '':
|
|
|
|
return {
|
|
|
|
return {
|
|
|
|
'success': False,
|
|
|
|
'success': False,
|
|
|
@ -23,14 +24,25 @@ def analyze():
|
|
|
|
'success': False,
|
|
|
|
'success': False,
|
|
|
|
'error': 'Загрузка онтологии ещё не реализована',
|
|
|
|
'error': 'Загрузка онтологии ещё не реализована',
|
|
|
|
}
|
|
|
|
}
|
|
|
|
img = request.files['image'].read();
|
|
|
|
|
|
|
|
img = numpy.fromstring(img, numpy.uint8)
|
|
|
|
# Подготовка исходного изображения.
|
|
|
|
img = get_image_buf_as_array(img)
|
|
|
|
image_source = request.files['image'].read();
|
|
|
|
|
|
|
|
image_source = numpy.fromstring(image_source, numpy.uint8)
|
|
|
|
|
|
|
|
image_source = get_image_buf_as_array(image_source)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Подготовка прочих данных и выполнение запроса.
|
|
|
|
queries = [ 'QueryGetNotEmpty', 'QueryGetCheck', 'QueryGetEmpty' ]
|
|
|
|
queries = [ 'QueryGetNotEmpty', 'QueryGetCheck', 'QueryGetEmpty' ]
|
|
|
|
results, response = analyze_base('5cc5570b-6ed9-3b33-9db4-bdb8ecb9f890', img, queries)
|
|
|
|
results, response = analyze_base('5cc5570b-6ed9-3b33-9db4-bdb8ecb9f890', image_source, queries)
|
|
|
|
imencoded = cv.imencode(".jpg", results[0].plot())[1]
|
|
|
|
|
|
|
|
|
|
|
|
# Подготовка изображения с ответом.
|
|
|
|
|
|
|
|
image_result = results[0].plot()
|
|
|
|
|
|
|
|
image_result = cv.cvtColor(image_result, cv.COLOR_BGR2RGB)
|
|
|
|
|
|
|
|
image_result = cv.imencode(".jpg", image_result)[1]
|
|
|
|
|
|
|
|
image_result = base64.b64encode(image_result).decode("utf-8")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Вывод ответа.
|
|
|
|
return {
|
|
|
|
return {
|
|
|
|
'success': True,
|
|
|
|
'success': True,
|
|
|
|
'data': response,
|
|
|
|
'data': response,
|
|
|
|
'image': base64.b64encode(imencoded).decode("utf-8"),
|
|
|
|
'image': image_result,
|
|
|
|
}
|
|
|
|
}
|
|
|
|