上一篇說(shuō)到了光感監(jiān)測(cè),由于攝像頭沒(méi)有光感監(jiān)測(cè),也沒(méi)有感光孔,所以只能是同檢測(cè)拍到的圖片亮度來(lái)達(dá)到識(shí)別是否需要照明,下面看一下實(shí)現(xiàn)過(guò)程:
#import
#import
@property(nonatomic,strong)AVCaptureVideoDataOutput*myVideoOutPut;
@property(nonatomic,strong)AVCaptureSession*mySession;
- (AVCaptureSession*)mySession
{
if(!_mySession) {
_mySession= [[AVCaptureSessionalloc]init];
[_mySessionsetSessionPreset:AVCaptureSessionPresetMedium];
}
return_mySession;
}
- (AVCaptureVideoDataOutput*)myVideoOutPut
{
if(!_myVideoOutPut) {
_myVideoOutPut= [[AVCaptureVideoDataOutputalloc]init];
[_myVideoOutPutsetAlwaysDiscardsLateVideoFrames:YES];
[_myVideoOutPutsetSampleBufferDelegate:(id)selfqueue:dispatch_get_main_queue()];
}
return_myVideoOutPut;
}
if([self.mySessioncanAddOutput:self.myVideoOutPut]) {
[self.mySessionaddOutput:self.myVideoOutPut];
}
[_mySessionstartRunning];
然后下面就是代理方法,就會(huì)得到圖片亮度
- (void)captureOutput:(AVCaptureOutput*)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection*)connection
{
CFDictionaryRefmetadataDict =CMCopyDictionaryOfAttachments(NULL,
sampleBuffer,kCMAttachmentMode_ShouldPropagate);
NSDictionary*metadata = [[NSMutableDictionaryalloc]
initWithDictionary:(__bridgeNSDictionary*)metadataDict];
CFRelease(metadataDict);
NSDictionary*exifMetadata = [[metadataobjectForKey:(NSString*)kCGImagePropertyExifDictionary]mutableCopy];
floatbrightnessValue = [[exifMetadataobjectForKey:(NSString*)kCGImagePropertyExifBrightnessValue]floatValue];
NSLog(@"%f",brightnessValue);
}
得到這個(gè)值就可以