Skip to content

Commit

Permalink
fix: fix visualizer memory leak
Browse files Browse the repository at this point in the history
  • Loading branch information
ShyAssassin committed Jan 6, 2024
1 parent b5075f3 commit 3c67478
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
7 changes: 5 additions & 2 deletions TrackingBackend/app/processes/camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
from multiprocessing import Value
import serial.tools.list_ports
from cv2.typing import MatLike
from queue import Queue, Full
from typing import Final
from queue import Queue
import numpy as np
import ctypes
import serial
Expand Down Expand Up @@ -201,7 +201,10 @@ def preprocess_frame(self, frame: MatLike) -> MatLike:

frame = mat_rotate(frame, self.config.rotation)
# send frame to frontend
self.frontend_queue.put(frame)
try:
self.frontend_queue.put(frame, block=False)
except Full:
pass
frame = mat_crop(self.config.roi_x, self.config.roi_y, self.config.roi_w, self.config.roi_h, frame)

return frame
Expand Down
7 changes: 5 additions & 2 deletions TrackingBackend/app/processes/eye_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from app.config import AlgorithmConfig, TrackerConfig
from app.utils import WorkerProcess, BaseAlgorithm
from cv2.typing import MatLike
from queue import Queue
from queue import Queue, Full
import queue
import cv2

Expand Down Expand Up @@ -48,7 +48,10 @@ def run(self) -> None:
break

self.osc_queue.put(result)
self.frontend_queue.put(current_frame)
try:
self.frontend_queue.put(current_frame, block=False)
except Full:
pass
self.window.imshow(self.process_name(), current_frame)

def shutdown(self) -> None:
Expand Down
4 changes: 2 additions & 2 deletions TrackingBackend/app/tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ def __init__(self, config: EyeTrackConfig, uuid: str, manager: SyncManager, rout
self.osc_queue: Queue[EyeData] = self.manager.Queue()
self.image_queue: Queue[MatLike] = self.manager.Queue()
# Used purely for visualization in the frontend
self.camera_queue: Queue[MatLike] = self.manager.Queue()
self.algo_frame_queue: Queue[MatLike] = self.manager.Queue()
self.camera_queue: Queue[MatLike] = self.manager.Queue(maxsize=15)
self.algo_frame_queue: Queue[MatLike] = self.manager.Queue(maxsize=15)
# processes
self.processor = EyeProcessor(self.tracker_config, self.image_queue, self.osc_queue, self.algo_frame_queue)
self.camera = Camera(self.tracker_config, self.image_queue, self.camera_queue)
Expand Down

0 comments on commit 3c67478

Please sign in to comment.