MotionScope-Pro / live_run.py
3v324v23's picture
Initial commit for MotionScope Pro (Docker deployment)
67f4ecf
"""
MotionScope Pro - Live Webcam Analysis
Run this script to see real-time updates in a new window.
Usage: python live_run.py
"""
import cv2
import time
from detector import MovementDetector, DetectionMode
def main():
print("Initializing...")
detector = MovementDetector()
# Try to open webcam
cap = cv2.VideoCapture(0)
if not cap.isOpened():
print("Error: Could not open webcam.")
return
print("Webcam started.")
print("Controls:")
print(" 'q' - Quit")
print(" 'm' - Switch Mode (Hand -> Motion -> Combined)")
mode = DetectionMode.MOTION_DETECTION
print(f"Current Mode: {mode.value}")
try:
while True:
ret, frame = cap.read()
if not ret:
print("Failed to grab frame.")
break
# Mirror effect
frame = cv2.flip(frame, 1)
# Process frame
processed = detector.process_frame(frame, mode)
# Draw HUD
cv2.putText(
processed, f"Mode: {mode.value} (Press 'm' to switch)",
(10, processed.shape[0] - 20),
cv2.FONT_HERSHEY_SIMPLEX, 0.6, (255, 255, 0), 2
)
cv2.imshow("MotionScope Pro (Live)", processed)
# Handle keys
key = cv2.waitKey(1) & 0xFF
if key == ord('q'):
break
elif key == ord('m'):
# Cycle modes
modes = list(DetectionMode)
current_idx = modes.index(mode)
next_idx = (current_idx + 1) % len(modes)
mode = modes[next_idx]
print(f"Switched to: {mode.value}")
finally:
cap.release()
cv2.destroyAllWindows()
detector.release()
print("Resources released.")
if __name__ == "__main__":
main()