Skip to content

Commit

Permalink
minor type related fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ShyAssassin committed Dec 27, 2024
1 parent c90661d commit dd189c3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 14 deletions.
6 changes: 3 additions & 3 deletions eyetrackvr_backend/algorithms/ahsf.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def draw_coarse(self, frame, pupil_rect, outer_rect, center_fitting):
cv2.drawMarker(frame, center_fitting, (255, 255, 255), cv2.MARKER_CROSS, 15, 1)

def run(self, frame: MatLike, tracker_position: TrackerPosition) -> tuple[EyeData, MatLike]:
average_color = np.mean(frame)
average_color = np.mean(frame) # type: ignore[arg-type]
# Get the dimensions of the rotated image
height, width = frame.shape
# Determine the size of the square background (choose the larger dimension)
Expand Down Expand Up @@ -196,7 +196,7 @@ def get_empty_array(frame_shape, width_min, width_max, wh_step, xy_step, roi, ra

wh_in_arr = 1 / wh_in_arr # .astype(np.float32)
# wh_out_arr=wh_out_arr.astype(np.float64)
mu_outer_rect = 1 / mu_outer_rect # .astype(np.float32)
mu_outer_rect = 1 / mu_outer_rect.astype(np.float32)
mu_outer_rect2 = -1.0 * mu_outer_rect # cv2.merge([mu_outer_rect,-1.0*mu_outer_rect])

# 1/wh_in_arr == wh_in_arr_mul
Expand Down Expand Up @@ -343,7 +343,7 @@ def coarse_detection(img_gray, params):
in_w[min_loc[1]],
in_h[min_loc[0]],
)
max_response_coarse = -min_response
max_response_coarse = -min_response # type: ignore[assignment]
pupil_rect_coarse = rec_in
outer_rect_coarse = rec_o

Expand Down
19 changes: 8 additions & 11 deletions eyetrackvr_backend/algorithms/ransac.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ class RANSAC(BaseAlgorithm):
def __init__(self, eye_processor: EyeProcessor):
self.ep = eye_processor

def run(self, frame: MatLike, tracker_position: TrackerPosition) -> EyeData:
def run(self, frame: MatLike, tracker_position: TrackerPosition) -> tuple[EyeData, MatLike]:

# frame = self.current_image_gray_clean
kernel = cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (3, 3))
Expand All @@ -250,7 +250,6 @@ def run(self, frame: MatLike, tracker_position: TrackerPosition) -> EyeData:
# To reduce the processing data, blur.
if frame is None:
print("[WARN] Frame is empty")
self.failed = self.failed + 1 # we have failed, move onto next algo
return TRACKING_FAILED
else:
frame_gray = cv2.GaussianBlur(frame, (5, 5), 0)
Expand All @@ -275,11 +274,11 @@ def run(self, frame: MatLike, tracker_position: TrackerPosition) -> EyeData:
try:
opening = cv2.morphologyEx(thresh, cv2.MORPH_OPEN, kernel)
closing = cv2.morphologyEx(opening, cv2.MORPH_CLOSE, kernel)
th_frame = 255 - closing
th_frame = 255 - closing.astype(np.float32)
except Exception as e:
print(e)
# I want to eliminate try here because try tends to be slow in execution.
th_frame = 255 - frame_gray
th_frame = 255 - frame_gray.astype(np.float32)

contours, _ = cv2.findContours(th_frame, cv2.RETR_TREE, cv2.CHAIN_APPROX_NONE)
hull = []
Expand All @@ -301,7 +300,7 @@ def run(self, frame: MatLike, tracker_position: TrackerPosition) -> EyeData:
# go to next loop
pass

cx, cy, w, h, theta = ransac_data
cx, cy, w, h, theta = ransac_data # type: ignore[reportArgumentType]
# print(cx, cy)
# cxi, cyi, wi, hi = int(cx), int(cy), int(w), int(h)

Expand Down Expand Up @@ -334,8 +333,8 @@ def run(self, frame: MatLike, tracker_position: TrackerPosition) -> EyeData:
angle = result_2d["angle"]
result_2d_final["ellipse"] = result_2d
result_2d_final["diameter"] = w
result_2d_final["location"] = (cx, cy)
result_2d_final["confidence"] = 0.99
result_2d_final["location"] = (cx, cy) # type: ignore[assignment]
result_2d_final["confidence"] = 0.99 # type: ignore[assignment]
# result_2d_final["timestamp"] = self.current_frame_number / self.current_fps
# Black magic happens here, but after this we have our reprojected pupil/eye, and all we had
# to do was sell our soul to satan and/or C++.
Expand Down Expand Up @@ -481,11 +480,9 @@ def run(self, frame: MatLike, tracker_position: TrackerPosition) -> EyeData:

print(cx)
try:
self.failed = 0 # we have succeded, continue with this
return EyeData(cx, cy, 1, tracker_position)
return (EyeData(cx, cy, 1, tracker_position), newFrame2)
# return cx, cy, angle, thresh, blink, w, h
except Exception as e:
print(e)
self.failed = self.failed + 1 # we have failed, move onto next algo
# return 0, 0, 0, thresh, blink, 0, 0
return TRACKING_FAILED
return (TRACKING_FAILED, newFrame2)

0 comments on commit dd189c3

Please sign in to comment.