カメラの入力をリアルタイムで表示し、中間のピクセルのカラー値を取得するプログラムがあります。CVPixelBufferから目的のデータを取得するリファレンス
// Get a CMSampleBuffer's Core Video image buffer for the media data
CVImageBufferRef imageBuffer = CMSampleBufferGetImageBuffer(sampleBuffer);
// Lock the base address of the pixel buffer
CVPixelBufferLockBaseAddress(imageBuffer, 0);
// Get the number of bytes per row for the pixel buffer
size_t bytesPerRow = CVPixelBufferGetBytesPerRow(imageBuffer);
// Get the pixel buffer width and height
size_t width = CVPixelBufferGetWidth(imageBuffer);
size_t height = CVPixelBufferGetHeight(imageBuffer);
unsigned char* pixel = (unsigned char *)CVPixelBufferGetBaseAddress(imageBuffer);
NSLog(@"Middle pixel: %hhu", pixel[((width*height)*4)/2]);
int red = pixel[(((width*height)*4)/2)+2];
int green = pixel[(((width*height)*4)/2)+1];
int blue = pixel[((width*height)*4)/2];
int alpha = 1;
UIColor *color = [UIColor colorWithRed:(red/255.0f) green:(green/255.0f) blue:(blue/255.0f) alpha:(alpha)];
I、式かかわらず:そして、私は、次のコードを使用してピクセルのRGB値を取得(CVPixelBufferとして読み取ることがたまたま)AVCaptureSession出力からCMSampleBufferを取得する方法:私はcaptureOutputを使用します((width * height)* 4)/ 2は中間のピクセルを取得しますが、画像の最上部の中間ピクセルを与えます。私はスクリーンの真ん中のピクセルにアクセスするためにどのような式を使用する必要があるのだろうと思っています。私は実際にはこれらのピクセルバッファの内部構造を知らないので、ちょっと固まっています。
将来的には4つの中間ピクセルをつかんで、より正確な色の読みに平均化したいと思いますが、今のところ、これらの処理がどのように機能するかを知りたいと思います。
あなた」は任意のポートレートモードの仕事をやっているので、もしはい、iOSデバイス上の2台のカメラのデフォルトの向きは、風景であります回転したフレームに対処する必要があります。 –
@Codoアドバイスはありますか? http://stackoverflow.com/questions/37611593/how-to-create-cvpixelbufferref-with-yuv420i420-data –
奇妙なことに、幅の部分に4を掛けているのはなぜですか? – OutOnAWeekend