【发布时间】:2012-01-21 15:26:40
【问题描述】:
我正在尝试使用 AVCaptureSession 抓取视频,在回调中处理视频(最终),然后将结果呈现到我的 GLKView 中。下面的代码有效,但我的 GLKView 中的图像旋转了 90 度并缩小了 50%。
glContext 是用 [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2];
创建的我的 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];
});
}
插入代码来执行和仿射变换似乎效率低下。我是否缺少设置调用或参数来防止旋转和缩放?
【问题讨论】:
-
这里有同样的问题。我使用了与您的情况几乎相同的代码。我最终放弃并使用仿射变换来校正旋转并调整图像大小以填满整个屏幕。
标签: ios5 avfoundation core-image