2

I'm working on the face detection functionality and getting buffer in the delegate below but when I try to make UIImage with CIImage, I'm getting image in Landscape code, I have only portrait orientation in app:

1)- On generating session, tried to make portrait mode:

 // previewLayer is kind of AVCaptureVideoPreviewLayer
    if ([self.previewLayer.connection isVideoOrientationSupported])
        [self.previewLayer.connection setVideoOrientation:AVCaptureVideoOrientationPortrait];

2)- Delegate:

    - (void)captureOutput:(AVCaptureOutput *)captureOutput
        didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer
       fromConnection:(AVCaptureConnection *)connection       

3)- Unable to rotate UIImage as image.CGImage is 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];

I'm not sure what's wrong with orientation of image that I get from delegate, I tried with multiple code snaps of stack overflow answers but none of them worked to rotate image or buffer, some are:

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?

Community
  • 1
  • 1
Shrejas
  • 468
  • 1
  • 4
  • 15

0 Answers0