2011-12-16 12 views
3

私はAVCaptureSessionでビデオを取り込み、コールバックでビデオを処理してから、結果を自分のGLKViewにレンダリングしようとしています。以下のコードは動作しますが、GLKViewの画像は90度回転して50%縮小します。CVPixelBufferRefから作成されたCIImageが回転し、GLKViewで縮小します。

glContextは[[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2]で作成されます。

My coreImageContextは[CIContext contextWithEAGLContext:glContext]で作成されます。

- (void)captureOutput:(AVCaptureOutput *)captureOutput 
didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer 
     fromConnection:(AVCaptureConnection *)connection 
{ 
    // process the image 
    CVPixelBufferRef pixelBuffer = (CVPixelBufferRef)CMSampleBufferGetImageBuffer(sampleBuffer); 
    CIImage *image = [CIImage imageWithCVPixelBuffer:pixelBuffer]; 

    // display it (using main thread) 
    dispatch_async(dispatch_get_main_queue(), ^{ 
     // running synchronously on the main thread now 
     [self.coreImageContext drawImage:image inRect:self.view.bounds fromRect:[image extent]]; 
     [self.glContext presentRenderbuffer:GL_RENDERBUFFER]; 
    }); 
} 

実行してアフィン変換するコードを挿入するのは効率が悪いようです。回転とスケーリングを防ぐためにセットアップコールやパラメータがないのですか?

+0

ここで同じ問題が発生します。私はあなたの場合とほとんど同じコードを使用しました。私はあきらめて、アフィン変換を使って回転を補正し、画面全体を満たすように画像のサイズを変更しました。 –

答えて

2

AVFoundationのビデオプレビュービューでは、グラフィックスハードウェアを使用してイメージの回転が行われます。後ろ向きカメラのネイティブキャプチャの向きは、左向きです。正面に向いているカメラの風景が右です。ビデオを録画するときAVFoundationはMOV/MP4のヘッダーにトランスフォームを配置して、プレーヤーにビデオの正しい向きを指示します。 MOV/MP4から画像を取り出すだけでは、元のキャプチャ方向になります。 SO Post

0

drawImage:inRect:fromRect:画像を宛先矩形に合わせて拡大/縮小します。

CGFloat screenScale = [[UIScreen mainScreen] scale]; 
[self.coreImageContext drawImage:image inRect:CGRectApplyAffineTransform(self.view.bounds, CGAffineTransformMakeScale(screenScale, screenScale)) fromRect:[image extent]]; 
関連する問題