Как во flet вывести изображение с YoloDeepSort?
Есть приложение на YoloDeepSort и интерфейс к нему на flet. Приложение генерирует покадрово меняющееся изображение (получается видео). Сейчас скрипт приложения запускается через subprocess и изображение выходит в Python окне. Как можно вставить это изображение во flet в виде какого-нибудь окна?
Код вывода изображения:
def draw_boxes(img, bbox, names,object_id, identities=None, offset=(0, 0)):
global count_up
global count_down
height, width, _ = img.shape
# remove tracked point from buffer if object is lost
for key in list(data_deque):
if key not in identities:
data_deque.pop(key)
for i, box in enumerate(bbox):
x1, y1, x2, y2 = [int(i) for i in box]
x1 += offset[0]
x2 += offset[0]
y1 += offset[1]
y2 += offset[1]
# code to find center of bottom edge
center = (int((x2+x1)/ 2), int((y2+y2)/2))
# get ID of object
id = int(identities[i]) if identities is not None else 0
# create new buffer for new object
if id not in data_deque:
data_deque[id] = deque(maxlen= 64)
color = compute_color_for_labels(object_id[i])
obj_name = names[object_id[i]]
label = '{}{:d}'.format("", id) + ":"+ '%s' % (obj_name)
# add center to buffer
data_deque[id].appendleft(center)
if len(data_deque[id]) >= 2:
direction = get_direction(data_deque[id][0], data_deque[id][1])
if intersect(data_deque[id][0], data_deque[id][1], line[0], line[1]):
cv2.line(img, line[0], line[1], (255, 255, 255), 3)
if 'South' in direction:
if obj_name not in object_counter:
object_counter[obj_name] = 1
count_down += 1
else:
object_counter[obj_name] += 1
count_down += 1
if 'North' in direction:
if obj_name not in object_counter1:
object_counter1[obj_name] = 1
count_up += 1
else:
object_counter1[obj_name] += 1
count_up += 1
UI_box(box, img, label=label, color=color, line_thickness=2)
# draw trail
for i in range(1, len(data_deque[id])):
# check if on buffer value is none
if data_deque[id][i - 1] is None or data_deque[id][i] is None:
continue
# generate dynamic thickness of trails
thickness = int(np.sqrt(64 / float(i + i)) * 1.5)
# draw trails
cv2.line(img, data_deque[id][i - 1], data_deque[id][i], color, thickness)
for idx, (key, value) in enumerate(object_counter1.items()):
cnt_str = str(key) + ":" + str(value)
# Cars Entering
cv2.putText(img, f'Count of Vehicles Entering', (width - 500, 35), 0, 1, [225, 255, 255], thickness=2, lineType=cv2.LINE_AA)
###
cv2.putText(img, 'Total Count: ' + str(count_up), (width - 300, 75), 0, 1, [225, 255, 255], thickness=2, lineType=cv2.LINE_AA)
###
cv2.line(img, (width - 150, 95 + (idx*40)), (width, 95 + (idx*40)), 0, 30)
cv2.putText(img, cnt_str, (width -200, 105 + (idx*40)), 0, 1, [255, 255, 255], thickness=2, lineType=cv2.LINE_AA)
for idx, (key, value) in enumerate(object_counter.items()):
cnt_str1 = str(key) + ":" + str(value)
# Cars Leaving
cv2.putText(img, f'Count of Vehicles Leaving', (11, 35), 0, 1, [225, 255, 255], thickness=2, lineType=cv2.LINE_AA)
###
cv2.putText(img, 'Total Count: ' + str(count_down), (11, 75), 0, 1, [225, 255, 255], thickness=2, lineType=cv2.LINE_AA)
###
cv2.line(img, (20, 95 + (idx * 40)), (127, 95 + (idx * 40)), 0, 30)
cv2.putText(img, cnt_str1, (11, 105 + (idx * 40)), 0, 1, [225, 255, 255], thickness=2, lineType=cv2.LINE_AA)
return img