Class CameraDesktopService

java.lang.Object
com.serinity.accesscontrol.service.CameraDesktopService

public final class CameraDesktopService extends Object
CameraService handles webcam access and frame capture.
Since:
2026-02-27 CameraDesktopService.java
Version:
1.0
Author:
@ZouariOmar (zouariomar20@gmail.com)
  • Constructor Details

    • CameraDesktopService

      public CameraDesktopService(int cameraIndex)
      Creates a camera service bound to the given camera index.
      Parameters:
      cameraIndex - zero-based camera index
  • Method Details

    • isOpen

      public boolean isOpen()
      Indicates whether the camera is open and usable.
      Returns:
      true when capture is available
    • startCapture

      public Thread startCapture(Consumer<org.opencv.core.Mat> frameConsumer, AtomicBoolean running)
      Starts a background thread that continuously captures frames from the camera and passes each frame to the provided consumer.

      The loop runs as long as running is true and the camera is open. Set running to false to stop capture gracefully.

      Parameters:
      frameConsumer - callback invoked with each captured Mat frame
      running - atomic flag; set to false to stop the loop
      Returns:
      capture thread that was started
    • captureFrame

      public org.opencv.core.Mat captureFrame()
      Captures a single frame from the camera.
      Returns:
      OpenCV Mat containing the frame
    • close

      public void close()
      Releases the camera resources.