-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDemo.py
More file actions
65 lines (43 loc) · 1.9 KB
/
Demo.py
File metadata and controls
65 lines (43 loc) · 1.9 KB
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
import time
from pathlib import Path
import streamlit as st
import cv2
import os
import numpy as np
import pandas as pd
from modules.inference import inference
st.set_page_config(layout="wide")
def demo():
main_form = st.form("main_form", clear_on_submit=True)
with main_form:
image = st.file_uploader("Выберите изображение", accept_multiple_files=False, type=['jpg', 'png'])
submitted = st.form_submit_button("Запустить")
if submitted:
if image is None:
st.error('Вам необходимо выбрать изображение!', icon="🚨")
else:
file_bytes = np.asarray(bytearray(image.read()), dtype=np.uint8)
opencv_image = cv2.imdecode(file_bytes, 1)
original = opencv_image.copy()
with st.spinner('Обработка изображения'):
img_det, img_match, matched_instances, user_instance, platform = inference(opencv_image)
# res_show = cv2.resize(res, (0,0), fx=0.5, fy=0.5)
show_result(original, img_det, img_match, matched_instances, user_instance, platform)
def show_result(original, detection, match, matches, user_instance, platform):
st.header("Результаты")
st.image(match, channels="BGR")
col1, col2, col3 = st.columns(3)
user_name = user_instance.value1 if user_instance is not None else 'Unknown'
col1.metric("User", f"{user_name}")
col2.metric("Platform", f"{platform}")
col1, col2, col3 = st.columns(3)
for idx, mm in enumerate(matches):
num = idx % 3
if num == 0:
col1.metric(f"{mm.value1}", f"{mm.match_instance.value1}")
elif num == 1:
col2.metric(f"{mm.value1}", f"{mm.match_instance.value1}")
elif num == 2:
col3.metric(f"{mm.value1}", f"{mm.match_instance.value1}")
if __name__ == "__main__":
demo()