2012-12-04 55 views
6

Tôi đang sử dụng máy ảnh iPhone/iPad để nhận luồng video và nhận dạng trên luồng, nhưng với những thay đổi về ánh sáng, nó có tác động tiêu cực đến độ bền. Tôi đã thử nghiệm các thiết lập khác nhau trong ánh sáng khác nhau và có thể làm cho nó hoạt động, nhưng cố gắng để có được các thiết lập để điều chỉnh tại thời gian chạy là những gì tôi cần.Có cách nào để có được mức độ sáng trên iOS của luồng của máy ảnh không?

Tôi có thể tính toán kiểm tra độ sáng đơn giản trên mỗi khung, nhưng máy ảnh điều chỉnh và ném kết quả của tôi tắt. Tôi có thể theo dõi những thay đổi mạnh mẽ và chạy kiểm tra sau đó, nhưng những thay đổi dần dần cũng sẽ làm giảm kết quả của tôi.

Lý tưởng nhất là tôi muốn truy cập dữ liệu máy ảnh/EXIF ​​cho luồng và xem nội dung đang đăng ký độ sáng chưa được lọc, có cách nào để thực hiện điều này không?

(Tôi đang làm việc cho các thiết bị iOS 5 trở lên)

Cảm ơn bạn

+0

Sử dụng [cảm biến ánh sáng] (http://stackoverflow.com/questions/6408840/about-ambient-light-sensor-in-iphone) nếu bạn có. –

Trả lời

8

Có sẵn trong iOS 4.0 trở lên. Có thể lấy thông tin EXIF ​​từ CMSampleBufferRef.

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

Trong bộ đệm mẫu, ủy nhiệm miễn phí bắc cầu sẽ nhận được NSD từ điển kết quả từ CMGetAttachment của CoreMedia.

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

mã hoàn chỉnh, như được sử dụng trong ứng dụng của riêng tôi:

- (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); 
} 

Biến lumaThreshold được gửi như là một biến đồng bộ để tạo bóng đoạn của tôi, làm tăng gấp bội sampler kết cấu Y để tìm ra độ sáng lý tưởng dựa về độ sáng của môi trường. Ngay bây giờ, nó sử dụng camera sau; Có lẽ tôi sẽ chuyển sang camera trước, vì tôi chỉ thay đổi "độ sáng" của màn hình để điều chỉnh để xem trong nhà/ngoài trời và mắt của người dùng ở phía trước máy ảnh (chứ không phải mặt sau).

Các vấn đề liên quan