You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

37 lines
1.2 KiB
Python

import base64
import cv2 as cv
from flask import Flask, redirect, request
import numpy
from imageWorking import get_image_buf_as_array
from main import analyze_base
app = Flask(__name__, static_url_path = "/")
@app.route("/")
def main():
return redirect('index.html')
@app.route("/analyze", methods=["POST"])
def analyze():
if 'image' not in request.files or request.files['image'].filename == '':
return {
'success': False,
'error': 'Укажите изображение',
}
if 'ontology' in request.files and request.files['ontology'].filename != '':
return {
'success': False,
'error': 'Загрузка онтологии ещё не реализована',
}
img = request.files['image'].read();
img = numpy.fromstring(img, numpy.uint8)
img = get_image_buf_as_array(img)
queries = [ 'QueryGetNotEmpty', 'QueryGetCheck', 'QueryGetEmpty' ]
results, response = analyze_base('5cc5570b-6ed9-3b33-9db4-bdb8ecb9f890', img, queries)
imencoded = cv.imencode(".jpg", results[0].plot())[1]
return {
'success': True,
'data': response,
'image': base64.b64encode(imencoded).decode("utf-8"),
}