如何从iPhone cam实时获取FNumber和ISOSpeedRatings [英] How to get FNumber and ISOSpeedRatings from iPhone cam in realtime

查看:126
本文介绍了如何从iPhone cam实时获取FNumber和ISOSpeedRatings的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要实时获取相机参数(exif数据),例如FNumber,ISOSpeedRatings,而不需要拍摄真实照片.有什么办法吗?

I need to get camera parameters (exif data) such as FNumber, ISOSpeedRatings in realtime without taking real photos. Is there any way to do that?

推荐答案

这是完整的解决方案.不要忘记导入适当的框架和标题.

Here is the complete solution. Dont forget to import appropriate frameworks and headers.

#import <AVFoundation/AVFoundation.h>
#import <ImageIO/CGImageProperties.h>

AVCaptureStillImageOutput *stillImageOutput;
AVCaptureSession *session;    

- (void)viewDidLoad
    {
        [super viewDidLoad];
        [self setupCaptureSession];
        // Do any additional setup after loading the view, typically from a nib.    
    }

    -(void)captureNow{


        AVCaptureConnection *videoConnection = nil;
        for (AVCaptureConnection *connection in stillImageOutput.connections)
        {
            for (AVCaptureInputPort *port in [connection inputPorts])
            {
                if ([[port mediaType] isEqual:AVMediaTypeVideo] )
                {
                    videoConnection = connection;
                    break;
                }
            }
            if (videoConnection) { break; }
        }

        [stillImageOutput captureStillImageAsynchronouslyFromConnection:videoConnection
         completionHandler:^(CMSampleBufferRef imageDataSampleBuffer, NSError *__strong error) {
            CFDictionaryRef exifAttachments = CMGetAttachment( imageDataSampleBuffer, kCGImagePropertyExifDictionary, NULL);
            if (exifAttachments)
            {
                // Do something with the attachments.
                NSLog(@"attachements: %@", exifAttachments);
            }
            else
              NSLog(@"no attachments");

            NSData *imageData = [AVCaptureStillImageOutput jpegStillImageNSDataRepresentation:imageDataSampleBuffer];
            UIImage *image = [[UIImage alloc] initWithData:imageData];
            }];

    }


    // Create and configure a capture session and start it running
    - (void)setupCaptureSession
    {
        NSError *error = nil;

        // Create the session
        session = [[AVCaptureSession alloc] init];

        // Configure the session to produce lower resolution video frames, if your
        // processing algorithm can cope. We'll specify medium quality for the
        // chosen device.
        session.sessionPreset = AVCaptureSessionPreset352x288;

        // Find a suitable AVCaptureDevice
        AVCaptureDevice *device = [AVCaptureDevice
                                   defaultDeviceWithMediaType:AVMediaTypeVideo];
        [device lockForConfiguration:nil];

        device.whiteBalanceMode = AVCaptureWhiteBalanceModeLocked;
        device.focusMode = AVCaptureFocusModeLocked;
        [device unlockForConfiguration];

        // Create a device input with the device and add it to the session.
        AVCaptureDeviceInput *input = [AVCaptureDeviceInput deviceInputWithDevice:device
                                                                            error:&error];
        if (!input) {
            // Handling the error appropriately.
        }
        [session addInput:input];




        stillImageOutput = [AVCaptureStillImageOutput new];
        NSDictionary *outputSettings = [[NSDictionary alloc] initWithObjectsAndKeys: AVVideoCodecJPEG, AVVideoCodecKey, nil];
        [stillImageOutput setOutputSettings:outputSettings];
        if ([session canAddOutput:stillImageOutput])
            [session addOutput:stillImageOutput];


        // Start the session running to start the flow of data
        [session startRunning];
        [self captureNow];

    }

这篇关于如何从iPhone cam实时获取FNumber和ISOSpeedRatings的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆