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

Commit

Permalink
autopep8 action fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
NLmeng authored Apr 1, 2023
1 parent 7fe691a commit 464fcbd
Show file tree
Hide file tree
Showing 11 changed files with 77 additions and 30 deletions.
2 changes: 1 addition & 1 deletion algorithms/CenterRowAlgorithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion algorithms/CheckRowEnd.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion algorithms/HoughAlgorithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
4 changes: 3 additions & 1 deletion algorithms/MiniContoursAlgorithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion algorithms/MiniContoursDownwards.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

cmask = ""


class MiniContoursDownwards():

def __init__(self, config):
Expand Down Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion algorithms/ScanningAlgorithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion algorithms/SeesawAlgorithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions algorithms/SeesawAlgorithmVersionTwo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)

Expand All @@ -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)])
Expand Down
78 changes: 61 additions & 17 deletions gui.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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",
Expand All @@ -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")
Expand Down Expand Up @@ -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()
#
#
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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
Expand All @@ -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
return app
2 changes: 1 addition & 1 deletion pre_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
4 changes: 2 additions & 2 deletions test_pf.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@
CheckRowEnd),
('seesaw',
SeesawAlgorithm),
('seesaw_v2',
('seesaw_v2',
SeesawAlgorithmVersionTwo)
]
]
#
number_of_frames = 0

Expand Down

0 comments on commit 464fcbd

Please sign in to comment.