From 3c609689bd62d764596f92a6656c370f9605fa2c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=99=E9=9B=B7=E9=B8=A3?= <12751416+sun-leiming@user.noreply.gitee.com> Date: Thu, 20 Jun 2024 14:39:53 +0000 Subject: [PATCH] update obj_tkinterapp.py. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 孙雷鸣 <12751416+sun-leiming@user.noreply.gitee.com> --- obj_tkinterapp.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/obj_tkinterapp.py b/obj_tkinterapp.py index e757eb2..ec9b527 100644 --- a/obj_tkinterapp.py +++ b/obj_tkinterapp.py @@ -5,7 +5,7 @@ from PIL import Image, ImageTk # 用于将 OpenCV 处理的图像转换为 tkin from ultralytics import YOLO # 导入 YOLO 对象侦测模型 import numpy as np # 导入 numpy 作为 np,用于处理数组 import logging # 导入日志模块,方便查看程序运行状态 -import utils # 导入 utils.py 文件,用于初始化模型和处理图像 +from utils import init_model, process_frame # 导入 utils.py 文件,用于初始化模型和处理图像 import os # 导入 os 模块,用于获取文件路径 # 设置日志 @@ -121,9 +121,12 @@ class Application: model_opt2 = self.model_var2.get() # TODO: 获取选择的模型内容构建模型的名称 model_name + model_name = 'yolov8' # TODO: 根据 model_name 构建模型完整路径 + if model_opt1 == "定位": + model_path = "./weights/" + model_name + model_opt2 - self.model = # TODO: 利用utils函数获取模型 + self.model = init_model(model_path)# TODO: 利用utils函数获取模型 # 用日志记录当前更改的模型名称 logging.info(f"更改模型为 {model_name}") @@ -180,7 +183,7 @@ class Application: new_height = int(new_width * (height / width)) frame = cv2.resize(frame, (new_width, new_height)) if self.detecting: - frame = # TODO: 仔细阅读本文件中的代码,利用 utils 中相关函数对视频帧进行处理 + frame = process_frame(self.model, frame, True, True)# TODO: 仔细阅读本文件中的代码,利用 utils 中相关函数对视频帧进行处理 self.photo = ImageTk.PhotoImage(image=Image.fromarray(frame)) self.canvas.create_image(0, 0, image=self.photo, anchor=tk.NW) -- Gitee