我正在处理面部检测功能并在下面的委托中获取缓冲区但是当我尝试使用CIImage制作UIImage时,我在横向代码中获取图像,我在应用程序中只有纵向:
1) - 在生成会话时,尝试进行肖像模式:
// previewLayer is kind of AVCaptureVideoPreviewLayer
if ([self.previewLayer.connection isVideoOrientationSupported])
[self.previewLayer.connection setVideoOrientation:AVCaptureVideoOrientationPortrait];
2) - 代表:
- (void)captureOutput:(AVCaptureOutput *)captureOutput
didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer
fromConnection:(AVCaptureConnection *)connection
3) - 无法将UIImage旋转为image.CGImage为nil
CVPixelBufferRef pixelBuffer = CMSampleBufferGetImageBuffer(sampleBuffer);
///CVPixelBufferRef pixelBuffer = [self rotateBuffer:sampleBuffer];
CFDictionaryRef attachments = CMCopyDictionaryOfAttachments(kCFAllocatorDefault, pixelBuffer, kCMAttachmentMode_ShouldPropagate);
CIImage *ciImage = [[CIImage alloc] initWithCVPixelBuffer:pixelBuffer
options:(__bridge NSDictionary *)attachments];
UIImage *image = [UIImage imageWithCIImage:ciImage];
我不确定从委托获得的图像方向有什么问题,我尝试使用堆栈溢出答案的多个代码捕捉但没有一个能够旋转图像或缓冲区,有些是:
iOS app camera orientation in captureOutput
Rotate CGImage taken from video frame
How to directly rotate CVImageBuffer image in IOS 4 without converting to UIImage?