Lê Khánh Vinh
Lê Khánh Vinh

Reputation: 2609

iOS AVFoundation set exposure value, in EV units

Hi I'm building a scanning IOS app (BarCode and QRCode). I have a silder to adjust the exposure value (to make image brighter or darker depend on light condition. I'm using this to set the exposure value manually

captureDevice.setExposureTargetBias(slider.value, completionHandler: nil)

But my question is what is the min and max value of ExposureTargetBias so that we can set min and max value for slider accordingly?

Is this an appropriate way to adjust the brightness of image or there are another? (iOS).

Upvotes: 4

Views: 2059

Answers (2)

maxkonovalov
maxkonovalov

Reputation: 3719

You can use captureDevice.minExposureTargetBias and captureDevice.maxExposureTargetBias for the min and max values of your slider.

Upvotes: 5

Bluewings
Bluewings

Reputation: 3488

Use the below property from AVCaptureDeviceFormat to get the min and max values for exposure duration.

Swift

var minExposureDuration: CMTime { get }
var maxExposureDuration: CMTime { get }

Objective C

@property(nonatomic, readonly) CMTime minExposureDuration;
@property(nonatomic, readonly) CMTime maxExposureDuration;

Note that you can not simply set these values into your slider directly. You might need to set it as 0-1 as the slider range and do a non-linear mapping from the slider value to the actual device exposure duration.

Here is the sample code from Apple AVCam Manual

    self.exposureDurationSlider.minimumValue = 0;
    self.exposureDurationSlider.maximumValue = 1;
    double exposureDurationSeconds = CMTimeGetSeconds( self.videoDevice.exposureDuration );
    double minExposureDurationSeconds = MAX( CMTimeGetSeconds( self.videoDevice.activeFormat.minExposureDuration ), kExposureMinimumDuration );
    double maxExposureDurationSeconds = CMTimeGetSeconds( self.videoDevice.activeFormat.maxExposureDuration );
    // Map from duration to non-linear UI range 0-1
    double p = ( exposureDurationSeconds - minExposureDurationSeconds ) / ( maxExposureDurationSeconds - minExposureDurationSeconds ); // Scale to 0-1
    self.exposureDurationSlider.value = pow( p, 1 / kExposureDurationPower ); // Apply inverse power
    self.exposureDurationSlider.enabled = ( self.videoDevice && self.videoDevice.exposureMode == AVCaptureExposureModeCustom );

You might want to check other properties like focus, white balance incase if you want to get a clear picture of QR code.

Upvotes: 2

Related Questions