2012-05-02 13 views
3

私は、UIViewのiPhoneカメラからのビデオを以下の委任方法で表示するのにAVCaptureVideoDataOutputSampleBufferDelegateを使用しています。カメラから有益な情報を得ることはできますか?

- (void)captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection *)connection 

Iは、露光、色、閾値として画像からいくつかの有用な情報を引き出すことができるようにしたいです。

この種の情報にアクセスするには、どのような方法が最適ですか?

答えて

2

はサンプルバッファからのメタデータの添付ファイルを抽出します。露出、色などはメタデータにあります。このようなもの:

NSDictionary *exifDictionary = (NSDictionary*)CMGetAttachment(sampleBuffer, kCGImagePropertyExifDictionary, NULL); 
1

あなたは、このコードで基本となるピクセルデータにアクセスすることができます。

CVPixelBufferRef pixelBuffer = CMSampleBufferGetImageBuffer(sampleBuffer); 
CVReturn lock = CVPixelBufferLockBaseAddress(pixelBuffer, 0); 
if (lock == kCVReturnSuccess) { 
    int w = 0; 
    int h = 0; 
    int r = 0; 
    int bytesPerPixel = 0; 
    unsigned char *buffer;  

    if (CVPixelBufferIsPlanar(pixelBuffer)) { 
    w = CVPixelBufferGetWidthOfPlane(pixelBuffer, 0); 
    h = CVPixelBufferGetHeightOfPlane(pixelBuffer, 0); 
    r = CVPixelBufferGetBytesPerRowOfPlane(pixelBuffer, 0); 
    bytesPerPixel = r/w; 

    buffer = CVPixelBufferGetBaseAddressOfPlane(pixelBuffer, 0); 
    }else { 
    w = CVPixelBufferGetWidth(pixelBuffer); 
    h = CVPixelBufferGetHeight(pixelBuffer); 
    r = CVPixelBufferGetBytesPerRow(pixelBuffer); 
    bytesPerPixel = r/w; 

    buffer = CVPixelBufferGetBaseAddress(pixelBuffer); 
    } 
} 
関連する問題