Небольшое приведение кода и README в порядок

pull/5/head
Vladislav Moiseev 1 year ago
parent 5da1ecb2e2
commit b7c7f8e066

@ -2,21 +2,23 @@
Сервис: http://kb.athene.tech/swagger-ui/index.html Сервис: http://kb.athene.tech/swagger-ui/index.html
Ручная установка зависимостей: Настройка виртуальной среды и установка зависимостей:
```commandline ```commandline
pip install -r requirements.txt python -m venv --clear .venv
```
Ручная установка зависимостей для mac с Apple Silicon: .venv\Scripts\activate.bat
# или
.\.venv\Scripts\Activate.ps1
# или
source .venv/bin/activate
```commandline python -m pip install -r requirements.txt
pip install -r requirements-mac.txt
``` ```
Запуск: Запуск:
```commandline ```commandline
main.py <Ontology UID> <Image Path> python main.py <Ontology UID> <Image Path>
main.py 5cc5570b-6ed9-3b33-9db4-bdb8ecb9f890 "test-data/lectionAudi/2021-03-12 13-48-31.JPG" python main.py 5cc5570b-6ed9-3b33-9db4-bdb8ecb9f890 "test-data/lectionAudi/2021-03-12 13-48-31.JPG"
``` ```

@ -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,
} }

Loading…
Cancel
Save