Capturing images using libcamera in Microchip platforms

Last modified by Microchip on 2025/06/09 11:08

Introduction

libcamera is an open-source software library handling image signal processors and embedded cameras that is supported on Linux based distributions. Refer libcamera architecture to know more about the architecture

Here is a block diagram from the official libcamera page

--------------------------< libcamera Public API >---------------------------
              ^                                          ^
              |                                          |
              v                                          v
       +-------------+  +---------------------------------------------------+
       |   Camera    |  |  Camera Device                                    |
       |   Manager   |  | +-----------------------------------------------+ |
       +-------------+  | | Device-Agnostic                               | |
              ^         | |                                               | |
              |         | |                    +--------------------------+ |
              |         | |                    |   ~~~~~~~~~~~~~~~~~~~~~~~  |
              |         | |                    |  {  +-----------------+  } |
              |         | |                    |  }  | //// Image //// |  { |
              |         | |                    | <-> | / Processing // |  } |
              |         | |                    |  }  | / Algorithms // |  { |
              |         | |                    |  {  +-----------------+  } |
              |         | |                    |   ~~~~~~~~~~~~~~~~~~~~~~~  |
              |         | |                    | ========================== |
              |         | |                    |     +-----------------+    |
              |         | |                    |     | // Pipeline /// |    |
              |         | |                    | <-> | /// Handler /// |    |
              |         | |                    |     | /////////////// |    |
              |         | +--------------------+     +-----------------+    |
              |         |                                   Device-Specific |
              |         +---------------------------------------------------+
              |                          ^                         ^
              |                          |                         |
              v                          v                         v
       +--------------------------------------------------------------------+
       | Helpers and Support Classes                                        |
       | +-------------+  +-------------+  +-------------+  +-------------+ |
       | |  MC & V4L2  |  |   Buffers   |  | Sandboxing  |  |   Plugins   | |
       | |   Support   |  |  Allocator  |  |     IPC     |  |   Manager   | |
       | +-------------+  +-------------+  +-------------+  +-------------+ |
       | +-------------+  +-------------+                                   |
       | |  Pipeline   |  |     ...     |                                   |
       | |   Runner    |  |             |                                   |
       | +-------------+  +-------------+                                   |
       +--------------------------------------------------------------------+

         /// Device-Specific Components
         ~~~ Sandboxing

Traditionally the camera interfaces in linux4sam platforms are configured using media-ctl and v4l2-ctl commands. Each entities in the pipeline has to be configured separately. Libcamera provides a higher level, flexible interface to manage this complexity.

It abstracts away the hardware differences and provides a consistent interface making it easier for application developers to support multiple devices. It provides control over camera pipelines, including white balance, gain and sensor tuning which is very critical for high quality image capture.

Microchip specific pipeline handler

In libcamera, a pipeline handler is a core component responsible for interfacing with camera hardware. It manages the media devices, configures the camera pipeline, and handles image capture operations. Each hardware platform typically requires a specific pipeline handler to accommodate its unique architecture and capabilities.The pipeline handler is a component of libcamera that is device specific. It manages the complex pipelines exposed by the kernel drivers through the Media Controller and V4L2 APIs. You can find the supported devices in the libcamera source in the following path src/libcamera/pipeline. The microchip ISC pipeline handler is implemented here

Capturing images using mchpcam-still

mchpcam-still is a comprehensive userspace demo application that can configure the microchip ISC and capture images. The application supports various image processing options and algorithms that are explained below with few examples.

Features in mchpcam-still

root@sama7g5ek-sd:~# mchpcam-still -h
Usage: mchpcam-still [options]
Camera options:
        -c, --camera=CAMERA          Camera index or name
        -o, --output=FILE            Output file name (default: output.jpg)
        -f, --format=FORMAT          Set pixel format (YUYV, RGB565)
        --width=WIDTH                Set capture width
        --height=HEIGHT              Set capture height

Image options:
        --jpeg-quality=VALUE         Set JPEG quality (1-100, default: 95)
        --png-compression=VALUE      Set PNG compression level (0-9, default: 6)
        --raw                        Save raw sensor data instead of processed image
        --image-format=FORMAT        Set output image format (jpeg, png, raw)

Image processing options:
        --brightness=VALUE           Set brightness (-100 to 100)
        --contrast=VALUE             Set contrast (0 to 100)
        --gamma=VALUE                Set gamma (0 to 2)
        --enable-processing          Enable software image processing

White balance options:
        --awb=MODE                   Set white balance mode (auto, daylight, cloudy, tungsten, fluorescent, shade, manual)
        --awb-enable                 Enable auto white balance
        --red-gain=VALUE             Set red component gain (0 to 8191)
        --blue-gain=VALUE            Set blue component gain (0 to 8191)
        --green-red-gain=VALUE       Set green-red component gain (0 to 8191)
        --green-blue-gain=VALUE      Set green-blue component gain (0 to 8191)
        --red-offset=VALUE           Set red component offset (-4095 to 4095)
        --blue-offset=VALUE          Set blue component offset (-4095 to 4095)
        --green-red-offset=VALUE     Set green-red component offset (-4095 to 4095)
        --green-blue-offset=VALUE    Set green-blue component offset (-4095 to 4095)

Algorithm options:
        --enable-agc                 Enable Automatic Gain Control
        --enable-blc                 Enable Black Level Correction
        --enable-ccm                 Enable Color Correction Matrix
        --enable-awb                 Enable Software Auto white balance processing
        --enable-all                 Enable all image processing algorithms

General options:
        -h, --help                   Print this help message

Examples

Capture a basic JPEG image with default settings at 1920x1080 resolution. The image is stored as output.jpg

root@sama7g5ek-sd:~# mchpcam-still
Requested resolution: 1920x1080
[0:14:40.401418600] [278]  INFO Camera camera_manager.cpp:313 libcamera v0.0.0+4886-linux4microchip-2025.04-rc1-dirty (2025-04-29T11:52:14UTC)
[0:14:40.487015400] [279]  WARN CameraSensor camera_sensor.cpp:259 'imx219 1-0010': Recommended V4L2 control 0x009a0922 not supported
[0:14:40.487442400] [279]  WARN CameraSensor camera_sensor.cpp:331 'imx219 1-0010': The sensor kernel driver needs to be fixed
[0:14:40.487654000] [279]  WARN CameraSensor camera_sensor.cpp:333 'imx219 1-0010': See Documentation/sensor_driver_requirements.rst in the libcamera sources forn
[0:14:40.494302600] [279]  WARN CameraSensor camera_sensor.cpp:479 'imx219 1-0010': Failed to retrieve the camera location
[0:14:40.494579000] [279]  WARN CameraSensor camera_sensor.cpp:501 'imx219 1-0010': Rotation control not available, default to 0 degrees
[0:14:40.500917800] [279]  WARN V4L2 v4l2_pixelformat.cpp:344 Unsupported V4L2 pixel format AR12
[0:14:40.501554000] [279]  WARN V4L2 v4l2_pixelformat.cpp:344 Unsupported V4L2 pixel format AR15
[0:14:40.503753200] [279]  WARN V4L2 v4l2_pixelformat.cpp:344 Unsupported V4L2 pixel format AR12
[0:14:40.504289200] [279]  WARN V4L2 v4l2_pixelformat.cpp:344 Unsupported V4L2 pixel format AR15
[0:14:40.506403400] [279]  WARN V4L2 v4l2_pixelformat.cpp:344 Unsupported V4L2 pixel format AR12
[0:14:40.506860400] [279]  WARN V4L2 v4l2_pixelformat.cpp:344 Unsupported V4L2 pixel format AR15
[0:14:40.509049000] [279]  WARN V4L2 v4l2_pixelformat.cpp:344 Unsupported V4L2 pixel format AR12
[0:14:40.509498400] [279]  WARN V4L2 v4l2_pixelformat.cpp:344 Unsupported V4L2 pixel format AR15
[0:14:40.511733400] [279]  WARN V4L2 v4l2_pixelformat.cpp:344 Unsupported V4L2 pixel format AR12
[0:14:40.512180600] [279]  WARN V4L2 v4l2_pixelformat.cpp:344 Unsupported V4L2 pixel format AR15
[0:14:40.514252600] [279]  WARN V4L2 v4l2_pixelformat.cpp:344 Unsupported V4L2 pixel format AR12
[0:14:40.514784200] [279]  WARN V4L2 v4l2_pixelformat.cpp:344 Unsupported V4L2 pixel format AR15
[0:14:40.516905400] [279]  WARN V4L2 v4l2_pixelformat.cpp:344 Unsupported V4L2 pixel format AR12
[0:14:40.517358200] [279]  WARN V4L2 v4l2_pixelformat.cpp:344 Unsupported V4L2 pixel format AR15
[0:14:40.519463600] [279]  WARN V4L2 v4l2_pixelformat.cpp:344 Unsupported V4L2 pixel format AR12
[0:14:40.519906800] [279]  WARN V4L2 v4l2_pixelformat.cpp:344 Unsupported V4L2 pixel format AR15
[0:14:40.522508800] [279]  INFO MicrochipISC microchip-isc.cpp:401 Registered camera '/base/soc/flexcom@e2818000/i2c@600/camera@10'
[0:14:40.524360800] [278]  INFO Camera camera.cpp:1183 configuring streams: (0) 1920x1080-RGB565
Camera configured with format: RGB565 (1920x1080)
Applying Default AWB parameters :
    Red Gain: 1944
    Blue Gain: 3404
    Green-Red Gain: 1103
    Green-Blue Gain: 1619
    Red Offset: 7928
    Blue Offset: 7936
    Green-Red Offset: 7920
    Green-Blue Offset: 7920
Configured for capture: 1920x1080 format: RGB565
Applying Default AWB parameters :
    Red Gain: 1944
    Blue Gain: 3404
    Green-Red Gain: 1103
    Green-Blue Gain: 1619
    Red Offset: 7928
    Blue Offset: 7936
    Green-Red Offset: 7920
    Green-Blue Offset: 7920
Capturing image...
[drivers/media/platform/microchip/microchip-sama7g5-isc.c:isc_sama7g5_config_dpc:301] bay_cfg = 0x1
[drivers/media/platform/microchip/microchip-sama7g5-isc.c:isc_sama7g5_config_dpc:321] ISC_DPC_CFG = 0x40006011
Sequence: 000000 timestamp: 880966700000
[0:14:41.243092200] [279]  WARN ISC_IPA microchip_isc_ipa.cpp:114 Unknown format 0x300f, defaulting to Raw Bayer processing
Captured image with resolution: 1920x1080
Saved JPEG image to output.jpg with quality 95

Capture image with IPA software processing for default settings. This enables awb=auto,agc,ccm by default

root@sama7g5ek-sd:~# mchpcam-still --enable-processing 

Capture a high-quality image with specific resolution:

root@sama7g5ek-sd:~# mchpcam-still --width=1920 --height=1080 --jpeg-quality=100 -o high_quality.jpg

Capture with specific white balance mode:

root@sama7g5ek-sd:~# mchpcam-still --awb=daylight -o daylight_scene.jpg

Enable all software processing:

root@sama7g5ek-sd:~# mchpcam-still --enable-processing --enable-all -o processed.jpg

Capture with custom white balance settings:

root@sama7g5ek-sd:~# mchpcam-still --awb=manual --red-gain=2000 --blue-gain=3500 -o custom_wb.jpg  

Capture at 640x480 resolution with YUV format:

root@sama7g5ek-sd:~# mchpcam-still --width=640 --height=480 --format=YUYV -o small.jpg