From 464fcbd3a20aaae80c0ab842c90fffef304aaa38 Mon Sep 17 00:00:00 2001 From: NLmeng Date: Sat, 1 Apr 2023 19:37:17 +0000 Subject: [PATCH] autopep8 action fixes --- algorithms/CenterRowAlgorithm.py | 2 +- algorithms/CheckRowEnd.py | 2 +- algorithms/HoughAlgorithm.py | 2 +- algorithms/MiniContoursAlgorithm.py | 4 +- algorithms/MiniContoursDownwards.py | 3 +- algorithms/ScanningAlgorithm.py | 2 +- algorithms/SeesawAlgorithm.py | 2 +- algorithms/SeesawAlgorithmVersionTwo.py | 6 +- gui.py | 78 +++++++++++++++++++------ pre_process.py | 2 +- test_pf.py | 4 +- 11 files changed, 77 insertions(+), 30 deletions(-) diff --git a/algorithms/CenterRowAlgorithm.py b/algorithms/CenterRowAlgorithm.py index 3e6759f..1a78c87 100644 --- a/algorithms/CenterRowAlgorithm.py +++ b/algorithms/CenterRowAlgorithm.py @@ -55,7 +55,7 @@ def update_lower_hsv(self, next): def update_upper_hsv(self, next): self.HIGH_GREEN = np.array(next) - + def process_frame(self, frame, show): """Uses contouring to create contours around each crop row and uses these contours to find centroid lines, row vanishing point, a center contour and the angle between the center contour and vanishing point\n diff --git a/algorithms/CheckRowEnd.py b/algorithms/CheckRowEnd.py index 3f1588a..5691d90 100644 --- a/algorithms/CheckRowEnd.py +++ b/algorithms/CheckRowEnd.py @@ -27,7 +27,7 @@ def update_lower_hsv(self, next): def update_upper_hsv(self, next): self.HIGH_GREEN = np.array(next) - + def process_frame(self, frame, show): """Averages values in each row in a mask of the frame. If the number of rows with an average value of zero is greater than req_rows_empty, then frame is row end\n diff --git a/algorithms/HoughAlgorithm.py b/algorithms/HoughAlgorithm.py index 18d4223..577c14d 100644 --- a/algorithms/HoughAlgorithm.py +++ b/algorithms/HoughAlgorithm.py @@ -42,7 +42,7 @@ def update_lower_hsv(self, next): def update_upper_hsv(self, next): self.HIGH_GREEN = np.array(next) - + # processFrame function that is called to process a frame of a video # takes in frame mat object obtained from cv2 video.read() def process_frame(self, frame, show=True): diff --git a/algorithms/MiniContoursAlgorithm.py b/algorithms/MiniContoursAlgorithm.py index ebd021f..3961522 100644 --- a/algorithms/MiniContoursAlgorithm.py +++ b/algorithms/MiniContoursAlgorithm.py @@ -11,6 +11,8 @@ cmask = "" + + class MiniContoursAlgorithm(Algorithm): # applies hsv binarization to the image # slices the image into horizontal strips and finds all the contours in each strip @@ -215,7 +217,7 @@ def update_lower_hsv(self, next): def update_upper_hsv(self, next): self.HIGH_GREEN = np.array(next) - + def process_frame(self, original_frame, num_strips=60, show=False): # original_frame: BGR frame diff --git a/algorithms/MiniContoursDownwards.py b/algorithms/MiniContoursDownwards.py index 4ededeb..63c9e3d 100644 --- a/algorithms/MiniContoursDownwards.py +++ b/algorithms/MiniContoursDownwards.py @@ -8,6 +8,7 @@ cmask = "" + class MiniContoursDownwards(): def __init__(self, config): @@ -166,7 +167,7 @@ def update_lower_hsv(self, next): def update_upper_hsv(self, next): self.HIGH_GREEN = np.array(next) - + def process_frame(self, original_frame, num_strips=60, show=False): """"" parameters: diff --git a/algorithms/ScanningAlgorithm.py b/algorithms/ScanningAlgorithm.py index 637e04a..04cf54b 100644 --- a/algorithms/ScanningAlgorithm.py +++ b/algorithms/ScanningAlgorithm.py @@ -84,7 +84,7 @@ def update_lower_hsv(self, next): def update_upper_hsv(self, next): self.HIGH_GREEN = np.array(next) - + def process_frame(self, frame, show): hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV) diff --git a/algorithms/SeesawAlgorithm.py b/algorithms/SeesawAlgorithm.py index 0ff6b94..465264a 100644 --- a/algorithms/SeesawAlgorithm.py +++ b/algorithms/SeesawAlgorithm.py @@ -33,7 +33,7 @@ def update_lower_hsv(self, next): def update_upper_hsv(self, next): self.HIGH_GREEN = np.array(next) - + def process_frame(self, frame, show): black_frame, points, both_points = self.plot_points(frame) diff --git a/algorithms/SeesawAlgorithmVersionTwo.py b/algorithms/SeesawAlgorithmVersionTwo.py index ff6d786..a1cc6b8 100644 --- a/algorithms/SeesawAlgorithmVersionTwo.py +++ b/algorithms/SeesawAlgorithmVersionTwo.py @@ -69,7 +69,7 @@ def process_frame(self, frame, show): # calculate angle if y1 - y2 != 0: angle = round(math.degrees(math.atan(int(x2 - x1) / int(y1 - y2))), 1) - bias = round(numpy.average(overall_bias)/(self.WIDTH/2)*90, 2) + bias = round(numpy.average(overall_bias) / (self.WIDTH / 2) * 90, 2) if abs(angle) > abs(bias): output = angle @@ -90,7 +90,7 @@ def plot_points(self, frame): :param frame: current frame (mat) :return: processed frame (mat), list of centre points """ - frame = cv.line(frame, (int(self.WIDTH/2), 0), (int(self.WIDTH/2), int(self.HEIGHT)), (255, 0, 255), 9) + frame = cv.line(frame, (int(self.WIDTH / 2), 0), (int(self.WIDTH / 2), int(self.HEIGHT)), (255, 0, 255), 9) bar_height = int(self.BAR_HEIGHT) mask = self.create_binary_mask(frame) @@ -112,7 +112,7 @@ def plot_points(self, frame): if points.any(): centre = int(numpy.median(points)) - bias = int(centre - self.WIDTH/2) + bias = int(centre - self.WIDTH / 2) black_frame = cv.circle(black_frame, [int(centre), int((square_high + square_low) / 2)], radius=0, color=(0, 0, 255), thickness=15) centre_points.append([centre, int((square_high + square_low) / 2)]) diff --git a/gui.py b/gui.py index b7aa6a9..f5a68ef 100644 --- a/gui.py +++ b/gui.py @@ -1,4 +1,4 @@ -import tkinter as tk # change to Tkinter for python2 +import tkinter as tk # change to Tkinter for python2 import cv2 as cv import numpy as np @@ -61,7 +61,11 @@ def __init__(self, master, img_dict, window_name): for i, (img_name, img_array) in enumerate(img_dict.items(), 1): radiobutton = tk.Radiobutton( - self.scrollable_frame, text=img_name, variable=self.var, value=i, command=lambda i=i: self.update_frameType(i)) + self.scrollable_frame, + text=img_name, + variable=self.var, + value=i, + command=lambda i=i: self.update_frameType(i)) radiobutton.pack(pady=5, side="bottom") self.brightness_scale = tk.Scale(self.scrollable_frame, from_=0, to=255, orient="horizontal", @@ -77,12 +81,12 @@ def __init__(self, master, img_dict, window_name): # Create a Frame to hold both the upper and lower frames self.center_frame = tk.Frame(self.scrollable_frame) self.center_frame.pack(in_=self.scrollable_frame, anchor="c", side="bottom") - + self.lower_frame = tk.Frame(self.center_frame) self.lower_frame.pack(in_=self.center_frame, anchor="c", side="left", ipady=15) self.upper_frame = tk.Frame(self.center_frame) self.upper_frame.pack(in_=self.center_frame, anchor="c", side="right", ipadx=15) - + self.alert_for_hsv = tk.Label( self.lower_frame, text="", fg="red") self.alert_for_hsv.pack(side="top", anchor="c") @@ -142,39 +146,81 @@ def __init__(self, master, img_dict, window_name): # self.update_btn_high.pack(pady=0, side="left") # Create the three sliders for MIN Hue, Saturation, and Value - self.min_hue_slider = tk.Scale(self.lower_frame, from_=0, to=255, orient="horizontal", label="Min Hue", command=self.update_min_color_canvas) + self.min_hue_slider = tk.Scale( + self.lower_frame, + from_=0, + to=255, + orient="horizontal", + label="Min Hue", + command=self.update_min_color_canvas) self.min_hue_slider.set(self.LOWER_GREEN[0]) self.min_hue_slider.pack() - self.min_saturation_slider = tk.Scale(self.lower_frame, from_=0, to=255, orient="horizontal", label="Min Saturation", command=self.update_min_color_canvas) + self.min_saturation_slider = tk.Scale( + self.lower_frame, + from_=0, + to=255, + orient="horizontal", + label="Min Saturation", + command=self.update_min_color_canvas) self.min_saturation_slider.set(self.LOWER_GREEN[1]) self.min_saturation_slider.pack() - self.min_value_slider = tk.Scale(self.lower_frame, from_=0, to=255, orient="horizontal", label="Min Value", command=self.update_min_color_canvas) + self.min_value_slider = tk.Scale( + self.lower_frame, + from_=0, + to=255, + orient="horizontal", + label="Min Value", + command=self.update_min_color_canvas) self.min_value_slider.set(self.LOWER_GREEN[2]) self.min_value_slider.pack() self.min_color_canvas = tk.Canvas(self.lower_frame, width=20, height=20, bg="#000000") self.min_color_canvas.pack() - self.min_color_update_button = tk.Button(self.lower_frame, text="Update Min Color", command=self.update_min_color) + self.min_color_update_button = tk.Button( + self.lower_frame, + text="Update Min Color", + command=self.update_min_color) self.min_color_update_button.pack() # Create the three sliders for MAX Hue, Saturation, and Value - self.max_hue_slider = tk.Scale(self.upper_frame, from_=0, to=255, orient="horizontal", label="Max Hue", command=self.update_max_color_canvas) + self.max_hue_slider = tk.Scale( + self.upper_frame, + from_=0, + to=255, + orient="horizontal", + label="Max Hue", + command=self.update_max_color_canvas) self.max_hue_slider.set(self.UPPER_GREEN[0]) self.max_hue_slider.pack() - self.max_saturation_slider = tk.Scale(self.upper_frame, from_=0, to=255, orient="horizontal", label="Max Saturation", command=self.update_max_color_canvas) + self.max_saturation_slider = tk.Scale( + self.upper_frame, + from_=0, + to=255, + orient="horizontal", + label="Max Saturation", + command=self.update_max_color_canvas) self.max_saturation_slider.set(self.UPPER_GREEN[1]) self.max_saturation_slider.pack() - self.max_value_slider = tk.Scale(self.upper_frame, from_=0, to=255, orient="horizontal", label="Max Value", command=self.update_max_color_canvas) + self.max_value_slider = tk.Scale( + self.upper_frame, + from_=0, + to=255, + orient="horizontal", + label="Max Value", + command=self.update_max_color_canvas) self.max_value_slider.set(self.UPPER_GREEN[2]) self.max_value_slider.pack() self.max_color_canvas = tk.Canvas(self.upper_frame, width=20, height=20, bg="#000000") self.max_color_canvas.pack() - self.max_color_update_button = tk.Button(self.upper_frame, text="Update Max Color", command=self.update_max_color) + self.max_color_update_button = tk.Button( + self.upper_frame, + text="Update Max Color", + command=self.update_max_color) self.max_color_update_button.pack() # # @@ -235,8 +281,6 @@ def update_max_color(self): self.alert_for_hsv.config( text=warning) - - def update_upper_hsv(self): upper_h = int(self.up_h_entry.get()) upper_s = int(self.up_s_entry.get()) @@ -365,7 +409,7 @@ def render_image(self): self.img_container.image = curr_img self.fps_label.config( text="Frames Per Second: ~" + str(self.fps), padx=10, pady=10) - + self.master.update() def isActive(self): @@ -396,7 +440,7 @@ def startGUI(window_name, **kwargs): raise KeyError("kwargs is empty in startGUI(), start with name1= ... ") for key, value in kwargs.items(): - if key == curr_name+str(curr_index): + if key == curr_name + str(curr_index): frame_type = value img_dict[frame_type] = np.zeros((100, 100)) curr_index += 1 @@ -408,4 +452,4 @@ def startGUI(window_name, **kwargs): isActive = True root.protocol("WM_DELETE_WINDOW", onClose) app = GUI(root, img_dict, window_name) - return app \ No newline at end of file + return app diff --git a/pre_process.py b/pre_process.py index 3cc92d7..f8b4f8f 100644 --- a/pre_process.py +++ b/pre_process.py @@ -152,7 +152,7 @@ def standardize_frame(img): try: hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV) - except: + except BaseException: img_float32 = np.float32(img) hsv = cv2.cvtColor(img_float32, cv2.COLOR_BGR2HSV) diff --git a/test_pf.py b/test_pf.py index b77c784..e9afd0b 100644 --- a/test_pf.py +++ b/test_pf.py @@ -40,9 +40,9 @@ CheckRowEnd), ('seesaw', SeesawAlgorithm), - ('seesaw_v2', + ('seesaw_v2', SeesawAlgorithmVersionTwo) - ] +] # number_of_frames = 0