# SHDR

Source: [https://docs.qualcomm.com/doc/80-70015-17/topic/shdr_public.html](https://docs.qualcomm.com/doc/80-70015-17/topic/shdr_public.html)

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://docs.qualcomm.com/bundle/publicresource/topics/80-70015-254/how_to.html#use-ssh) for instructions.

To collect the log, run the following command in the
            device:

    # journalctl -f > /opt/log.txtCopy to clipboard

## SHDR v3 – Dual virtual channel with two-frame exposure

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

Use the following GStreamer command to enable SHDR
                v3:

    gst-launch-1.0 -e qtiqmmfsrc name=camsrc camera=0 vhdr=2 ! \
    video/x-raw\(memory:GBM\),format=NV12,width=3840,height=2160,framerate=30/1,\
    compression=ubwc,interlace-mode=progressive,colorimetry=bt601 ! v4l2h264enc \
    capture-io-mode=5 output-io-mode=5 extra-controls="controls,video_bitrate=6000000,\
    video_bitrate_mode=0;" ! h264parse ! mp4mux ! filesink location=/opt/cam_4k.mp4
    Copy to clipboard

The video file is saved at /opt/cam\_4k.mp4.

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

    cam-server: CamX: [CORE_CFG]891 23288 [CORE   ] camxpipeline.h:3024
     SetPipelineStatus() RealTimeYUVSHDR_0 status is now PipelineStatus::STREAM_ONCopy to clipboard

## 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

    gst-launch-1.0 -e qtiqmmfsrc name=camsrc camera=0 vhdr=1 ! \
    video/x-raw\(memory:GBM\),format=NV12,width=3840,height=2160,framerate=30/1,\
    compression=ubwc,interlace-mode=progressive,colorimetry=bt601 ! v4l2h264enc \
    capture-io-mode=5 output-io-mode=5 extra-controls="controls,video_bitrate=6000000,\
    video_bitrate_mode=0;" ! h264parse ! mp4mux ! filesink location=/opt/cam_4k.mp4
    Copy to clipboard

The video file is saved at /opt/cam\_4k.mp4.

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

    cam-server: CamX: [CORE_CFG]852 2070 [CORE   ] camxpipeline.h:3015 SetPipelineStatus()
    RealTimeSHDR_0 status is now PipelineStatus::STREAM_ONCopy to clipboard

## 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.

To validate the defog feature:

1. Use the `shdrModeType=5` override setting in
                        /var/cache/camera/camxoverridesettings.txt to enable
                    the defog feature in SHDR use cases.
2. Use the following override settings in
                        /var/cache/camera/camxoverridesettings.txt to verify
                    the defog feature is working:

        logInfoMask=0x40000
        logVerboseMask=0x40000Copy to clipboard
3. Test the defog feature.
    - Run the following command to test defog with a SHDR v2 use
                            case:

            gst-pipeline-app -e qtiqmmfsrc name=camsrc vhdr=1  ! \
            video/x-raw\(memory:GBM\),format=NV12,width=3840,height=2160,framerate=30/1,\
            compression=ubwc,interlace-mode=progressive,colorimetry=bt601 ! v4l2h264enc capture-io-mode=5 \
            output-io-mode=5  extra-controls="controls,video_bitrate=6000000,video_bitrate_mode=0;" ! queue ! \
            h264parse ! mp4mux ! queue ! filesink location=/opt/cam_4k.mp4Copy to clipboard
    - Run the following command to test defog with a SHDR v3 use
                            case:

            gst-pipeline-app -e qtiqmmfsrc name=camsrc vhdr=2 ! \
            video/x-raw\(memory:GBM\),format=NV12,width=3840,height=2160,framerate=30/1,\
            compression=ubwc,interlace-mode=progressive,colorimetry=bt601 ! v4l2h264enc capture-io-mode=5 \
            output-io-mode=5 extra-controls="controls,video_bitrate=6000000,video_bitrate_mode=0;" ! queue ! \
            h264parse ! mp4mux ! queue ! filesink location=/opt/cam_4k.mp4Copy to clipboard
4. Enable defog.
    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.

            org.quic.camera.defog, enable=true, strength=3, ates_strength=1;Copy to clipboard
    8. Close the camera by selecting (b) BACK and then (q) QUIT.

    The video file is saved at
                    /opt/cam\_4k.mp4.
5. Check for the following logs to verify the defog feature is enabled:

        defog.cpp:5782 DefogInitialize() ===================== Defog lib v2.5.0=====================
        cam-server: CamX: [ VERB]793766 793830 [CHI ] camxchinodedefog.cpp:1981 SetDeFog2ConfigParams() Previous ( defog_en = 0 defog_strength = 0 ates_strength =  0
        cam-server: CamX: [ VERB]793766 793830 [CHI ] camxchinodedefog.cpp:1984 SetDeFog2ConfigParams() Current ( defog_en = 1 defog_strength = 3 ates_strength =  1Copy to clipboard

**Parent Topic:** [Advanced Camera Features](https://docs.qualcomm.com/doc/80-70015-17/topic/advanced_camera_features.html)

Last Published: Oct 17, 2024

[Previous Topic
Advanced Camera Features](https://docs.qualcomm.com/bundle/publicresource/80-70015-17/topics/advanced_camera_features.md) [Next Topic
EIS and LDC use cases](https://docs.qualcomm.com/bundle/publicresource/80-70015-17/topics/eis_and_ldc_use_cases_public.md)