我是iOS编程的新手,我想知道是否有办法从带有AVFoundation的相机或Xcode中的其他库访问10位或12位原始数据?如果是这样,怎么样?
谢谢!
答案 0 :(得分:2)
如果您可以将图像加载到UIImage
,则可以使用Core Graphics来获取像素缓冲区。我怀疑它将以每像素16位的形式存储在内存中,但请试一试并查看。
UIImage *image = ...
CGImageRef imageRef = image.CGImage; // get the CGImageRef
NSAssert(imageRef, @"Unable to get CGImageRef");
CGDataProviderRef provider = CGImageGetDataProvider(imageRef); // get the data provider
NSAssert(provider, @"Unable to get provider");
NSData *data = CFBridgingRelease(CGDataProviderCopyData(provider)); // get copy of the data
NSAssert(data, @"Unable to copy image data");
NSInteger bitsPerComponent = CGImageGetBitsPerComponent(imageRef); // some other interesting details about image
NSInteger bitsPerPixel = CGImageGetBitsPerPixel(imageRef);
CGBitmapInfo bitmapInfo = CGImageGetBitmapInfo(imageRef);
NSInteger bytesPerRow = CGImageGetBytesPerRow(imageRef);
NSInteger width = CGImageGetWidth(imageRef);
NSInteger height = CGImageGetHeight(imageRef);
CGColorSpaceRef colorspace = CGImageGetColorSpace(imageRef);
有关详细信息,请参阅The Quartz 2D Programming Guide。
答案 1 :(得分:1)
您需要为摄像头捕获设置AVCaptureSession
,然后使用委托功能:
- (void)captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection *)connection
要捕获原始图像数据(sampleBuffer),请参阅:https://developer.apple.com/library/ios/documentation/AudioVideo/Conceptual/AVFoundationPG/Articles/04_MediaCapture.html