CaptureStillImageAsynchronouslyFromConnection without a JPG broker

I try to get as many images from the camera as possible, but I can only find examples that captureStillImageAsynchronouslyFromConnection , and then go straight to:

 NSData *imageData = [AVCaptureStillImageOutput jpegStillImageNSDataRepresentation:imageSampleBuffer]; UIImage *image = [[UIImage alloc] initWithData:imageData]; 

JPEG is loss and that’s it, is there a way to get data like PNG, or even just RGBA (BGRA, what-have-you?). AVCaptureStillImageOutput does not seem to have other NSData * methods.

Actually, looking at CMSampleBufferRef, it seems that it is already locked as JPEG ~

 formatDescription = <CMVideoFormatDescription 0xfe5e1f0 [0x3e5ac650]> { mediaType:'vide' mediaSubType:'jpeg' mediaSpecific: { codecType: 'jpeg' dimensions: 2592 x 1936 } extensions: {(null)} } 

Is there any other way to make a full resolution image and get raw data?

+6
source share
2 answers

You will need to set the output settings with a different pixel format. If you want, for example, a 32-bit BGRA, you can set:

 NSDictionary *outputSettings = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithUnsignedInt:kCVPixelFormatType_32BGRA], (id)kCVPixelBufferPixelFormatTypeKey, nil]; 

From https://developer.apple.com/library/mac/#documentation/AVFoundation/Reference/AVCaptureStillImageOutput_Class/Reference/Reference.html "recommended" pixel formats:

  • kCMVideoCodecType_JPEG
  • kCVPixelFormatType_420YpCbCr8BiPlanarFullRange
  • kCVPixelFormatType_32BGRA

Of course, if you do not use JPEG output, you cannot use jpegStillImageNSDataRepresentation: but there is an example here: how to convert CVImageBufferRef to UIImage

+10
source

Just change the output settings of your connection:

OutputSettings Compression options for output.

 @property(nonatomic, copy) NSDictionary *outputSettings 

You can restore NSDictionary of supported values ​​using

availableImageDataCodecTypes Supported image codec formats that can be specified in outputSettings parameters. (Only for reading)

 @property(nonatomic, readonly) NSArray *availableImageDataCodecTypes 
0
source

Source: https://habr.com/ru/post/920929/


All Articles