3

次のデリゲートメソッドを使用AVCaptureVideoDataOutputSampleBufferDelegateして、カスタムでiPhoneカメラからのビデオを表示するためにを使用しています。UIView

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

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

この種の情報にアクセスするための最良の方法は何ですか?

4

2 に答える 2

2

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

NSDictionary *exifDictionary = (NSDictionary*)CMGetAttachment(sampleBuffer, kCGImagePropertyExifDictionary, NULL);
于 2012-05-02T17:12:40.673 に答える
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);
  }
}
于 2012-05-02T17:12:29.063 に答える