From b7c7f8e066cd8cc35b107987cc1b0c35de49a400 Mon Sep 17 00:00:00 2001 From: Vladislav Moiseev Date: Fri, 7 Jul 2023 22:10:13 +0400 Subject: [PATCH] =?UTF-8?q?=D0=9D=D0=B5=D0=B1=D0=BE=D0=BB=D1=8C=D1=88?= =?UTF-8?q?=D0=BE=D0=B5=20=D0=BF=D1=80=D0=B8=D0=B2=D0=B5=D0=B4=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D0=B5=20=D0=BA=D0=BE=D0=B4=D0=B0=20=D0=B8=20README=20?= =?UTF-8?q?=D0=B2=20=D0=BF=D0=BE=D1=80=D1=8F=D0=B4=D0=BE=D0=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 18 ++++++++++-------- webApp.py | 24 ++++++++++++++++++------ 2 files changed, 28 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 1730407..81b0c3a 100644 --- a/README.md +++ b/README.md @@ -2,21 +2,23 @@ Сервис: http://kb.athene.tech/swagger-ui/index.html -Ручная установка зависимостей: +Настройка виртуальной среды и установка зависимостей: ```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 -pip install -r requirements-mac.txt +python -m pip install -r requirements.txt ``` Запуск: ```commandline -main.py -main.py 5cc5570b-6ed9-3b33-9db4-bdb8ecb9f890 "test-data/lectionAudi/2021-03-12 13-48-31.JPG" +python main.py +python main.py 5cc5570b-6ed9-3b33-9db4-bdb8ecb9f890 "test-data/lectionAudi/2021-03-12 13-48-31.JPG" ``` diff --git a/webApp.py b/webApp.py index a364496..df763ee 100644 --- a/webApp.py +++ b/webApp.py @@ -13,6 +13,7 @@ def main(): @app.route("/analyze", methods=["POST"]) def analyze(): + # Первоначальные проверки. if 'image' not in request.files or request.files['image'].filename == '': return { 'success': False, @@ -23,14 +24,25 @@ def analyze(): 'success': False, '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' ] - results, response = analyze_base('5cc5570b-6ed9-3b33-9db4-bdb8ecb9f890', img, queries) - imencoded = cv.imencode(".jpg", results[0].plot())[1] + results, response = analyze_base('5cc5570b-6ed9-3b33-9db4-bdb8ecb9f890', image_source, queries) + + # Подготовка изображения с ответом. + 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 { 'success': True, 'data': response, - 'image': base64.b64encode(imencoded).decode("utf-8"), + 'image': image_result, }