Image style#

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

Camera 1#

Image style is configured with CameraStyle.Setting.

CameraStyle.Setting.style() and CameraStyle.Setting.setStyle() are used to get and set 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 CameraStyle.Setting.supportedStyles().

The contrast, saturation and sharpness can be customized with style parameters given by CameraStyle.Setting.contrast(), CameraStyle.Setting.saturation() and CameraStyle.Setting.sharpness(). These 3 style parameters are of type CameraStyle.StyleParameter.

CameraStyle.StyleParameter gives access the current value (get and set) and indicates the minimal and maximal supported values.

Sample code to monitor image style:

/** Reference on MainCamera peripheral. */
private var cameraRef: Ref<MainCamera>? = null

/** Monitors and prints image style. */
fun monitorImageStyle(drone: Drone) {
    cameraRef = drone.getPeripheral(MainCamera::class.java) { camera ->
        // called on main thread when the camera peripheral changes
        // get image style setting
        camera?.style()?.run {
            println("Style: ${style()}")
            contrast().run {
                print("Contrast: $value min: $min max: $max")
            }
            saturation().run {
                print("Saturation: $value min: $min max: $max")
            }
            sharpness().run {
                print("Sharpness: $value min: $min max: $max")
            }
            println("Updating: $isUpdating")
        }
    }
}

Example of output:

Style: PASTEL
Contrast: 2 min: -2 max: 2
Saturation: 0 min: -2 max: 2
Sharpness: 1 min: -1 max: 1
Updating: false

Sample code to modify image style:

/** Sets image style. */
fun setImageStyle(drone: Drone, style: CameraStyle.Style) {
    drone.getPeripheral(MainCamera::class.java)?.run {
        style().setStyle(style)
    }
}

Sample code to modify image contrast, saturation and sharpness:

/** Sets image style. */
fun setImageStyle(drone: Drone, style: CameraStyle.Style) {
    drone.getPeripheral(MainCamera::class.java)?.run {
        style().setStyle(style)
    }
}

/** Sets image contrast. */
fun setImageContrast(drone: Drone, contrast: Int) {
    drone.getPeripheral(MainCamera::class.java)?.run {
        setImageParameter(style().contrast(), contrast)
    }
}


/** Sets image saturation. */
fun setImageSaturation(drone: Drone, saturation: Int) {
    drone.getPeripheral(MainCamera::class.java)?.run {
        setImageParameter(style().saturation(), saturation)
    }
}

/** Sets image sharpness. */
fun setImageSharpness(drone: Drone, sharpness: Int) {
    drone.getPeripheral(MainCamera::class.java)?.run {
        setImageParameter(style().sharpness(), sharpness)
    }
}

/** Sets image parameter value. */
fun setImageParameter(parameter: CameraStyle.StyleParameter, value: Int) {
    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 Camera.Config.IMAGE_STYLE.

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 Camera.Config.IMAGE_CONTRAST.

The saturation can be customized with parameter Camera.Config.IMAGE_SATURATION.

The sharpness can be customized with parameter Camera.Config.IMAGE_SHARPNESS.

Sample code to monitor image style:

/** Reference on MainCamera peripheral. */
private var cameraRef: Ref<MainCamera>? = null

/** Monitors and prints exposure settings. */
fun monitorImageStyle(drone: Drone) {
    cameraRef = drone.getPeripheral(MainCamera::class.java) { camera ->
        // called on main thread when the camera peripheral changes
        camera?.run {
            // image style
            config[Camera.Config.IMAGE_STYLE].run {
                if (supportedValues(onlyCurrent = true).isEmpty()) {
                    // parameter value is not relevant
                    // if there is not supported values in current configuration
                    println("Image style: no supported value in current configuration")
                } else {
                    println("Image style: $value")
                }
            }

            // image contrast
            config[Camera.Config.IMAGE_CONTRAST].run {
                if (supportedValues(onlyCurrent = true) == DoubleRange.EMPTY) {
                    // parameter value is not relevant
                    // if there is not supported values in current configuration
                    println("Image contrast: no supported value in current configuration")
                } else {
                    println("Image contrast: $value")
                }
            }

            // image saturation
            config[Camera.Config.IMAGE_SATURATION].run {
                if (supportedValues(onlyCurrent = true) == DoubleRange.EMPTY) {
                    // parameter value is not relevant
                    // if there is not supported values in current configuration
                    println("Image saturation: no supported value in current configuration")
                } else {
                    println("Image saturation: $value")
                }
            }

            // image sharpness
            config[Camera.Config.IMAGE_SHARPNESS].run {
                if (supportedValues(onlyCurrent = true) == DoubleRange.EMPTY) {
                    // parameter value is not relevant
                    // if there is not supported values in current configuration
                    println("Image sharpness: no supported value in current configuration")
                } else {
                    println("Image sharpness: $value")
                }
            }
        }
    }
}

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. */
fun setImageStyle(drone: Drone, style: Camera.ImageStyle) {
    drone.getPeripheral(MainCamera::class.java)?.run {
        // create configuration editor, starting from current configuration
        val editor = config.edit(fromScratch = false)
        // get configuration parameter
        editor[Camera.Config.IMAGE_STYLE].let { configParam ->
            // 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 retrieved by calling configParam.supportedValues(onlyCurrent = false).

Sample code to modify image contrast:

/** Sets image contrast. */
fun setImageContrast(drone: Drone, contrast: Double) {
    drone.getPeripheral(MainCamera::class.java)?.run {
        // create configuration editor, starting from current configuration
        val editor = config.edit(fromScratch = false)
        // get configuration parameter
        editor[Camera.Config.IMAGE_CONTRAST].let { configParam ->
            // change parameter value,
            // and unset other parameters conflicting with this new value
            configParam.value = contrast
            // 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 retrieved by calling configParam.supportedValues(onlyCurrent = false).

Sample code to modify image saturation:

/** Sets image saturation. */
fun setImageSaturation(drone: Drone, saturation: Double) {
    drone.getPeripheral(MainCamera::class.java)?.run {
        // create configuration editor, starting from current configuration
        val editor = config.edit(fromScratch = false)
        // get configuration parameter
        editor[Camera.Config.IMAGE_CONTRAST].let { configParam ->
            // 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 retrieved by calling configParam.supportedValues(onlyCurrent = false).

Sample code to modify image sharpness:

/** Sets image sharpness. */
fun setImageSharpness(drone: Drone, sharpness: Double) {
    drone.getPeripheral(MainCamera::class.java)?.run {
        // create configuration editor, starting from current configuration
        val editor = config.edit(fromScratch = false)
        // get configuration parameter
        editor[Camera.Config.IMAGE_CONTRAST].let { configParam ->
            // 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 retrieved by calling configParam.supportedValues(onlyCurrent = false).