これをリアルタイムで行いたいと仮定します (スクリーン キャプチャを使用するのではなく、具体的には望まないと言います):
まず、Apple がここで概説しているように、ビデオ バッファをキャプチャする必要があります。
その後、 で好きなことを行うことができますCMSampleBufferRef
。Apple のサンプル アプリは をUIImage
作成しますが、単純に(またはunsigned char
を介して) ポインターにコピーし、次のような問題のピクセルの BGRA 値を取得できます (テストされていないコード: 例は 100x,200y のピクセルの場合です)。 :CVImageBufferRef
CVPixelBufferRef
int x = 100;
int y = 200;
CVPixelBufferRef imageBuffer = CMSampleBufferGetImageBuffer(sampleBuffer);
CVPixelBufferLockBaseAddress(imageBuffer,0);
tempAddress = (uint8_t *)CVPixelBufferGetBaseAddress(imageBuffer);
size_t bytesPerRow = CVPixelBufferGetBytesPerRow(imageBuffer);
size_t width = CVPixelBufferGetWidth(imageBuffer);
size_t height = CVPixelBufferGetHeight(imageBuffer);
CVPixelBufferUnlockBaseAddress(imageBuffer,0);
int bufferSize = bytesPerRow * height;
uint8_t *myPixelBuf = malloc(bufferSize);
memmove(myPixelBuf, tempAddress, bufferSize);
tempAddress = nil;
// remember it's BGRA data
int b = myPixelBuf[(x*4)+(y*bytesPerRow)];
int g = myPixelBuf[((x*4)+(y*bytesPerRow))+1];
int r = myPixelBuf[((x*4)+(y*bytesPerRow))+2];
free(myPixelBuf);
NSLog(@"r:%i g:%i b:%i",r,g,b);
これはビデオ フィード自体のピクセルに対する相対位置を取得しますが、これはあなたが望むものではないかもしれません: iPhone のディスプレイに表示されるピクセルの位置が必要な場合は、これをスケーリングする必要があるかもしれません。