Skip to content

info

cmd_info(ctx, camera_name=None, camera_codec=VideoCodec.yuyv.name, camera_width=640, camera_height=480) #

Get properties of connected cameras

Source code in cogip/tools/camera/info.py
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
71
72
73
74
75
76
def cmd_info(
    ctx: typer.Context,
    camera_name: Annotated[
        Optional[CameraName],  # noqa
        typer.Option(
            help="Name of the camera (all if not specified)",
            envvar="CAMERA_NAME",
        ),
    ] = None,
    camera_codec: Annotated[
        VideoCodec,
        typer.Option(
            help="Camera video codec",
            envvar="CAMERA_CODEC",
        ),
    ] = VideoCodec.yuyv.name,
    camera_width: Annotated[
        int,
        typer.Option(
            help="Camera frame width",
            envvar="CAMERA_WIDTH",
        ),
    ] = 640,
    camera_height: Annotated[
        int,
        typer.Option(
            help="Camera frame height",
            envvar="CAMERA_HEIGHT",
        ),
    ] = 480,
):
    """Get properties of connected cameras"""
    obj = ctx.ensure_object(dict)
    debug = obj.get("debug", False)

    if debug:
        v4l2py.device.log.setLevel(logging.DEBUG)
    else:
        v4l2py.device.log.setLevel(logging.INFO)

    if camera_name:
        if not Path(camera_name.val).exists():
            logger.error(f"Camera not found: {camera_name}")
            return
        device = v4l2py.Device(camera_name.val)
        try:
            device.open()
        except OSError:
            logger.error(f"Failed to open {camera_name.val}")
            return
        print_device_info(device)
        device.close()
        show_stream(camera_name, camera_codec, camera_width, camera_height)
        return

    for device in v4l2py.iter_video_capture_devices():
        try:
            device.open()
        except OSError:
            pass
        else:
            print_device_info(device)
            device.close()
            print()