Created
July 4, 2024 14:56
-
-
Save yatharthb97/2ee7f1f828bb58f6be79e79f99e84c2d to your computer and use it in GitHub Desktop.
Author chatgpt: for tests
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pylibcamera as plc | |
# Initialize the CameraManager | |
camera_manager = plc.CameraManager() | |
camera_manager.start() | |
# List available cameras | |
cameras = camera_manager.cameras | |
for i, camera in enumerate(cameras): | |
print(f"Camera {i}: {camera}") | |
# Open the first camera | |
camera = cameras[0] | |
camera.acquire() | |
# Configure the camera | |
config = camera.generate_configuration([plc.StreamRole.Viewfinder]) | |
config['size'] = (640, 480) | |
camera.configure(config) | |
# Allocate buffers | |
allocator = plc.FrameBufferAllocator(camera) | |
for stream in config: | |
allocator.allocate(stream) | |
# Start the camera | |
camera.start() | |
# Capture an image | |
request = camera.create_request() | |
buffer = allocator.get_buffers(config[0])[0] | |
request.add_buffer(config[0], buffer) | |
camera.queue_request(request) | |
# Wait for the request to complete | |
completed_request = camera.get_next_completed_request() | |
if completed_request.status == plc.RequestStatus.Complete: | |
buffer = completed_request.get_buffer(config[0]) | |
with open("output.raw", "wb") as f: | |
f.write(buffer.get_data()) | |
# Clean up | |
camera.stop() | |
camera.release() | |
camera_manager.stop() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment