diff --git a/Python程序设计课程设计报告模板 2024年.doc b/Python程序设计课程设计报告模板 2024年.doc index da73d03..0851e4b 100644 Binary files a/Python程序设计课程设计报告模板 2024年.doc and b/Python程序设计课程设计报告模板 2024年.doc differ diff --git a/~$thon程序设计课程设计报告模板 2024年.doc b/~$thon程序设计课程设计报告模板 2024年.doc new file mode 100644 index 0000000..335f20c Binary files /dev/null and b/~$thon程序设计课程设计报告模板 2024年.doc differ diff --git a/工程/Area_tracking.py b/工程/Area_tracking.py index 9ced093..afb9a4d 100644 --- a/工程/Area_tracking.py +++ b/工程/Area_tracking.py @@ -34,13 +34,13 @@ def main(): # 如果还没有选择颜色区域,显示当前帧并允许用户选择 if not color_selected: - cv2.imshow('Select color area', frame) + cv2.imshow('选择颜色区域', frame) # 用户按下'c'键时,截取当前帧并允许用户选择ROI if cv2.waitKey(1) & 0xFF == ord('c'): # 转换到HSV hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV) - roi = cv2.selectROI('Select color area', hsv) + roi = cv2.selectROI('选择颜色区域', hsv) if roi != (0, 0, 0, 0): # 计算ROI的平均颜色 roi_hsv = hsv[int(roi[1]):int(roi[1] + roi[3]), int(roi[0]):int(roi[0] + roi[2])] @@ -53,9 +53,9 @@ def main(): [min(color_mean[0] + 10, 179), 255, 255]) # print(f"Selected color: {color_mean}, Lower bound: {greenLower}, Upper bound: {greenUpper}") color_selected = True - cv2.destroyWindow('Select color area') + cv2.destroyWindow('选择颜色区域') else: - print("No ROI selected. Exiting...") + print("未选择区域,退出...") break else: diff --git a/工程/Color_tracking.py b/工程/Color_tracking.py index 20c10f0..d492fbd 100644 --- a/工程/Color_tracking.py +++ b/工程/Color_tracking.py @@ -63,6 +63,14 @@ def choose_color(): else: messagebox.showerror("错误", "颜色选择无效") +def update_color_threshold(color_name): + """更新颜色阈值""" + global lower_hsv, upper_hsv, selected_color + # 根据选择的颜色更新颜色阈值 + selected_color = color_name # 更新selected_color + lower_hsv = color_hsv_ranges[color_name]['lower'] + upper_hsv = color_hsv_ranges[color_name]['upper'] + def rgb_to_hsv(rgba): """将RGB颜色转换为HSV颜色""" rgb = rgba[:3] # 忽略alpha通道 @@ -85,6 +93,7 @@ def choose_custom_color(): # 更新自定义颜色的HSV阈值 update_custom_hsv(lower, upper) +# 更新自定义颜色的HSV阈值 def update_custom_hsv(lower, upper): global color_hsv_ranges color_hsv_ranges['custom']['lower'] = lower.astype(np.uint8) @@ -104,6 +113,7 @@ def initialize_gui(): """初始化GUI界面""" global root root = tk.Tk() + root.geometry("200x600") root.title("颜色追踪") # 开始/停止摄像头按钮 start_button = tk.Button(root, text="开始/停止", command=start_camera) @@ -227,9 +237,6 @@ def camera_thread(): (int(prediction[0] + w), int(prediction[1] + h)), (255, 0, 0), 2) - - print(lower_hsv, upper_hsv) - cv2.imshow('Frame', frame) cv2.imshow('Mask', mask) @@ -238,14 +245,6 @@ def camera_thread(): cv2.destroyAllWindows() -def update_color_threshold(color_name): - """更新颜色阈值""" - global lower_hsv, upper_hsv, selected_color - # 根据选择的颜色更新颜色阈值 - selected_color = color_name # 更新selected_color - lower_hsv = color_hsv_ranges[color_name]['lower'] - upper_hsv = color_hsv_ranges[color_name]['upper'] - def main(): """主函数,程序入口""" diff --git a/工程/invoke.py b/工程/invoke.py index ddd0c8a..f507ae9 100644 --- a/工程/invoke.py +++ b/工程/invoke.py @@ -7,13 +7,12 @@ def quit_app(): sys.exit(app.quit()) def main1(): - print("main1 function called") + Color_tracking.main() def main2(): - print("main2 function called") + Area_tracking.main() app = QApplication(sys.argv) - widget = QWidget() widget.resize(300, 200) @@ -29,8 +28,6 @@ quit_button = QPushButton('退出', widget) quit_button.move(200, 50) quit_button.clicked.connect(quit_app) - - widget.show() sys.exit(app.exec())