IPhone YUV Channel Orientation

I grab the YUV channel with the IPhone in the format kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange (YUV, biplanar).

I intend to handle the y-channel, so I grab it using

CVImageBufferRef pixelBuffer = CMSampleBufferGetImageBuffer( sampleBuffer );

CVPixelBufferLockBaseAddress( pixelBuffer, 0 );

int bufferHeight = CVPixelBufferGetHeight(pixelBuffer);
int bufferWidth = CVPixelBufferGetWidth(pixelBuffer);

uint8_t *y_channel = CVPixelBufferGetBaseAddressOfPlane(pixelBuffer, 0);

The problem is that the y_channel pixels seem rotated and mirrored (I draw them on the overlay layer to see what it looks like:

- (void)drawLayer:(CALayer *)layer inContext:(CGContextRef)context
{
    CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceGray();
    CGContextRef bitmapContext = CGBitmapContextCreate(rotated,
                                                       imageSize->x,
                                                       imageSize->y,
                                                       8, // bitsPerComponent
                                                       1*imageSize->x, // bytesPerRow
                                                       colorSpace,
                                                       kCGImageAlphaNone);

    CFRelease(colorSpace);

    CGImageRef cgImage = CGBitmapContextCreateImage(bitmapContext);

    CGContextDrawImage(context,  CGRectMake(0, 0, imageSize->x/2, imageSize->y/2), cgImage);

    CFRelease(cgImage);
    CFRelease(bitmapContext);
}

I looked at the loop through the pixels and created a fixed version of the image, but I wonder if there is a way to get y_channel in the correct orientation (IE: doesn't rotate 90 degrees) right from the camera.

0
source share
1 answer

, Y, , , . , 90 , , .

, , , , Core Graphics, . iPhone, CALayers, UIViews, , , , .

, , Y- OpenGL ES. . , , , .

, iOS OpenGL ES 2.0 , , . BGRA, Y- .

+2

All Articles