iOS camera: manual exposure duration but auto ISO? -


i'm using camera video feed image processing , optimise fastest shutter speed. know can manually set exposure duration , iso using

setexposuremodecustomwithduration:iso:completionhandler: 

but requires 1 set both values hand. there method or clever trick allow set exposure duraction manually have iso handle try correctly expose image?

i'm not sure if solution best one, since struggling were. i've done listen changes in exposure offset and, them, adjust iso until reach acceptable exposure level. of code has been taken apple sample code

so, first of all, listen changes on exposuretargetoffset. add in class declaration:

static void *exposuretargetoffsetcontext = &exposuretargetoffsetcontext;

then, once have done device setup properly:

[self addobserver:self forkeypath:@"capturedevice.exposuretargetoffset" options:nskeyvalueobservingoptionnew context:exposuretargetoffsetcontext];

(instead of capturedevice, use property device) implement in class callback kvo:

- (void)observevalueforkeypath:(nsstring *)keypath ofobject:(id)object change:(nsdictionary *)change context:(void *)context{  if (context == exposuretargetoffsetcontext){         float newexposuretargetoffset = [change[nskeyvaluechangenewkey] floatvalue];         nslog(@"offset : %f",newexposuretargetoffset);          if(!self.device) return;          cgfloat currentiso = self.device.iso;         cgfloat biasiso = 0;          //assume 0,3 our limit correct iso         if(newexposuretargetoffset > 0.3f) //decrease iso             biasiso = -50;         else if(newexposuretargetoffset < -0.3f) //increase iso             biasiso = 50;          if(biasiso){             //normalize iso level 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 code, shutter speed remain constant , iso adjusted leave image not under or overexposed.

don't forget remove observer whenever needed. hope suits you.

cheers!


Popular posts from this blog

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -