iPhoneで画像処理をしようとしています。http://developer.apple.com/library/ios/#qa/qa2010/qa1702.htmlを使用してカメラ フレームをキャプチャしています。
私の問題は、キャプチャされたバッファにアクセスしようとすると、カメラの FPS が 30 から約 20 に低下することです。修正方法を知っている人はいますか?
kCVPixelFormatType_32BGRA 形式で見つけた最低のキャプチャ品質 (AVCaptureSessionPresetLow = 192x144) を使用します。私が使用できるより低い品質を誰かが知っている場合は、喜んで試してみます.
Symbian などの他のプラットフォームで同じイメージ アクセスを行うと、問題なく動作します。
これが私のコードです:
#pragma mark -
#pragma mark AVCaptureSession delegate
- (void)captureOutput:(AVCaptureOutput *)captureOutput
didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer
fromConnection:(AVCaptureConnection *)connection
{
/*We create an autorelease pool because as we are not in the main_queue our code is
not executed in the main thread. So we have to create an autorelease pool for the thread we are in*/
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
CVImageBufferRef imageBuffer = CMSampleBufferGetImageBuffer(sampleBuffer);
//Lock the image buffer
if (CVPixelBufferLockBaseAddress(imageBuffer, 0) == kCVReturnSuccess)
{
// calculate FPS and display it using main thread
[self performSelectorOnMainThread:@selector(updateFps:) withObject: (id) nil waitUntilDone:NO];
UInt8 *base = (UInt8 *)CVPixelBufferGetBaseAddress(imageBuffer); //image buffer start address
size_t width = CVPixelBufferGetWidth(imageBuffer);
size_t height = CVPixelBufferGetHeight(imageBuffer);
int size = (height*width);
UInt8* pRGBtmp = m_pRGBimage;
/*
Here is the problem; m_pRGBimage is RGB image I want to process.
In the 'for' loop I convert the image from BGRA to RGB. As a resault, the FPS drops to 20.
*/
for (int i=0;i<size;i++)
{
pRGBtmp[0] = base[2];
pRGBtmp[1] = base[1];
pRGBtmp[2] = base[0];
base = base+4;
pRGBtmp = pRGBtmp+3;
}
// Display received action
[self performSelectorOnMainThread:@selector(displayAction:) withObject: (id) nil waitUntilDone:NO];
//[self displayAction:&eyePlayOutput];
//saveFrame( imageBuffer );
//unlock the image buffer
CVPixelBufferUnlockBaseAddress(imageBuffer,0);
}
[pool drain];
}
回答の続きとして、画像をリアルタイムで処理する必要があり、表示されています。
AVCaptureSessionPresetHigh を使用すると、次のような最も単純なことを行うことに気付きました。
for (int i=0;i<size;i++)
x = base[0];
フレームレートが 4 ~ 5 FPS に低下します。そのサイズの画像がキャッシュされていないためだと思います。
基本的に、96x48 の画像が必要です。ハードウェアアクセラレーションを使用してカメラ出力画像を縮小する簡単な方法はありますか?