Problem / motivation
Currently, cv2.VideoCapture.read() is called synchronously in the main vision loop. Because camera I/O is a blocking operation, the main thread halts and waits for the hardware to return the next frame. This creates artificial latency, slowing down the overall gesture inference pipeline and dropping the effective FPS.
Proposed solution
Decouple the camera I/O from the inference loop by implementing a threaded video capture class. A daemon thread should continuously read frames from the camera into a shared variable, allowing the main gesture loop to instantly grab the freshest frame without waiting for hardware I/O.
Implementation notes
- Create a
ThreadedCamera class in a new utils/camera.py file.
- Initialize a
threading.Thread(target=self._update, args=()) running as a daemon.
- The
_update method continuously reads cap.read() into an instance variable self.frame.
- The main loop simply calls a non-blocking
read() method that returns self.frame instantly.
Would you like to work on this?
Problem / motivation
Currently,
cv2.VideoCapture.read()is called synchronously in the main vision loop. Because camera I/O is a blocking operation, the main thread halts and waits for the hardware to return the next frame. This creates artificial latency, slowing down the overall gesture inference pipeline and dropping the effective FPS.Proposed solution
Decouple the camera I/O from the inference loop by implementing a threaded video capture class. A daemon thread should continuously read frames from the camera into a shared variable, allowing the main gesture loop to instantly grab the freshest frame without waiting for hardware I/O.
Implementation notes
ThreadedCameraclass in a newutils/camera.pyfile.threading.Thread(target=self._update, args=())running as a daemon._updatemethod continuously readscap.read()into an instance variableself.frame.read()method that returnsself.frameinstantly.Would you like to work on this?