forked from openUC2/ImSwitch
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_camera_direct.py
More file actions
68 lines (53 loc) · 1.86 KB
/
test_camera_direct.py
File metadata and controls
68 lines (53 loc) · 1.86 KB
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
#!/usr/bin/env python3
"""
Direct test of the updated CameraTucsen class
"""
import sys
import os
import time
# Add the parent directory to path so we can import
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
# Direct import without going through ImSwitch framework
try:
from imswitch.imcontrol.model.interfaces.tucsencamera import CameraTucsen
print("CameraTucsen imported successfully")
except Exception as e:
print(f"Failed to import CameraTucsen: {e}")
sys.exit(1)
def test_camera_direct():
"""Test camera without full ImSwitch framework"""
print("Testing CameraTucsen directly...")
try:
# Force cleanup first
CameraTucsen.force_cleanup()
# Initialize camera
print("Creating camera instance...")
camera = CameraTucsen(cameraNo=0)
print(f"Camera connected: {camera.is_connected}")
if not camera.is_connected:
print("Camera not connected, exiting")
return
# Test streaming
print("Starting live streaming...")
camera.start_live()
print("Waiting for frames...")
time.sleep(5) # Let it capture some frames
# Check if we got any frames
frame = camera.getLast(returnFrameNumber=False, timeout=2.0)
if frame is not None:
print(f"SUCCESS! Got frame with shape: {frame.shape}")
else:
print("NO FRAMES CAPTURED")
# Stop streaming
print("Stopping streaming...")
camera.stop_live()
# Close camera
print("Closing camera...")
camera.close()
print("Test completed")
except Exception as e:
print(f"Error during test: {e}")
import traceback
traceback.print_exc()
if __name__ == "__main__":
test_camera_direct()