Как заставить отображаться изображение? (подробнее ниже)

from PIL import Image, ImageTk
import tkinter as tk
from imageai.Detection import ObjectDetection
import os

window = tk.Tk()
window.title("Наличие работников в опасной зоне")

def red():
    exec_path = os.getcwd()  
    detector = ObjectDetection()
    detector.setModelTypeAsRetinaNet()
    detector.setModelPath(os.path.join(exec_path, "resnet50_coco_best_v2.1.0.h5"))
    detector.loadModel()
    
    custom = detector.CustomObjects(person=True)
    list = detector.detectObjectsFromImage(
        custom_objects=custom,
        input_image=os.path.join(exec_path, "1.png"),
        output_image_path=os.path.join(exec_path, "11.png"),
        minimum_percentage_probability=50,
        display_percentage_probability=False,
        display_object_name=False,
        thread_safe=True
    )
    
    if len(list) == 0:
        label = tk.Label(text="Число работников в красной зоне: " + 
        str(len(list)), width=120, height=3)
        
    if len(list) > 0:
        label = tk.Label(text="Нарушение! Число работников в красной зоне: " + 
        str(len(list)), bg="red", width=120, height=3)
        
    im = Image.open("11.png").resize((750, 500))
    img = ImageTk.PhotoImage(im)
    panel = tk.Label(master=window, image=img, borderwidth=0)
    
    label.pack()
    panel.pack()

def yellow():
    exec_path = os.getcwd()  
    detector = ObjectDetection()
    detector.setModelTypeAsRetinaNet()
    detector.setModelPath(os.path.join(exec_path, "resnet50_coco_best_v2.1.0.h5"))
    detector.loadModel()
    
    custom = detector.CustomObjects(person=True)
    list = detector.detectObjectsFromImage(
        custom_objects=custom,
        input_image=os.path.join(exec_path, "1.png"),
        output_image_path=os.path.join(exec_path, "11.png"),
        minimum_percentage_probability=50,
        display_percentage_probability=False,
        display_object_name=False,
        thread_safe=True
    )
    
    if len(list) <= 3:
        label = tk.Label(text="Число работников в жёлтой зоне: " +
        str(len(list)), width=120, height=3)
        
    if len(list) > 3:
        label = tk.Label(text="Нарушение! Число работников в жёлтой зоне: " +
        str(len(list)), bg="red", width=120, height=3)
    
    im = Image.open("11.png").resize((750, 500))
    img = ImageTk.PhotoImage(im)
    panel = tk.Label(master=window, image=img, borderwidth=0)
    
    label.pack()
    panel.pack()

def blue():
    exec_path = os.getcwd()  
    detector = ObjectDetection()
    detector.setModelTypeAsRetinaNet()
    detector.setModelPath(os.path.join(exec_path, "resnet50_coco_best_v2.1.0.h5"))
    detector.loadModel()
    
    custom = detector.CustomObjects(person=True)
    list = detector.detectObjectsFromImage(
        custom_objects=custom,
        input_image=os.path.join(exec_path, "1.png"),
        output_image_path=os.path.join(exec_path, "11.png"),
        minimum_percentage_probability=50,
        display_percentage_probability=False,
        display_object_name=False,
        thread_safe=True
    )
    
    label = tk.Label(text="Число работников в синей зоне: " + str(len(list)), 
    width=120, height=3)
    
    im = Image.open("11.png").resize((750, 500))
    img = ImageTk.PhotoImage(im)
    panel = tk.Label(master=window, image=img, borderwidth=0)
    
    label.pack()
    panel.pack()
    
btn_red = tk.Button(master=window, width=120, height=3,
text="Красная зона (ни одного работника)",  command=red)
btn_yellow = tk.Button(master=window, width=120, height=3,
text="Жёлтая зона (не более 3 работников)", command=yellow)
btn_blue = tk.Button(master=window, width=120, height=3,
text="Синяя зона (любое число работников)", command=blue)
lbl = tk.Label(text="" , width=120, height=3)

# frm = tk.Frame(master=window, width=120, height=30)

btn_red.pack()
btn_yellow.pack()
btn_blue.pack()
lbl.pack()

window.mainloop()

переименовать в 1.png

файл необходим для работы imageai

В программе после нажатия кнопки функция red, blue или yellow должна выводить в окно ярлык с текстом и изображение 11.png, созданное imageai, но вместо него выводится только пустое белое пространство, хотя его размер считывается корректно. Аналогичная программа вне функции выводит изображение нормально


Ответы (0 шт):