File size: 1,797 Bytes
0469d65
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/usr/bin/env python3
"""
Test camera access directly
"""

import cv2
import time

def test_camera():
    print("πŸ” Testing camera access...")
    
    # Try to open camera
    cap = cv2.VideoCapture(0)
    
    if not cap.isOpened():
        print("❌ Error: Could not open camera")
        print("   Possible causes:")
        print("   - Camera is being used by another application")
        print("   - Camera permissions not granted")
        print("   - No camera available")
        return False
    
    print("βœ… Camera opened successfully")
    
    # Get camera properties
    width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))
    height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
    fps = int(cap.get(cv2.CAP_PROP_FPS))
    
    print(f"   Resolution: {width}x{height}")
    print(f"   FPS: {fps}")
    
    # Try to read a frame
    ret, frame = cap.read()
    
    if not ret:
        print("❌ Error: Could not read frame from camera")
        cap.release()
        return False
    
    print("βœ… Successfully read frame from camera")
    print(f"   Frame shape: {frame.shape}")
    
    # Test reading a few frames
    frames_read = 0
    start_time = time.time()
    
    for i in range(10):
        ret, frame = cap.read()
        if ret:
            frames_read += 1
        time.sleep(0.1)
    
    elapsed = time.time() - start_time
    actual_fps = frames_read / elapsed
    
    print(f"   Read {frames_read}/10 frames successfully")
    print(f"   Actual FPS: {actual_fps:.1f}")
    
    cap.release()
    
    if frames_read >= 8:  # Allow for some dropped frames
        print("βœ… Camera test PASSED")
        return True
    else:
        print("❌ Camera test FAILED - too many dropped frames")
        return False

if __name__ == "__main__":
    test_camera()