Skip to content

Commit 30f8d61

Browse files
authored
Merge pull request #18 from nponsard/fix/linting
fix: mypy lint errors
2 parents a9c999e + f462629 commit 30f8d61

File tree

3 files changed

+17
-17
lines changed

3 files changed

+17
-17
lines changed

eyetrackvr_backend/algorithms/ahsf.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -350,15 +350,15 @@ def coarse_detection(img_gray, params):
350350
return pupil_rect_coarse, outer_rect_coarse, max_response_coarse, mu_inner, mu_outer
351351

352352

353-
def fine_detection(frame, pupil_rect_coarse):
353+
def fine_detection(frame: MatLike, pupil_rect_coarse):
354354
valid_ratio = 1.2
355355
boundary = (0, 0, frame.shape[1], frame.shape[0])
356356
valid_rect = intersect_rect(rect_scale(pupil_rect_coarse, valid_ratio), boundary)
357357
img_pupil = frame[
358358
valid_rect[1] : valid_rect[1] + valid_rect[3],
359359
valid_rect[0] : valid_rect[0] + valid_rect[2],
360360
]
361-
img_pupil_blur = cv2.GaussianBlur(img_pupil, (5, 5), 0, 0)
361+
img_pupil_blur = cv2.GaussianBlur(img_pupil, (5, 5), sigmaX=0, sigmaY=0)
362362
edges_filter = detect_edges(img_pupil_blur)
363363
# fit ellipse to edges
364364
contours, hierarchy = cv2.findContours(edges_filter, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_NONE)
@@ -399,12 +399,14 @@ def fine_detection(frame, pupil_rect_coarse):
399399
return pupil_rect_coarse, center
400400

401401

402-
def detect_edges(img_pupil_blur):
402+
def detect_edges(img_pupil_blur: MatLike):
403403
edges = cv2.Canny(img_pupil_blur, 64, 128)
404404

405405
# img_bw = np.zeros_like(img_pupil_blur)
406406
# img_bw[img_pupil_blur > 100] = 255
407-
img_bw = cv2.compare(img_pupil_blur, 100, cv2.CMP_GT)
407+
408+
# The usage is valid, the typing in opencv-python is wrong, see https://github.com/opencv/opencv-python/issues/1008
409+
img_bw = cv2.compare(img_pupil_blur, 100, cv2.CMP_GT) # type: ignore[call-overload]
408410
kernel = cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (5, 5))
409411
img_bw = cv2.dilate(img_bw, kernel)
410412

eyetrackvr_backend/algorithms/ransac.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,13 @@
2929
# ruff: noqa: F841
3030
# TODO: remove this noqa once unused variables have been cleaned up
3131

32+
import platform
3233
import cv2
3334
import numpy as np
3435
from enum import IntEnum
3536

3637
import os
3738
import psutil
38-
import sys
3939
from cv2.typing import MatLike
4040
from ..processes import EyeProcessor
4141
from ..utils import BaseAlgorithm
@@ -44,13 +44,12 @@
4444
from pye3d.detector_3d import Detector3D, DetectorMode
4545

4646
process = psutil.Process(os.getpid()) # set process priority to low
47-
try: # medium chance this does absolutely nothing but eh
48-
sys.getwindowsversion()
49-
except AttributeError:
50-
process.nice(0) # UNIX: 0 low 10 high
47+
if platform.system() == "Windows":
48+
# Ignoring type error appearing on Linux as this is a Windows variable
49+
process.nice(psutil.BELOW_NORMAL_PRIORITY_CLASS) # type: ignore[attr-defined]
5150
process.nice()
5251
else:
53-
process.nice(psutil.BELOW_NORMAL_PRIORITY_CLASS) # Windows
52+
process.nice(0) # UNIX: 0 low 10 high
5453
process.nice()
5554

5655

@@ -284,14 +283,13 @@ def run(self, frame: MatLike, tracker_position: TrackerPosition) -> tuple[EyeDat
284283
hull = []
285284

286285
for cnt in contours:
287-
hull.append(cv2.convexHull(cnt, False))
286+
hull.append(cv2.convexHull(cnt, clockwise=False))
288287
if not hull:
289288
# If empty, go to next loop
290289
pass
291290
try:
292-
293-
cnt = sorted(hull, key=cv2.contourArea)
294-
maxcnt = cnt[-1]
291+
contour = sorted(hull, key=cv2.contourArea)
292+
maxcnt = contour[-1]
295293
# ellipse = cv2.fitEllipse(maxcnt)
296294
ransac_data = fit_rotated_ellipse_ransac(maxcnt.reshape(-1, 2), rng)
297295
print(ransac_data)

eyetrackvr_backend/processes/camera.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,17 +127,17 @@ def connect_serial_camera(self) -> None:
127127
if os.path.islink(capture_source):
128128
capture_source = os.path.realpath(capture_source)
129129
self.logger.info(f"Connecting to serial capture source {self.current_capture_source} ({capture_source})")
130-
if not any(p for p in serial.tools.list_ports.comports() if capture_source in p):
130+
if not any(p for p in serial.tools.list_ports.comports() if capture_source in p.device):
131131
self.logger.warning(f"Serial port `{self.current_capture_source}` (`{capture_source}`) not found, waiting for reconnect.")
132132
self.set_state(CameraState.DISCONNECTED)
133133
time.sleep(COM_PORT_NOT_FOUND_TIMEOUT)
134134
return
135135

136136
try:
137137
self.serial_camera = serial.Serial(port=capture_source, baudrate=3000000, xonxoff=False, dsrdtr=False, rtscts=False)
138-
# The `set_buffer_size` method is only available on Windows
138+
# The `set_buffer_size` method is only available on Windows (we ignore the type error for linux)
139139
if os.name == "nt":
140-
self.serial_camera.set_buffer_size(rx_size=32768, tx_size=32768)
140+
self.serial_camera.set_buffer_size(rx_size=32768, tx_size=32768) # type: ignore[attr-defined]
141141
self.logger.info(f"Serial camera connected to `{self.current_capture_source}` (`{capture_source}`)")
142142
self.set_state(CameraState.CONNECTED)
143143
except Exception:

0 commit comments

Comments
 (0)