limit image size to 480 to prevent issues

macos fixes
This commit is contained in:
Prohurtz 2023-09-23 14:47:58 -05:00
parent 916967c560
commit 0b7b1bed07
2 changed files with 15 additions and 4 deletions

View File

@ -5,7 +5,7 @@ import serial
import serial.tools.list_ports import serial.tools.list_ports
import threading import threading
import time import time
import platform
from colorama import Fore from colorama import Fore
from config import EyeTrackConfig from config import EyeTrackConfig
from enum import Enum from enum import Enum
@ -113,6 +113,9 @@ class Camera:
self.cv2_camera = cv2.VideoCapture() self.cv2_camera = cv2.VideoCapture()
self.cv2_camera.setExceptionMode(True) self.cv2_camera.setExceptionMode(True)
# https://github.com/opencv/opencv/blob/4.8.0/modules/videoio/include/opencv2/videoio.hpp#L803 # https://github.com/opencv/opencv/blob/4.8.0/modules/videoio/include/opencv2/videoio.hpp#L803
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) self.cv2_camera.open(self.current_capture_source, cv2.CAP_FFMPEG, params=OPENCV_PARAMS)
should_push = False should_push = False
else: else:
@ -137,6 +140,11 @@ class Camera:
def get_cv2_camera_picture(self, should_push): def get_cv2_camera_picture(self, should_push):
try: try:
ret, image = self.cv2_camera.read() 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: if not ret:
self.cv2_camera.set(cv2.CAP_PROP_POS_FRAMES, 0) self.cv2_camera.set(cv2.CAP_PROP_POS_FRAMES, 0)
raise RuntimeError("Problem while getting frame") raise RuntimeError("Problem while getting frame")

View File

@ -39,7 +39,7 @@ from one_euro_filter import OneEuroFilter
import psutil, os import psutil, os
import sys import sys
from utils.misc_utils import resource_path from utils.misc_utils import resource_path
import platform
frames = 0 frames = 0
def run_model(input_queue, output_queue, session): def run_model(input_queue, output_queue, session):
@ -77,6 +77,9 @@ class LEAP_C(object):
# Config variables # 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.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.queue_max_size = 1 # Optimize for best CPU usage, Memory, and Latency. A maxsize is needed to not create a potential memory leak.
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.model_path = resource_path('Models/mommy072623.onnx')
self.interval = 1 # FPS print update rate self.interval = 1 # FPS print update rate
self.low_priority = True # set process priority to low self.low_priority = True # set process priority to low