From 0b7b1bed070d194923ccaa591d059ee8f519e233 Mon Sep 17 00:00:00 2001 From: Prohurtz <48768484+RedHawk989@users.noreply.github.com> Date: Sat, 23 Sep 2023 14:47:58 -0500 Subject: [PATCH] limit image size to 480 to prevent issues macos fixes --- EyeTrackApp/camera.py | 12 ++++++++++-- EyeTrackApp/leap.py | 7 +++++-- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/EyeTrackApp/camera.py b/EyeTrackApp/camera.py index 497e536..8e35daa 100644 --- a/EyeTrackApp/camera.py +++ b/EyeTrackApp/camera.py @@ -5,7 +5,7 @@ import serial import serial.tools.list_ports import threading import time - +import platform from colorama import Fore from config import EyeTrackConfig from enum import Enum @@ -113,7 +113,10 @@ class Camera: self.cv2_camera = cv2.VideoCapture() self.cv2_camera.setExceptionMode(True) # https://github.com/opencv/opencv/blob/4.8.0/modules/videoio/include/opencv2/videoio.hpp#L803 - self.cv2_camera.open(self.current_capture_source, cv2.CAP_FFMPEG, params=OPENCV_PARAMS) + if platform.system() == "Darwin": + self.cv2_camera.open(self.current_capture_source) #MacOS + else: + self.cv2_camera.open(self.current_capture_source, cv2.CAP_FFMPEG, params=OPENCV_PARAMS) should_push = False else: # We don't have a capture source to try yet, wait for one to show up in the GUI. @@ -137,6 +140,11 @@ class Camera: def get_cv2_camera_picture(self, should_push): try: ret, image = self.cv2_camera.read() + height, width = image.shape[:2] # Calculate the aspect ratio + aspect_ratio = float(width) / float(height) # Determine the new height based on the desired maximum width + new_height = int(680 / aspect_ratio) + image = cv2.resize(image, (680, new_height)) + # image = cv2.resize(image, (480, 480)) if not ret: self.cv2_camera.set(cv2.CAP_PROP_POS_FRAMES, 0) raise RuntimeError("Problem while getting frame") diff --git a/EyeTrackApp/leap.py b/EyeTrackApp/leap.py index 6177d01..f6be09d 100644 --- a/EyeTrackApp/leap.py +++ b/EyeTrackApp/leap.py @@ -39,7 +39,7 @@ from one_euro_filter import OneEuroFilter import psutil, os import sys from utils.misc_utils import resource_path - +import platform frames = 0 def run_model(input_queue, output_queue, session): @@ -77,7 +77,10 @@ class LEAP_C(object): # Config variables self.num_threads = 3 # Number of python threads to use (using ~1 more than needed to achieve wanted fps yields lower cpu usage) self.queue_max_size = 1 # Optimize for best CPU usage, Memory, and Latency. A maxsize is needed to not create a potential memory leak. - self.model_path = resource_path('Models/mommy072623.onnx') + if platform.system() == "Darwin": + self.model_path = resource_path('EyeTrackApp/Models/mommy072623.onnx') # funny MacOS files issues :P + else: + self.model_path = resource_path('Models/mommy072623.onnx') self.interval = 1 # FPS print update rate self.low_priority = True # set process priority to low self.print_fps = True