-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcamera.py
More file actions
32 lines (25 loc) · 790 Bytes
/
Copy pathcamera.py
File metadata and controls
32 lines (25 loc) · 790 Bytes
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
from picamera2 import Picamera2
import time
def connect_camera():
cam = Picamera2()
config = cam.create_preview_configuration(main={"size": (640, 480), "format": "RGB888"})
cam.configure(config)
cam.start()
print("Camera connected — OV5647 on Tony (Hexapod)")
return cam
def capture_frame(cam):
frame = cam.capture_array()
return frame
def disconnect_camera(cam):
cam.stop()
cam.close()
print("Camera disconnected.")
if __name__ == "__main__":
cam = connect_camera()
time.sleep(1) # warm-up
frame = capture_frame(cam)
print(f"Frame captured: shape={frame.shape}, dtype={frame.dtype}")
# Save a test snapshot
cam.capture_file("snapshot.jpg")
print("Snapshot saved to snapshot.jpg")
disconnect_camera(cam)