Skip to content
This repository has been archived by the owner on Sep 5, 2023. It is now read-only.

Commit

Permalink
recommit 'fixed dimension problem, expand smoother, fix bug with lowe…
Browse files Browse the repository at this point in the history
…rhsv'
  • Loading branch information
NLmeng committed Mar 4, 2023
1 parent bc467bb commit d1b4970
Showing 1 changed file with 59 additions and 30 deletions.
89 changes: 59 additions & 30 deletions gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,18 @@ def __init__(self, master, img_dict, window_name):
self.container.pack(side='top', anchor='nw', fill="both", expand=True)

self.canvas = tk.Canvas(self.container)
self.scrollbar = tk.Scrollbar(self.container, orient="vertical", command=self.canvas.yview)
self.scrollbar = tk.Scrollbar(
self.container, orient="vertical", command=self.canvas.yview)
self.scrollable_frame = tk.Frame(self.canvas)
self.scrollable_frame.bind("<Configure>", lambda e: self.canvas.configure(scrollregion=self.canvas.bbox("all")))
self.scrollable_frame.bind("<Configure>", lambda e: self.canvas.configure(
scrollregion=self.canvas.bbox("all")))

self.img_container = tk.Label(self.scrollable_frame)
self.img_container = tk.Label(self.scrollable_frame, padx=10, pady=10)
self.img_container.pack(side='top', fill="both", expand=True)
# self.img_container.config(width=600, height=400)

self.canvas.create_window((0, 0), window=self.scrollable_frame, anchor='c')
self.canvas.create_window(
(0, 0), window=self.scrollable_frame, anchor='c')
self.canvas.configure(yscrollcommand=self.scrollbar.set)

self.canvas.pack(side="left", fill="both", expand=True)
Expand Down Expand Up @@ -70,34 +73,36 @@ def __init__(self, master, img_dict, window_name):
#
#
self.upper_frame = tk.Frame(self.scrollable_frame)
self.upper_frame.pack(in_=self.scrollable_frame, anchor="c", side="bottom")
self.upper_frame.pack(in_=self.scrollable_frame,
anchor="c", side="bottom")
self.lower_frame = tk.Frame(self.scrollable_frame)
self.lower_frame.pack(in_=self.scrollable_frame, anchor="c", side="bottom")
self.lower_frame.pack(in_=self.scrollable_frame,
anchor="c", side="bottom")
self.alert_for_hsv = tk.Label(
self.lower_frame, text="", fg="red")
self.alert_for_hsv.pack(pady=5, side="top")
#
#
self.LOW_GREEN = [35, 80, 80]
self.LOWER_GREEN = [35, 80, 80]
self.low_h_entry_label = tk.Label(self.lower_frame, text="LOWER-H:")
self.low_h_entry_label.pack(pady=5, side="left")
self.low_h_entry = tk.Entry(
self.lower_frame, width=5, justify="center", font="Courier 12")
self.low_h_entry.insert(0, str(self.LOW_GREEN[0]))
self.low_h_entry.insert(0, str(self.LOWER_GREEN[0]))
self.low_h_entry.pack(pady=5, side="left")
#
self.low_s_entry_label = tk.Label(self.lower_frame, text="S:")
self.low_s_entry_label.pack(pady=5, side="left")
self.low_s_entry = tk.Entry(
self.lower_frame, width=5, justify="center", font="Courier 12")
self.low_s_entry.insert(0, str(self.LOW_GREEN[1]))
self.low_s_entry.insert(0, str(self.LOWER_GREEN[1]))
self.low_s_entry.pack(pady=5, side="left")
#
self.low_v_entry_label = tk.Label(self.lower_frame, text="V:")
self.low_v_entry_label.pack(pady=5, side="left")
self.low_v_entry = tk.Entry(
self.lower_frame, width=5, justify="center", font="Courier 12")
self.low_v_entry.insert(0, str(self.LOW_GREEN[2]))
self.low_v_entry.insert(0, str(self.LOWER_GREEN[2]))
self.low_v_entry.pack(pady=5, side="left")
#
self.update_btn_low = tk.Button(
Expand Down Expand Up @@ -139,48 +144,70 @@ def update_upper_hsv(self):
upper_h = int(self.up_h_entry.get())
upper_s = int(self.up_s_entry.get())
upper_v = int(self.up_v_entry.get())
if upper_h > self.LOW_GREEN[0] and upper_s > self.LOW_GREEN[1] and upper_v > self.LOW_GREEN[2]:
if upper_h > self.LOWER_GREEN[0] and upper_s > self.LOWER_GREEN[1] and upper_v > self.LOWER_GREEN[2] and upper_h <= 255 and upper_s <= 255 and upper_v <= 255:
self.UPPER_GREEN = (upper_h, upper_s, upper_v)
self.alert_for_hsv.config(
text="")
text="new UPPER-HSV: " + str(self.UPPER_GREEN))
else:
warning = "INVALID: "
if upper_h <= self.LOWER_GREEN[0]:
warning += "UPPER_H <= LOWER_H\t"
elif upper_s <= self.LOWER_GREEN[1]:
warning += "UPPER_S <= LOWER_S\t"
elif upper_v <= self.LOWER_GREEN[2]:
warning += "UPPER_V <= LOWER_V\t"
else:
warning += "UPPER_V > 255\t"

self.alert_for_hsv.config(
text="Invalid UPPER HSV values")
text=warning)

self.up_h_entry.delete(0, tk.END)
self.up_h_entry.insert(
0, str(self.UPPER_GREEN[0]))
self.up_v_entry.delete(0, tk.END)
self.up_v_entry.insert(
0, str(self.UPPER_GREEN[1]))
self.up_s_entry.delete(0, tk.END)
self.up_s_entry.insert(
0, str(self.UPPER_GREEN[1]))
self.up_v_entry.delete(0, tk.END)
self.up_v_entry.insert(
0, str(self.UPPER_GREEN[2]))
print(self.UPPER_GREEN)
# print(self.UPPER_GREEN)

def update_lower_hsv(self):
lower_h = int(self.low_h_entry.get())
lower_s = int(self.low_s_entry.get())
lower_v = int(self.low_v_entry.get())
if lower_h < self.UPPER_GREEN[0] and lower_s < self.UPPER_GREEN[1] and lower_v < self.UPPER_GREEN[2]:
if lower_h < self.UPPER_GREEN[0] and lower_s < self.UPPER_GREEN[1] and lower_v < self.UPPER_GREEN[2] and lower_h >= 0 and lower_s >= 0 and lower_v >= 0:
self.LOWER_GREEN = (lower_h, lower_s, lower_v)
self.alert_for_hsv.config(
text="")
text="new LOWER-HSV: " + str(self.LOWER_GREEN))
else:
warning = "INVALID: "
if lower_h >= self.UPPER_GREEN[0]:
warning += "UPPER_H <= LOWER_H\t"
elif lower_s >= self.UPPER_GREEN[1]:
warning += "UPPER_S <= LOWER_S\t"
elif lower_v >= self.UPPER_GREEN[2]:
warning += "UPPER_V <= LOWER_V\t"
else:
warning += "LOWER_V < 0\t"

self.alert_for_hsv.config(
text="Invalid LOWER HSV values")
text=warning)

self.low_h_entry.delete(0, tk.END)
self.low_h_entry.insert(
0, str(self.LOW_GREEN[0]))
self.low_v_entry.delete(0, tk.END)
self.low_v_entry.insert(
0, str(self.LOW_GREEN[1]))
0, str(self.LOWER_GREEN[0]))
self.low_s_entry.delete(0, tk.END)
self.low_s_entry.insert(
0, str(self.LOW_GREEN[2]))
print(self.LOW_GREEN)
0, str(self.LOWER_GREEN[1]))
self.low_v_entry.delete(0, tk.END)
self.low_v_entry.insert(
0, str(self.LOWER_GREEN[2]))
# print(self.LOWER_GREEN)

def getLowerHSV(self):
return self.LOW_GREEN
return self.LOWER_GREEN

def getUpperHSV(self):
return self.UPPER_GREEN
Expand Down Expand Up @@ -231,15 +258,17 @@ def render_image(self):
# Resize the image to fit within the available space, while maintaining aspect ratio
new_width = int(img_width * scale_factor)
new_height = int(img_height * scale_factor)
if new_height > 10 and new_width > 10:
new_width -= 10
new_height -= 10
curr_img = curr_img.resize((new_width, new_height), Image.ANTIALIAS)

curr_img = ImageTk.PhotoImage(curr_img)
self.img_container.config(image=curr_img)
self.img_container.config(image=curr_img, padx=10, pady=10)
self.img_container.image = curr_img
self.fps_label.config(
text="Frames Per Second: ~" + str(self.fps))
text="Frames Per Second: ~" + str(self.fps), padx=10, pady=10)
self.master.update()


def isActive(self):
global isActive
Expand Down

0 comments on commit d1b4970

Please sign in to comment.