2012-12-04 13 views
6

मैं वीडियो स्ट्रीम प्राप्त करने और स्ट्रीम पर मान्यता प्राप्त करने के लिए आईफोन/आईपैड कैमरा का उपयोग कर रहा हूं, लेकिन प्रकाश परिवर्तन के साथ इसका मजबूती पर नकारात्मक प्रभाव पड़ता है। मैंने अलग-अलग रोशनी में अलग-अलग सेटिंग्स का परीक्षण किया है और इसे काम पर ला सकता है, लेकिन रन टाइम पर समायोजित करने के लिए सेटिंग्स को प्राप्त करने का प्रयास करना मुझे चाहिए।क्या कैमरे की स्ट्रीम के आईओएस पर चमक स्तर पाने का कोई तरीका है?

मैं प्रत्येक फ्रेम पर एक साधारण चमक जांच की गणना कर सकता हूं, लेकिन कैमरा मेरे परिणामों को समायोजित और फेंकता है। मैं तेज परिवर्तनों के लिए देख सकता हूं और चेक चला सकता हूं, लेकिन धीरे-धीरे परिवर्तन मेरे परिणामों को भी फेंक देंगे।

आदर्श रूप से मैं स्ट्रीम के लिए कैमरा/EXIF ​​डेटा तक पहुंचना चाहता हूं और यह देख सकता हूं कि यह अपरिपक्व चमक को पंजीकृत कर रहा है, क्या ऐसा करने का कोई तरीका है?

(मैं उपकरणों iOS 5 और ऊपर के लिए काम कर रहा हूँ) धन्यवाद आईओएस 4.0 और इसके बाद के संस्करण में

+0

यदि आपके पास है तो [लाइट सेंसर] (http://stackoverflow.com/questions/6408840/about-ambient-light-sensor-in-iphone) का उपयोग करें। –

उत्तर

8

उपलब्ध है। CMSampleBufferRef से EXIF ​​जानकारी प्राप्त करना संभव है।

//Import ImageIO & include framework in your project. 
#import <ImageIO/CGImageProperties.h> 

अपने नमूना बफर प्रतिनिधि टोल फ्री पाटने में CoreMedia के CMGetAttachment से प्राप्त परिणामों का NSDictionary मिल जाएगा।

- (void)captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection *)connection { 
    NSDictionary* dict = (NSDictionary*)CMGetAttachment(sampleBuffer, kCGImagePropertyExifDictionary, NULL); 
1

पूरा कोड, के रूप में अपने खुद के अनुप्रयोग में इस्तेमाल किया:

- (void)setupAVCapture { 

//-- Setup Capture Session. 
_session = [[AVCaptureSession alloc] init]; 
[_session beginConfiguration]; 

//-- Set preset session size. 
[_session setSessionPreset:AVCaptureSessionPreset1920x1080]; 

//-- Creata a video device and input from that Device. Add the input to the capture session. 
AVCaptureDevice * videoDevice = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo]; 
if(videoDevice == nil) 
    assert(0); 

//-- Add the device to the session. 
NSError *error; 
AVCaptureDeviceInput *input = [AVCaptureDeviceInput deviceInputWithDevice:videoDevice error:&error]; 
if(error) 
    assert(0); 

[_session addInput:input]; 

//-- Create the output for the capture session. 
AVCaptureVideoDataOutput * dataOutput = [[AVCaptureVideoDataOutput alloc] init]; 
[dataOutput setAlwaysDiscardsLateVideoFrames:YES]; // Probably want to set this to NO when recording 

//-- Set to YUV420. 
[dataOutput setVideoSettings:[NSDictionary dictionaryWithObject:[NSNumber numberWithInt:kCVPixelFormatType_420YpCbCr8BiPlanarFullRange] 
                 forKey:(id)kCVPixelBufferPixelFormatTypeKey]]; // Necessary for manual preview 

// Set dispatch to be on the main thread so OpenGL can do things with the data 
[dataOutput setSampleBufferDelegate:self queue:dispatch_get_main_queue()]; 

[_session addOutput:dataOutput]; 
[_session commitConfiguration]; 

[_session startRunning]; 
} 

- (void)captureOutput:(AVCaptureOutput *)captureOutput 
didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer 
     fromConnection:(AVCaptureConnection *)connection 
{ 
    CFDictionaryRef metadataDict = CMCopyDictionaryOfAttachments(NULL, 
                   sampleBuffer, kCMAttachmentMode_ShouldPropagate); 
    NSDictionary *metadata = [[NSMutableDictionary alloc] 
           initWithDictionary:(__bridge NSDictionary*)metadataDict]; 
    CFRelease(metadataDict); 
    NSDictionary *exifMetadata = [[metadata 
            objectForKey:(NSString *)kCGImagePropertyExifDictionary] mutableCopy]; 
    self.autoBrightness = [[exifMetadata 
         objectForKey:(NSString *)kCGImagePropertyExifBrightnessValue] floatValue]; 

    float oldMin = -4.639957; // dark 
    float oldMax = 4.639957; // light 
    if (self.autoBrightness > oldMax) oldMax = self.autoBrightness; // adjust oldMax if brighter than expected oldMax 

    self.lumaThreshold = ((self.autoBrightness - oldMin) * ((3.0 - 1.0)/(oldMax - oldMin))) + 1.0; 

    NSLog(@"brightnessValue %f", self.autoBrightness); 
    NSLog(@"lumaThreshold %f", self.lumaThreshold); 
} 

lumaThreshold चर मेरी टुकड़ा शेडर है, जो आदर्श आधारित चमक को खोजने के लिए वाई नमूना बनावट गुणा करने के लिए एक समान चर के रूप में भेजा जाता है पर्यावरण की चमक पर। अभी, यह बैक कैमरा का उपयोग करता है; मैं शायद सामने वाले कैमरे पर स्विच करूंगा, क्योंकि मैं इनडोर/आउटडोर देखने के लिए समायोजित करने के लिए स्क्रीन की "चमक" को बदल रहा हूं, और उपयोगकर्ता की आंखें कैमरे के सामने हैं (और पीछे नहीं)।

संबंधित मुद्दे

 संबंधित मुद्दे