.. include:: /keyword.rst

=======================================
Camera Integration (MediaTek Imgsensor)
=======================================

.. contents:: Sections
    :local:
    :depth: 1

.. toctree::
    :hidden:

In this section, we will demonstrate how to integrate a new sensor into |G510-G700-EVK|.

Sensor Porting
--------------

The user who wants to use other sensors will need to integrate the sensor driver into MediaTek Imgsensor.
For more details, please refer to the sensor porting guide on `MediaTek On-Line <https://online.mediatek.com/>`_:

.. csv-table:: Sensor Porting Guide For Genio 510
    :header: "Sensor Type", "Document Path"
    :encoding: utf-8
    :width: 100%
    :widths: 10 90

    "RAW", ``IoT/Software/Genio Series SoC/Genio 510/IoT Yocto/Camera/MTK_MT8370_IoT_Yocto_RAW_Image_Sensor_Driver_Development_Guide_v1.4.2.docx``
    "YUV", ``IoT/Software/Genio Series SoC/Genio 510/IoT Yocto/Camera/MTK_MT8370_IoT_Yocto_YUV_Image_Sensor_Driver_Development_Guide_v1.4.2.docx``

.. csv-table:: Sensor Porting Guide For Genio 700
    :header: "Sensor Type", "Document Path"
    :encoding: utf-8
    :width: 100%
    :widths: 10 90

    "RAW", ``IoT/Software/Genio Series SoC/Genio 700/IoT Yocto/Camera/MTK_MT8390_IoT_Yocto_RAW_Image_Sensor_Driver_Development_Guide_v1.4.2.docx``
    "YUV", ``IoT/Software/Genio Series SoC/Genio 700/IoT Yocto/Camera/MTK_MT8390_IoT_Yocto_YUV_Image_Sensor_Driver_Development_Guide_v1.4.2.docx``

Calibration and Tuning
----------------------

Camera Calibration
^^^^^^^^^^^^^^^^^^

In camera sensor calibration, several parameters are calibrated to ensure optimal image quality and accurate performance.
Here is an overview of the key calibration items that the MediaTek calibration tool supports:

* **Optical Black (OB) Calibration**
    The optical black level is subtracted from the image data to remove the dark current and produce a corrected image with better image quality.

* **Auto White Balance (AWB) Calibration**
    This process corrects color temperature variations in different lighting conditions.
    It involves adjusting the camera's white balance settings to accurately reproduce colors under various lighting sources.

* **Auto Exposure (AE) Calibration**
    AE calibration determines the camera's exposure settings to achieve accurate exposure levels in different lighting conditions.
    Through algorithms and analysis, the calibration determines the appropriate exposure time, Gain, ISO sensitivity,
    and other parameters to capture well-exposed images while maintaining details in high-contrast scenes.

* **Lens Shading Calibration**
    Shading refers to variations in brightness or color across the image sensor due to factors like lens vignetting or uneven illumination.
    Shading correction involves estimating the shading pattern across the sensor and applying corrections to ensure uniform brightness
    and color reproduction throughout the image.

We offer the **MediaToolKit** to assist with camera calibration (Require NDA).
This tool can be found under the name ``MediaToolKit Yocto`` on `MediaTek On-Line > Tool <https://online.mediatek.com/apps/tool/>`_. 
For detailed information on how to use the **MediaToolKit**, please refer to the user documentation available on `MediaTek On-Line <https://online.mediatek.com/>`_ document path:
*IoT/Software/Genio Series SoC/Genio 700/IoT Yocto/Camera/Camera Tuning Tool/MediaToolKit/*

.. important::

    To establish the MediaToolKit CCT connection, some additional steps must be executed before launching MediaToolKit.
    Please refer to the ``CCT_script_for_IoT_G510-700-1200/ReadMe_IoTYocto_CCT_Connect.txt`` in the MediaToolKit package.

.. note::

    The **MediaToolKit** requires capturing JPEG format images through the :ref:`v4l2-ctl utility <v4l2-ctl>`.
    Therefore, if you need to capture JPEG images using MediaToolKit, please ensure that the **v4l2-ctl** utility is installed.
    Before capturing JPEG images, you can set the image resolution through the properties: ``vendor.debug.camera.cct.jpeg.width`` and ``vendor.debug.camera.cct.jpeg.height``.

    .. prompt:: bash # auto

        # setprop vendor.debug.camera.cct.jpeg.width 1920
        # setprop vendor.debug.camera.cct.jpeg.height 1080

Camera Tuning
^^^^^^^^^^^^^

Camera tuning will primarily involve adjusting the relevant parameters of the ISP (Image Signal Processor) module
and aims to reproduce the captured image to closely resemble what is perceived by the human eye.
This involves enhancing various visual aspects such as saturation, sharpness, de-noise, and even stylization if desired.

Within the realm of camera tuning, we offer the **ImagiqSimulator** to provide the following features:

* **Parameter Adjustment**
    It allows for the manipulation and adjustment of various ISP parameters to fine-tune the image processing pipeline.

* **Image Comparison**
    It enables users to compare the original image with the processed image to evaluate the effectiveness of parameter adjustments.

* **Parameter Import/Export**
    It provides parameters DB tool to allow for the importation/exportation of tuned parameter sets,
    which can be extracted/applied directly on target devices or integrated into the codebase.

* **Batch Processing**
    It supports batch processing, enabling users to apply the same set of parameter adjustments to multiple images automatically.

To obtain more detailed information about the **ImagiqSimulator** (Require NDA),
please refer to the user documentation available on `MediaTek On-Line <https://online.mediatek.com/>`_ document path:
*IoT/Software/Genio Series SoC/Genio 700/IoT Yocto/Camera/Camera Tuning Tool/ImagiqSimulator5/*

.. note::

    The ImagiqSimulator can NOT be downloaded from MediaTek On-Line and requires a USB dongle key for permission certification.
    Please consult with your PM/CPM to obtain a USB dongle key, and then request the ImagiqSimulator by submitting an eService ticket.