Reachy Mini documentation

Take Picture

Hugging Face's logo
Join the Hugging Face community

and get access to the augmented documentation experience

to get started

Take Picture

This example demonstrates how to capture a single frame from Reachy Mini’s camera and save it as an image file.

Run with:

python take_picture.py --backend [default|gstreamer|webrtc]

The captured image will be saved as reachy_mini_picture.jpg in the current directory.


import argparse
import sys
import time

import cv2

from reachy_mini import ReachyMini


def main(backend: str) -> None:
    """Get a frame and take a picture."""
    with ReachyMini(media_backend=backend) as reachy_mini:
        frame = reachy_mini.media.get_frame()
        start_time = time.time()
        while frame is None:
            if time.time() - start_time > 20:
                print("Timeout: Failed to grab frame within 20 seconds.")
                sys.exit(1)
            print("Failed to grab frame. Retrying...")
            frame = reachy_mini.media.get_frame()
            time.sleep(1)

        cv2.imwrite("reachy_mini_picture.jpg", frame)
        print("Saved frame as reachy_mini_picture.jpg")


if __name__ == "__main__":
    parser = argparse.ArgumentParser(
        description="Take a picture using Reachy Mini camera."
    )
    parser.add_argument(
        "--backend",
        type=str,
        choices=["default", "gstreamer", "webrtc"],
        default="default",
        help="Media backend to use.",
    )

    args = parser.parse_args()
    main(backend=args.backend)
Update on GitHub