File size: 1,880 Bytes
67f4ecf
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
"""
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()