how do i signal people that it can take ints now
This commit is contained in:
1 parent
8f6c3969c0
commit
fa32c7b28c
6 files changed
+91
-23
No files matched your search
+4
-4
@@ -12,14 +12,14 @@ logger = logging.getLogger(__name__)
|
||||
# Auto-detect device
|
||||
DEVICE = 0 if torch.cuda.is_available() else "cpu"
|
||||
if DEVICE == 0:
|
||||
logger.info(f"GPU detected! Using CUDA device: {torch.cuda.get_device_name(0)}")
|
||||
logger.info("GPU detected! Using CUDA device: %s", torch.cuda.get_device_name(0))
|
||||
else:
|
||||
logger.info("No GPU detected. Running on CPU.")
|
||||
|
||||
|
||||
class YoloPersonDetector(Model):
|
||||
def __init__(self, model_path: str = "yolo11n.pt"): # Using small model for speed
|
||||
logger.info(f"Loading Person Detector: {model_path}")
|
||||
logger.info("Loading Person Detector: %s", model_path)
|
||||
self.model = YOLO(model_path) # Load model
|
||||
|
||||
def predict(self, input_data: Any) -> List[Detection]:
|
||||
@@ -46,7 +46,7 @@ class YoloPersonDetector(Model):
|
||||
|
||||
class YoloCigaretteDetector(Model):
|
||||
def __init__(self, model_path: str):
|
||||
logger.info(f"Loading Cigarette Detector: {model_path}")
|
||||
logger.info("Loading Cigarette Detector: %s", model_path)
|
||||
self.model = YOLO(model_path)
|
||||
|
||||
def predict(self, input_data: Any) -> List[Detection]:
|
||||
@@ -74,7 +74,7 @@ class YoloCigaretteDetector(Model):
|
||||
|
||||
class YoloClassifier(Verifier):
|
||||
def __init__(self, model_path: str):
|
||||
logger.info(f"Loading Smoking Classifier: {model_path}")
|
||||
logger.info("Loading Smoking Classifier: %s", model_path)
|
||||
self.model = YOLO(model_path)
|
||||
|
||||
def verify(self, input_data: Any) -> float:
|
||||
|
||||
+4
-4
@@ -46,7 +46,7 @@ class SmartEventSink(Sink):
|
||||
self.current_event_writer: Optional[cv2.VideoWriter] = None
|
||||
self.current_event_id = None
|
||||
|
||||
logger.info(f"Initialized SmartEventSink in {output_dir}")
|
||||
logger.info("Initialized SmartEventSink in %s", output_dir)
|
||||
|
||||
def handle(self, frame: Frame):
|
||||
# Always add to buffer if not recording to keep context
|
||||
@@ -146,7 +146,7 @@ class FileAlertStore:
|
||||
def __init__(self, path: str):
|
||||
self.path = path
|
||||
self.file = open(path, "a", encoding="utf-8") # Append mode
|
||||
logger.info(f"Initialized FileAlertStore writing to {path}")
|
||||
logger.info("Initialized FileAlertStore writing to %s", path)
|
||||
|
||||
def handle(self, frame: Frame):
|
||||
if not frame.ticket:
|
||||
@@ -201,7 +201,7 @@ class VideoFileStore:
|
||||
|
||||
# Open metadata file
|
||||
self.meta_file = open(self.metadata_path, "w")
|
||||
logger.info(f"Initialized Async VideoFileStore writing to {output_path}")
|
||||
logger.info("Initialized Async VideoFileStore writing to %s", output_path)
|
||||
self.thread.start()
|
||||
|
||||
def handle(self, frame: Frame):
|
||||
@@ -224,7 +224,7 @@ class VideoFileStore:
|
||||
try:
|
||||
self._process_frame(frame)
|
||||
except Exception as e:
|
||||
logger.error(f"Error processing video output: {e}")
|
||||
logger.error("Error processing video output: %s", e)
|
||||
finally:
|
||||
self.queue.task_done()
|
||||
|
||||
|
||||
@@ -25,6 +25,10 @@ class StreamSource(Protocol):
|
||||
"""Yield frames from source."""
|
||||
...
|
||||
|
||||
def stop(self):
|
||||
"""Stop the source and release resources."""
|
||||
...
|
||||
|
||||
|
||||
class Sink(Protocol):
|
||||
def handle(self, frame: Frame):
|
||||
|
||||
+17
-13
@@ -25,7 +25,7 @@ class FileStreamSource(StreamSource):
|
||||
self._fps = cap.get(cv2.CAP_PROP_FPS) or 30.0
|
||||
cap.release()
|
||||
except Exception as e:
|
||||
logger.warning(f"Could not probe FPS from {path}: {e}")
|
||||
logger.warning("Could not probe FPS from %s: %s", path, e)
|
||||
|
||||
@property
|
||||
def fps(self) -> float:
|
||||
@@ -40,7 +40,7 @@ class FileStreamSource(StreamSource):
|
||||
# Todo: handle image sequence
|
||||
return
|
||||
|
||||
logger.info(f"Opening video file: {self.path}")
|
||||
logger.info("Opening video file: %s", self.path)
|
||||
cap = cv2.VideoCapture(self.path)
|
||||
frame_id = 0
|
||||
while cap.isOpened():
|
||||
@@ -53,31 +53,35 @@ class FileStreamSource(StreamSource):
|
||||
frame_id += 1
|
||||
cap.release()
|
||||
|
||||
def stop(self):
|
||||
"""No-op for file source (stream ends naturally)."""
|
||||
pass
|
||||
|
||||
|
||||
class ThreadedRTSPSource(StreamSource):
|
||||
"""
|
||||
Reads from RTSP stream in a background thread to prevent buffer buildup
|
||||
Reads from RTSP stream or webcam in a background thread to prevent buffer buildup
|
||||
and allow main processing loop to run at its own pace without stalling the decoding.
|
||||
"""
|
||||
|
||||
def __init__(self, rtsp_url: str, queue_size=5):
|
||||
self.rtsp_url = rtsp_url
|
||||
self.queue = Queue(maxsize=queue_size)
|
||||
def __init__(self, source: str | int, queue_size: int = 5):
|
||||
self.source = source
|
||||
self.queue: Queue[Frame] = Queue(maxsize=queue_size)
|
||||
self._fps = 30.0
|
||||
|
||||
# Probe FPS (with timeout safety ideally, but simple here)
|
||||
try:
|
||||
cap = cv2.VideoCapture(self.rtsp_url)
|
||||
cap = cv2.VideoCapture(self.source)
|
||||
if cap.isOpened():
|
||||
self._fps = cap.get(cv2.CAP_PROP_FPS) or 30.0
|
||||
cap.release()
|
||||
except Exception:
|
||||
logger.warning("Could not probe FPS from RTSP source.")
|
||||
logger.warning("Could not probe FPS from source.")
|
||||
|
||||
self.stopped = False
|
||||
self.thread = threading.Thread(target=self._update, daemon=True)
|
||||
self._start()
|
||||
logger.info(f"Initialized ThreadedRTSPSource for {rtsp_url}")
|
||||
logger.info("Initialized ThreadedRTSPSource for %s", source)
|
||||
|
||||
@property
|
||||
def fps(self) -> float:
|
||||
@@ -87,15 +91,15 @@ class ThreadedRTSPSource(StreamSource):
|
||||
self.thread.start()
|
||||
|
||||
def _update(self):
|
||||
logger.info(f"RTSP Thread started for {self.rtsp_url}")
|
||||
cap = cv2.VideoCapture(self.rtsp_url)
|
||||
logger.info("Reader thread started for %s", self.source)
|
||||
cap = cv2.VideoCapture(self.source)
|
||||
frame_id = 0
|
||||
while not self.stopped:
|
||||
if not cap.isOpened():
|
||||
# Try reconnecting
|
||||
logger.warning("RTSP stream not open, retrying...")
|
||||
logger.warning("Stream not open, retrying...")
|
||||
time.sleep(1)
|
||||
cap = cv2.VideoCapture(self.rtsp_url)
|
||||
cap = cv2.VideoCapture(self.source)
|
||||
continue
|
||||
|
||||
ret, frame = cap.read()
|
||||
|
||||
Reference in new issue
Block a user