|
|
|
@ -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():
|
|
|
|
|
"""主函数,程序入口"""
|
|
|
|
|