Capturing images using libcamera in Microchip platforms

Last modified by Microchip on 2025/11/24 07:26

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 control options:
        --brightness=VALUE           Set brightness (-100 to 100)
        --contrast=VALUE             Set contrast (0 to 100)
        --gamma=VALUE                Set gamma (0 to 2)

White balance control 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)

Image processing options:
        --enable-agc                 Enable Automatic Gain Control
        --disable-agc                Disable Automatic Gain Control
        --enable-ccm                 Enable Color Correction Matrix
        --disable-ccm                Disable Color Correction Matrix
        --enable-awb                 Enable Auto White Balance processing
        --disable-awb                Disable Auto White Balance processing
        --enable-all                 Enable all IPA algorithms
        --disable-all                Disable all IPA algorithms

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


root@sama7g5ek-sd:~# mchpcam-still 
Requested resolution: 1920x1080
[0:01:33.153693200] [256]  INFO Camera camera_manager.cpp:313 libcamera v0.0.0+4933-linux4microchip-2025.04-46-gf7268d4e-dirty (2025-11-20T21:41:40UTC)
[0:01:33.275917400] [257]  WARN CameraSensor camera_sensor.cpp:259 'imx219 1-0010': Recommended V4L2 control 0x009a0922 not supported
[0:01:33.276343000] [257]  WARN CameraSensor camera_sensor.cpp:331 'imx219 1-0010': The sensor kernel driver needs to be fixed
[0:01:33.276561400] [257]  WARN CameraSensor camera_sensor.cpp:333 'imx219 1-0010': See Documentation/sensor_driver_requirements.rst in the libcamera sources for more information
[0:01:33.283437800] [257]  WARN CameraSensor camera_sensor.cpp:479 'imx219 1-0010': Failed to retrieve the camera location
[0:01:33.283731200] [257]  WARN CameraSensor camera_sensor.cpp:501 'imx219 1-0010': Rotation control not available, default to 0 degrees
[0:01:33.292656200] [257]  WARN V4L2 v4l2_pixelformat.cpp:344 Unsupported V4L2 pixel format AR12
[0:01:33.293215000] [257]  WARN V4L2 v4l2_pixelformat.cpp:344 Unsupported V4L2 pixel format AR15
[0:01:33.295589600] [257]  WARN V4L2 v4l2_pixelformat.cpp:344 Unsupported V4L2 pixel format AR12
[0:01:33.296082000] [257]  WARN V4L2 v4l2_pixelformat.cpp:344 Unsupported V4L2 pixel format AR15
[0:01:33.298220400] [257]  WARN V4L2 v4l2_pixelformat.cpp:344 Unsupported V4L2 pixel format AR12
[0:01:33.298672800] [257]  WARN V4L2 v4l2_pixelformat.cpp:344 Unsupported V4L2 pixel format AR15
[0:01:33.301196400] [257]  WARN V4L2 v4l2_pixelformat.cpp:344 Unsupported V4L2 pixel format AR12
[0:01:33.301672200] [257]  WARN V4L2 v4l2_pixelformat.cpp:344 Unsupported V4L2 pixel format AR15
[0:01:33.303834600] [257]  WARN V4L2 v4l2_pixelformat.cpp:344 Unsupported V4L2 pixel format AR12
[0:01:33.304280600] [257]  WARN V4L2 v4l2_pixelformat.cpp:344 Unsupported V4L2 pixel format AR15
[0:01:33.306378600] [257]  WARN V4L2 v4l2_pixelformat.cpp:344 Unsupported V4L2 pixel format AR12
[0:01:33.306947400] [257]  WARN V4L2 v4l2_pixelformat.cpp:344 Unsupported V4L2 pixel format AR15
[0:01:33.309073600] [257]  WARN V4L2 v4l2_pixelformat.cpp:344 Unsupported V4L2 pixel format AR12
[0:01:33.309521400] [257]  WARN V4L2 v4l2_pixelformat.cpp:344 Unsupported V4L2 pixel format AR15
[0:01:33.311793600] [257]  WARN V4L2 v4l2_pixelformat.cpp:344 Unsupported V4L2 pixel format AR12
[0:01:33.312249200] [257]  WARN V4L2 v4l2_pixelformat.cpp:344 Unsupported V4L2 pixel format AR15
[0:01:33.314169600] [257]  INFO MicrochipISC microchip-isc.cpp:774 Registered camera '/base/soc/flexcom@e2818000/i2c@600/camera@10'
[0:01:33.314390000] [257]  INFO MicrochipISC microchip-isc.cpp:778  Camera registration complete with HARDWARE HISTOGRAM support
[0:01:33.316156200] [256]  INFO Camera camera.cpp:1183 configuring streams: (0) 1920x1080-RGB565
[0:01:33.319234800] [257]  INFO ISC_IPA microchip_isc_ipa.cpp:77 Configuring IPA for sensor: imx219 (1920x1080)
[0:01:33.320535400] [257]  INFO MicrochipISC microchip-isc.cpp:896 ✅ IPA configured successfully
[0:01:33.320892600] [257]  INFO MicrochipISC microchip-isc.cpp:914 Camera configuration complete: /base/soc/flexcom@e2818000/i2c@600/camera@10
Camera configured with format: RGB565 (1920x1080)
 AUTOMATIC AWB (Advanced IPA)
 Using advanced IPA AWB algorithms
STILL MODE - Immediate classification
Configured for capture: 1920x1080 format: RGB565
Enabled IPA Algorithms: AWB, AGC, CCM
Capturing image...
[0:01:34.500781000] [257]  INFO V4L2 v4l2_videodevice.cpp:1846 /dev/video1[14:cap]: Zero sequence expected for first frame (got 7)
Sequence: 000007 timestamp: 94530774000
[0:01:34.536466800] [257]  WARN ISC_COMMON common.cpp:38 Invalid channel mean R[1]: 67913.5
[0:01:34.537232200] [257]  WARN ISC_IPA microchip_isc_ipa.cpp:182 Hardware stats validation failed
[0:01:34.538835800] [257]  WARN ISC_COMMON common.cpp:38 Invalid channel mean R[1]: 67913.5
[0:01:34.539426800] [257]  WARN ISC_AWB awb.cpp:63 Invalid image statistics - skipping AWB
[0:01:34.540769400] [257]  WARN ISC_COMMON common.cpp:38 Invalid channel mean R[1]: 67913.5
[0:01:34.586363400] [257]  INFO ISC_CCM ccm.cpp:436 Selected CCM: Daylight_Vivid (score=3.19623)
[0:01:34.599335000] [257]  INFO MicrochipISC microchip-isc.cpp:1427 ✅ AWB values written to ISC hardware
[0:01:34.603161200] [257]  INFO MicrochipISC microchip-isc.cpp:1555 ✅ Sensor hardware controls applied successfully
Captured image with resolution: 1920x1080
 Format conversion completed successfully
Saved JPEG image to output.jpg with quality 95
 File saved successfully!


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

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