Skip to content

Commit

Permalink
Merge pull request #43 from NativeSensors/develop
Browse files Browse the repository at this point in the history
adding lowpass filter for keypoints
  • Loading branch information
PeterWaIIace authored Dec 29, 2024
2 parents a2e808f + 7cb3cc4 commit 3066321
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 3 deletions.
2 changes: 1 addition & 1 deletion examples/simple_example_v3.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

# Set up the screen
screen = pygame.display.set_mode((screen_width, screen_height))
pygame.display.set_caption("EyeGestures v2 example")
pygame.display.set_caption("EyeGestures v3 example")
font_size = 48
bold_font = pygame.font.Font(None, font_size)
bold_font.set_bold(True) # Set the font to bold
Expand Down
8 changes: 7 additions & 1 deletion eyeGestures/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from eyeGestures.calibration_v1 import Calibrator as Calibrator_v1
from eyeGestures.calibration_v2 import Calibrator as Calibrator_v2
from eyeGestures.gevent import Gevent, Cevent
from eyeGestures.utils import timeit, Buffor
from eyeGestures.utils import timeit, Buffor, low_pass_filter_fourier
import numpy as np
import pickle
import time
Expand Down Expand Up @@ -40,6 +40,7 @@ def __init__(self, calibration_radius = 1000):
self.velocity_max = dict()
self.velocity_min = dict()
self.fixationTracker = dict()
self.key_points_buffer = dict()

self.starting_head_position = np.zeros((1,2))
self.starting_size = np.zeros((1,2))
Expand Down Expand Up @@ -130,6 +131,7 @@ def addContext(self, context):
self.velocity_max[context] = 0
self.velocity_min[context] = 100000000
self.fixationTracker[context] = Fixation(0,0,100)
self.key_points_buffer[context] = []


def step(self, frame, calibration, width, height, context="main"):
Expand All @@ -138,6 +140,10 @@ def step(self, frame, calibration, width, height, context="main"):
self.calibration[context] = calibration

key_points, blink, sub_frame = self.getLandmarks(frame)
self.key_points_buffer[context].append(key_points)
if len(self.key_points_buffer[context]) > 10:
self.key_points_buffer[context].pop(0)
key_points = low_pass_filter_fourier(key_points,200)

y_point = self.clb[context].predict(key_points)
self.average_points[context][1:,:] = self.average_points[context][:(self.average_points[context].shape[0] - 1),:]
Expand Down
11 changes: 11 additions & 0 deletions eyeGestures/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,17 @@ def inner(*args, **kwargs):
return ret
return inner

def low_pass_filter_fourier(data, cutoff_frequency):
# Apply Fourier Transform-based filter column-wise
filtered_data = np.zeros_like(data, dtype=float)
for col in range(data.shape[1]): # Iterate over each column
fft_data = np.fft.fft(data[:, col])
frequencies = np.fft.fftfreq(len(data[:, col]))
# Apply the low-pass filter
fft_data[np.abs(frequencies) > cutoff_frequency] = 0
# Perform Inverse Fourier Transform
filtered_data[:, col] = np.fft.ifft(fft_data).real
return filtered_data

def shape_to_np(shape, dtype="int"):
"""
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ exclude = [

[project]
name = "eyeGestures"
version = "3.1.4"
version = "3.2.4"
authors = [
{ name="Piotr Walas", email="[email protected]" },
]
Expand Down

0 comments on commit 3066321

Please sign in to comment.