IOS camera: manual exposure duration, but auto ISO?

I use the camera’s video stream for some image processing and would like to optimize for maximum shutter speed. I know that you can manually set the exposure time and ISO using

setExposureModeCustomWithDuration:ISO:completionHandler: 

but this requires you to set both values ​​manually. Is there a way or smart trick so that you can manually set the exposure duration, but is there an ISO handler to try to display the image correctly?

+5
source share
1 answer

I am not sure if this is the best solution since I struggled with this as you. I did this to listen to the exposure bias changes and adjust the ISO from them until you reach an acceptable exposure level. Most of this code was taken from Apple's sample code.

So, first of all, you are listening to the changes in the ExposureTargetOffset. Add to the class declaration:

static void *ExposureTargetOffsetContext = &ExposureTargetOffsetContext;

Then, once you have configured your device setup correctly:

[self addObserver:self forKeyPath:@"captureDevice.exposureTargetOffset" options:NSKeyValueObservingOptionNew context:ExposureTargetOffsetContext];

(Instead of captureDevice, use your property for the device) Then implement a callback for KVO in your class:

 - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context{ if (context == ExposureTargetOffsetContext){ float newExposureTargetOffset = [change[NSKeyValueChangeNewKey] floatValue]; NSLog(@"Offset is : %f",newExposureTargetOffset); if(!self.device) return; CGFloat currentISO = self.device.ISO; CGFloat biasISO = 0; //Assume 0,3 as our limit to correct the ISO if(newExposureTargetOffset > 0.3f) //decrease ISO biasISO = -50; else if(newExposureTargetOffset < -0.3f) //increase ISO biasISO = 50; if(biasISO){ //Normalize ISO level for the current device CGFloat newISO = currentISO+biasISO; newISO = newISO > self.device.activeFormat.maxISO? self.device.activeFormat.maxISO : newISO; newISO = newISO < self.device.activeFormat.minISO? self.device.activeFormat.minISO : newISO; NSError *error = nil; if ([self.device lockForConfiguration:&error]) { [self.device setExposureModeCustomWithDuration:AVCaptureExposureDurationCurrent ISO:newISO completionHandler:^(CMTime syncTime) {}]; [self.device unlockForConfiguration]; } } } } 

With this code, the shutter speed will remain constant and the ISO will be adjusted so that the image is not too overexposed or overexposed.

Remember to remove the observer whenever necessary. Hope this suits you.

Hurrah!

+5
source

All Articles