2012-05-02 49 views
3

我使用AVCaptureVideoDataOutputSampleBufferDelegate以自定義UIView中的iPhones相機顯示視頻,並使用以下代理方法。我可以從相機獲取任何有用信息嗎?

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

我希望能夠從圖像中提取一些有用的信息,如曝光,顏色,閾值。

訪問這類信息的最佳方式是什麼?

回答

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); 
    } 
} 
相關問題