> ## Documentation Index
> Fetch the complete documentation index at: https://dragonwingdocs.qualcomm.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Enable high dynamic range

> Enable Staggered High Dynamic Range (SHDR) and Digital Overlap (DOL) modes to capture and fuse multiple exposure frames on QCS6490.

<div style={{display:'flex',gap:'8px',flexWrap:'wrap',marginBottom:'16px'}}>
  <span style={{background:'#ede9fe',color:'#5b21b6',padding:'2px 10px',borderRadius:'999px',fontSize:'12px',fontWeight:600}}>QCS6490</span>
  <span style={{background:'#f0fdf4',color:'#166534',padding:'2px 10px',borderRadius:'999px',fontSize:'12px',fontWeight:600}}>Stable</span>
</div>

<CardGroup cols={4}>
  <Card title="LEF/SEF" icon="layer-group">Dual Exposure</Card>
  <Card title="DOL" icon="barcode">Row Interleaved</Card>
  <Card title="v3" icon="network">Dual VC</Card>
  <Card title="v2" icon="link">Single VC</Card>
</CardGroup>

<Note>
  **Platform Scope:**<br />
  This section is only applicable for **QCS6490**.
</Note>

***

## 01 · What Is It?

Staggered High Dynamic Range (SHDR) mode is a sensor feature that outputs frames with different exposure times - Long exposure frame (LEF) and short exposure frame (SEF).

* The sensor outputs a pair of two lines as one unit. The frame of LEF and the frame of SEF are output alternately in the pair of these two lines.
* The rolling shutter readout is staggered (row interleaved) so that the short integration starts immediately (within the same frame) after sampling of the long integration. This is also called Digital Overlap (DOL) mode.
* The SHDR sensors are capable of outputting LEF and SEF frames with a single virtual channel (the single frame contains both LEF and SEF in an interleaved manner) or different virtual channels (LEF and SEF frames are output separately on different virtual channels).
* On Qualcomm chipsets, there are two solutions (SHDR v3 and SHDR v2). SHDR v3 works for dual virtual channels. SHDR v2 works for single virtual channel.

<Note>
  Connect to the device console using SSH. See [How To SSH?](https://dragonwingdocs.qualcomm.com/Linux/devices/iq9075-evk/set-up-the-device#connect-over-ssh) for instructions.
</Note>

<Note>
  Collect the logs by running: `journalctl -f > /opt/log.txt`
</Note>

***

## 02 · SHDR v3 - Dual virtual channel with two-frame exposure

The SHDR v3 solution uses sensors that can send the exposure frames (LEF, SEF) on different CSI virtual channels. Long and short exposure frames are transmitted on different virtual channels.

Use the following GStreamer command to enable SHDR v3:

```bash title = "GStreamer (SHDRv3)" theme={null}
gst-launch-1.0 -e qtiqmmfsrc name=camsrc camera=0 vhdr=2 ! \
video/x-raw,format=NV12,width=3840,height=2160,framerate=30/1,\
interlace-mode=progressive,colorimetry=bt601 ! v4l2h264enc \
capture-io-mode=4 output-io-mode=5 extra-controls="controls,video_bitrate=6000000,\
video_bitrate_mode=0;" ! h264parse ! mp4mux ! filesink location=/opt/cam_4k.mp4
```

The video file is saved at `/opt/cam_4k.mp4`.

To verify the SHDR v3 use case is selected, check for the following log:

```text title = "Log Verification" theme={null}
cam-server: CamX: [CORE_CFG]891 23288 [CORE  ] camxpipeline.h:3024 SetPipelineStatus() RealTimeYUVSHDR_0 status is now PipelineStatus::STREAM_ON
```

***

## 03 · SHDR v2 - Single virtual channel with two-frame exposure

The SHDR v2 solution requires the sensor to output both LEF and SEF on a single virtual channel in an interleaved manner (also referred to as DOL mode). The rolling shutter readout is staggered (row interleaved) so that the short integration starts immediately (within the same frame) after sampling of the long integration.

Use the following GStreamer command to enable SHDR v2:

```bash title = "GStreamer (SHDRv2)" theme={null}
gst-launch-1.0 -e qtiqmmfsrc name=camsrc camera=0 vhdr=1 ! \
video/x-raw,format=NV12,width=3840,height=2160,framerate=30/1,\
interlace-mode=progressive,colorimetry=bt601 ! v4l2h264enc \
capture-io-mode=4 output-io-mode=5 extra-controls="controls,video_bitrate=6000000,\
video_bitrate_mode=0;" ! h264parse ! mp4mux ! filesink location=/opt/cam_4k.mp4
```

The video file is saved at `/opt/cam_4k.mp4`.

To verify the SHDR v2 use case is selected, check for the following log:

```text title = "Log Verification" theme={null}
cam-server: CamX: [CORE_CFG]852 2070 [CORE] camxpipeline.h:3015 SetPipelineStatus()
RealTimeSHDR_0 status is now PipelineStatus::STREAM_ON
```

***

## 04 · Defog feature

Defog is a fog detection and removal technique. This feature allows users to remove the foggy effect in poor weather conditions, such as rain, smog, haze, or fog. It provides a defogged image by improving the image quality in SHDR v2 and SHDR v3 use cases. The defog library performs defog operations with the statistics and interpolation data collected from IFE, BPS, and IPE and generates new tables for the IQ modules to apply in the next frame.

### Validation

<Steps>
  <Step title="Configure override settings">
    Use the following override settings in `/var/cache/camera/camxoverridesettings.txt` to verify the defog feature is working:

    ```text title="Camx Override Settings" theme={null}
    logInfoMask=0x50000
    logVerboseMask=0x50000
    ```
  </Step>

  <Step title="Test the defog feature">
    Run the following command to test defog with a SHDR v2 use case:

    ```bash title = "GStreamer (Defog with SHDRv2)" theme={null}
    gst-pipeline-app -e qtiqmmfsrc name=camsrc vhdr=1  ! \
    video/x-raw,format=NV12,width=3840,height=2160,framerate=30/1,\
    interlace-mode=progressive,colorimetry=bt601 ! v4l2h264enc capture-io-mode=4 \
    output-io-mode=5  extra-controls="controls,video_bitrate=6000000,video_bitrate_mode=0;" ! queue ! \
    h264parse ! mp4mux ! queue ! filesink location=/opt/cam_4k.mp4
    ```

    Run the following command to test defog with a SHDR v3 use case:

    ```bash title = "GStreamer (Defog with SHDRv3)" theme={null}
    gst-pipeline-app -e qtiqmmfsrc name=camsrc vhdr=2 ! \
    video/x-raw,format=NV12,width=3840,height=2160,framerate=30/1,\
    interlace-mode=progressive,colorimetry=bt601 ! v4l2h264enc capture-io-mode=4 \
    output-io-mode=5 extra-controls="controls,video_bitrate=6000000,video_bitrate_mode=0;" ! queue ! \
    h264parse ! mp4mux ! queue ! filesink location=/opt/cam_4k.mp4
    ```
  </Step>

  <Step title="Enable defog manually">
    1. Select **(1) READY**.
    2. Select **(3) PLAYING**.
    3. Press **Enter**.
    4. Select **(p) Plugin Mode**.
    5. Select **(8) camsrc**.
    6. Select **(24) defog-table**.
    7. Enter the following string to enable defog:
       ```text theme={null}
       org.quic.camera.defog, enable=true, strength=3, ates_strength=1;
       ```
    8. Close the camera by selecting **(b) BACK** and then **(q) QUIT**. The video file is saved at `/opt/cam_4k.mp4`.
  </Step>

  <Step title="Verify log output">
    Check for the following logs to verify the defog feature is enabled:

    **SHDR v2:**

    ```text title = "Log Verification" theme={null}
    CamX: [ INFO]2149 2256 [CORE   ] camxpipeline.cpp:5331 FillSHDRSensorModeInfo() isSHDREnabled=1 isSHDRRAWMode=1 isSHDRVCMode=0 isSHDRUseFusedStats=1 numVCSupported=0 isDefogEnablewithSHDR=1
    CamX: [ VERB]2149 2182 [CHI    ] camxchinodedefog.cpp:1988 SetDeFog2ConfigParams() Previous (  defog_en = 1  defog_strength = 3 ates_strength = 1
    CamX: [ VERB]2149 2182 [CHI    ] camxchinodedefog.cpp:1991 SetDeFog2ConfigParams() Current (  defog_en = 1  defog_strength = 3 ates_strength = 1
    ```

    **SHDR v3:**

    ```text title = "Log Verification" theme={null}
    CamX: [ INFO]2149 2256 [CORE   ] camxpipeline.cpp:5285 FillSHDRSensorModeInfo() isSHDREnabled:1 isSHDRRAWMode:0 isSHDRVCMode:1 isSHDRUseFusedStats:0 numVCSupported:2 isDefogEnablewithSHDR:1
    CamX: [ VERB]2149 2182 [CHI    ] camxchinodedefog.cpp:1988 SetDeFog2ConfigParams() Previous (  defog_en = 1  defog_strength = 3 ates_strength = 1
    CamX: [ VERB]2149 2182 [CHI    ] camxchinodedefog.cpp:1991 SetDeFog2ConfigParams() Current (  defog_en = 1  defog_strength = 3 ates_strength = 1
    ```
  </Step>
</Steps>
