From 95fcb2e16a4481dd2ea48433d719ffb27faca0ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BE=8E=E4=B8=AD=E4=BD=9C=E4=B9=90?= <2069209493@qq.com> Date: Thu, 20 Jun 2024 15:39:31 +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: 美中作乐 <2069209493@qq.com> --- obj_tkinterapp.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/obj_tkinterapp.py b/obj_tkinterapp.py index e757eb2..b6e1027 100644 --- a/obj_tkinterapp.py +++ b/obj_tkinterapp.py @@ -7,6 +7,8 @@ import numpy as np # 导入 numpy 作为 np,用于处理数组 import logging # 导入日志模块,方便查看程序运行状态 import utils # 导入 utils.py 文件,用于初始化模型和处理图像 import os # 导入 os 模块,用于获取文件路径 +from utils import init_model, process_frame + # 设置日志 logging.basicConfig( @@ -121,9 +123,13 @@ 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 +186,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) @@ -214,4 +220,4 @@ class Application: # 创建一个窗口并将其传递给 Application 对象 -App = Application(tk.Tk(), "Tkinter and OpenCV") +App = Application(tk.Tk(), "Tkinter and OpenCV") \ No newline at end of file -- Gitee