Image style#

Image contrast, saturation and sharpness can be configured with Camera APIs.

Camera 1#

Image style is configured with CameraStyleSettings.

CameraStyleSettings.activeStyle is used to set and get the current image style. Existing image styles are:

  • standard: natural look style.

  • plog: Parrot Log, produce flat and desaturated images, best for post-processing.

  • intense: lntense look style, providing bright colors, warm shade and high contrast.

  • pastel: pastel look style, providing soft colors, cold shade and low contrast.

The list of supported styles is given by CameraStyleSettings.supportedStyles.

The contrast, saturation and sharpness can be customized with fields CameraStyleSettings.contrast, CameraStyleSettings.saturation and CameraStyleSettings.sharpness. These 3 elements are of type CameraStyleParameter.

CameraStyleParameter gives access the current value (get and set) and indicates the minimal and maximal supported values. It also indicates if the parameter can be modified in the current configuration.

Sample code to monitor image style:

/// Keep reference on MainCamera peripheral to get notified of changes.
private var cameraRef: Ref<MainCamera>?

/// Monitors and prints image style.
func monitorImageStyle(drone: Drone) {
    cameraRef = drone.getPeripheral(Peripherals.mainCamera) { camera in
        // called on main thread when the camera peripheral changes
        if let camera = camera {
            let style = camera.styleSettings.activeStyle
            print("Style: \(style)")
            let contrast = camera.styleSettings.contrast
            print("Contrast: \(contrast.displayString) \(contrast.mutable ? "mutable" : "unmutable")")
            let saturation = camera.styleSettings.saturation
            print("Saturation: \(saturation.displayString) \(contrast.mutable ? "mutable" : "unmutable")")
            let sharpness = camera.styleSettings.sharpness
            print("Sharpness: \(sharpness.displayString) \(contrast.mutable ? "mutable" : "unmutable")")
        }
    }
}

Example of output:

Style: pastel
Contrast: -2 / 2 / 2 mutable
Saturation: -2 / 0 / 2 mutable
Sharpness: -1 / 1 / 1 mutable

Sample code to modify image style:

/// Sets image style.
func setImageStyle(drone: Drone, style: CameraStyle) {
    if let camera = drone.getPeripheral(Peripherals.mainCamera) {
        if camera.styleSettings.supportedStyles.contains(style) {
            camera.styleSettings.activeStyle = style
        } else {
            print("Image style not supported: \(style)")
        }
    }
}

Sample code to modify image contrast, saturation and sharpness:

/// Sets image contrast.
func setImageContrast(drone: Drone, contrast: Int) {
    if let camera = drone.getPeripheral(Peripherals.mainCamera) {
        setImageParameter(parameter: camera.styleSettings.contrast, value: contrast)
    }
}

/// Sets image saturation.
func setImageSaturation(drone: Drone, saturation: Int) {
    if let camera = drone.getPeripheral(Peripherals.mainCamera) {
        setImageParameter(parameter: camera.styleSettings.saturation, value: saturation)
    }
}

/// Sets image sharpness.
func setImageSharpness(drone: Drone, sharpness: Int) {
    if let camera = drone.getPeripheral(Peripherals.mainCamera) {
        setImageParameter(parameter: camera.styleSettings.sharpness, value: sharpness)
    }
}

/// Sets image parameter value.
func setImageParameter(parameter: CameraStyleParameter, value: Int) {
    if !parameter.mutable {
        print("Image parameter not mutable")
    } else if !(value >= parameter.min && value <= parameter.max) {
        print("Image parameter value out of range")
    } else {
        parameter.value = value
    }
}

Camera 2#

Image style is configured with parameter Camera2Params.imageStyle.

Existing image styles are:

  • custom: custom style, allowing custom contrast, saturation and sharpness.

  • standard: natural look style.

  • plog: Parrot Log, produce flat and desaturated images, best for post-processing.

  • intense: lntense look style, providing bright colors, warm shade and high contrast.

  • pastel: pastel look style, providing soft colors, cold shade and low contrast.

The contrast can be customized with parameter Camera2Params.imageContrast.

The saturation can be customized with parameter Camera2Params.imageSaturation.

The sharpness can be customized with parameter Camera2Params.imageSharpness.

Sample code to monitor image style:

/// Keep reference on MainCamera2 peripheral to get notified of changes.
private var cameraRef: Ref<MainCamera2>?

// Monitors and prints image style, contrast, saturation and sharpness.
func monitorImageStyle(drone: Drone) {
    cameraRef = drone.getPeripheral(Peripherals.mainCamera2) { camera in
        // called on main thread when the camera peripheral changes
        if let camera = camera {

            // get configuration parameter for image style
            if let configParam = camera.config[Camera2Params.imageStyle] {
                if configParam.currentSupportedValues.isEmpty {
                    // parameter value is not relevant
                    // if there is not supported values in current configuration
                    print("Image style: no supported value in current configuration")
                } else {
                    // get parameter value
                    let style = configParam.value
                    print("Image style: \(style)")
                }
            }

            // get configuration parameter for image contrast
            if let configParam = camera.config[Camera2Params.imageContrast] {
                if configParam.currentSupportedValues == nil {
                    // parameter value is not relevant
                    // if there is not supported values in current configuration
                    print("Image contrast: no supported value in current configuration")
                } else {
                    // get parameter value
                    let contrast = configParam.value
                    print("Image contrast: \(contrast)")
                }
            }

            // get configuration parameter for image saturation
            if let configParam = camera.config[Camera2Params.imageSaturation] {
                if configParam.currentSupportedValues == nil {
                    // parameter value is not relevant
                    // if there is not supported values in current configuration
                    print("Image saturation: no supported value in current configuration")
                } else {
                    // get parameter value
                    let saturation = configParam.value
                    print("Image saturation: \(saturation)")
                }
            }

            // get configuration parameter for image sharpness
            if let configParam = camera.config[Camera2Params.imageSharpness] {
                if configParam.currentSupportedValues == nil {
                    // parameter value is not relevant
                    // if there is not supported values in current configuration
                    print("Image sharpness: no supported value in current configuration")
                } else {
                    // get parameter value
                    let sharpness = configParam.value
                    print("Image sharpness: \(sharpness)")
                }
            }
        }
    }
}

Example of output:

Image style: standard
Image contrast: 0.0
Image saturation: 0.0
Image sharpness: 0.0

Sample code to modify image style:

/// Sets image style.
func setImageStyle(drone: Drone, style: Camera2Style) {
    if let camera = drone.getPeripheral(Peripherals.mainCamera2) {
        // create configuration editor, starting from current configuration
        let editor = camera.config.edit(fromScratch: false)
        // retrieve configuration parameter
        if let configParam = editor[Camera2Params.imageStyle] {
            // change parameter value,
            // and unset other parameters conflicting with this new value
            configParam.value = style
            // complete configuration, by setting missing parameters values
            editor.autoComplete()
            // send new configuration to drone
            editor.commit()
        }
    }
}

Trying to change the parameter value to an unsupported value has no effect. Values supported by the camera are provided by the parameter field configParam.overallSupportedValues.

Sample code to modify image contrast:

/// Sets image contrast.
func setImageContrast(drone: Drone, constrast: Double) {
    if let camera = drone.getPeripheral(Peripherals.mainCamera2) {
        // create configuration editor, starting from current configuration
        let editor = camera.config.edit(fromScratch: false)
        // retrieve configuration parameter
        if let configParam = editor[Camera2Params.imageContrast] {
            // change parameter value,
            // and unset other parameters conflicting with this new value
            configParam.value = constrast
            // complete configuration, by setting missing parameters values
            editor.autoComplete()
            // send new configuration to drone
            editor.commit()
        }
    }
}

Trying to change the parameter value to an unsupported value has no effect. Values supported by the camera are provided by the parameter field configParam.overallSupportedValues.

Sample code to modify image saturation:

/// Sets image saturation.
func setImageSaturation(drone: Drone, saturation: Double) {
    if let camera = drone.getPeripheral(Peripherals.mainCamera2) {
        // create configuration editor, starting from current configuration
        let editor = camera.config.edit(fromScratch: false)
        // retrieve configuration parameter
        if let configParam = editor[Camera2Params.imageSaturation] {
            // change parameter value,
            // and unset other parameters conflicting with this new value
            configParam.value = saturation
            // complete configuration, by setting missing parameters values
            editor.autoComplete()
            // send new configuration to drone
            editor.commit()
        }
    }
}

Trying to change the parameter value to an unsupported value has no effect. Values supported by the camera are provided by the parameter field configParam.overallSupportedValues.

Sample code to modify image sharpness:

/// Sets image sharpness.
func setImageSharpness(drone: Drone, sharpness: Double) {
    if let camera = drone.getPeripheral(Peripherals.mainCamera2) {
        // create configuration editor, starting from current configuration
        let editor = camera.config.edit(fromScratch: false)
        // retrieve configuration parameter
        if let configParam = editor[Camera2Params.imageSharpness] {
            // change parameter value,
            // and unset other parameters conflicting with this new value
            configParam.value = sharpness
            // complete configuration, by setting missing parameters values
            editor.autoComplete()
            // send new configuration to drone
            editor.commit()
        }
    }
}

Trying to change the parameter value to an unsupported value has no effect. Values supported by the camera are provided by the parameter field configParam.overallSupportedValues.